michaelbelgium / laravel-youtube-api
Add a youtube api to your Laravel instance
Fund package maintenance!
MichaelBelgium
www.paypal.com/donate/?hosted_button_id=ZJSKX2ASR3ARL
Requires
- google/apiclient: ^2.4
- illuminate/support: ^8.0|^9.0|^10.0
- norkunas/youtube-dl-php: ^2.0
Requires (Dev)
- orchestra/testbench: ^6.0
- phpunit/phpunit: ^10.0
README
This package provides a simple youtube api for your Laravel application. It is based on my non-laravel package Youtube API.
Installation
- Install the package via composer:
composer require michaelbelgium/laravel-youtube-api
- Optional: publish the config file and edit if u like:
php artisan vendor:publish --tag=youtube-api-config
- This package uses the public disk of Laravel. Run this command to create a symbolic link to the public folder so that converted Youtube downloads are accessible:
php artisan storage:link
- Execute package migrations
php artisan migrate
- Acquire a Google API key at the Google Developer Console for the API "Youtube Data API v3". Use this key in the environment variable
GOOGLE_API_KEY
- that this packages uses
Software
On the server where your laravel app is located, you'll need to install some packages.
- Install ffmpeg (+ libmp3lame - see this wiki for tutorial)
- install youtube-dl
API Usage
This package adds 3 api routes. The route prefix, /ytconverter/
in this case, is configurable.
- POST|GET /ytconverter/convert
- DELETE /ytconverter/{id}
- GET /ytconverter/search
Check the wiki page of this repository for more information about the routes.
API authorization
If needed, you can protect the API routes with an authentication guard by setting auth
in the configuration.
Example:
'auth' => 'sanctum',
API rate limiting
If needed, you can limit API calls by editing the config setting ratelimiter
. See Laravel docs for more information or examples.
Example:
'ratelimiter' => function (Request $request) { return Limit::perMinute(5); },