{"id":13609549,"url":"https://github.com/alaouy/YouTube","last_synced_at":"2025-04-12T20:32:04.649Z","repository":{"id":21253306,"uuid":"24568844","full_name":"alaouy/YouTube","owner":"alaouy","description":"🔥 Laravel PHP Facade/Wrapper for the Youtube Data API","archived":false,"fork":false,"pushed_at":"2024-10-15T09:41:24.000Z","size":170,"stargazers_count":790,"open_issues_count":8,"forks_count":204,"subscribers_count":51,"default_branch":"master","last_synced_at":"2025-04-05T22:01:41.450Z","etag":null,"topics":["api","laravel","package","youtube"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alaouy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-09-28T19:50:06.000Z","updated_at":"2025-04-02T19:06:55.000Z","dependencies_parsed_at":"2024-05-31T09:23:58.784Z","dependency_job_id":"bc9a70fb-3a2f-463e-bdb3-a716288c4aa2","html_url":"https://github.com/alaouy/YouTube","commit_stats":{"total_commits":132,"total_committers":43,"mean_commits":"3.0697674418604652","dds":0.5681818181818181,"last_synced_commit":"d92230706bf6c28d6f50de3704043b27ec66fb5a"},"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alaouy%2FYouTube","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alaouy%2FYouTube/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alaouy%2FYouTube/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alaouy%2FYouTube/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alaouy","download_url":"https://codeload.github.com/alaouy/YouTube/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248629805,"owners_count":21136320,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","laravel","package","youtube"],"created_at":"2024-08-01T19:01:35.868Z","updated_at":"2025-04-12T20:32:04.291Z","avatar_url":"https://github.com/alaouy.png","language":"PHP","funding_links":["https://www.paypal.me/malaouy"],"categories":["PHP"],"sub_categories":[],"readme":"YouTube\n=========\n\n[![YouTube Tests](https://github.com/alaouy/YouTube/actions/workflows/tests.yml/badge.svg)](https://github.com/alaouy/YouTube/actions/workflows/tests.yml) [![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.me/malaouy)\n\nLaravel PHP Facade/Wrapper for the YouTube Data API v3 ( Non-OAuth )\n\n## Requirements\n\n- PHP 7.0 or higher\n- Laravel 5.1 or higher\n- API key from [Google Console](https://console.developers.google.com)\n\nLooking for YouTube Package for either of these: PHP 5, Laravel 5.0, Laravel 4? Visit the [`php5-branch`](https://github.com/alaouy/YouTube/tree/php5)\n\n## Installation\n\nRun in console below command to download package to your project:\n```bash\ncomposer require alaouy/youtube\n```\n\n## Configuration\n\nIn `/config/app.php` add YoutubeServiceProvider (Laravel \u003c 5.5):\n```php\nAlaouy\\Youtube\\YoutubeServiceProvider::class,\n```\n\nDo not forget to add also YouTube facade there (Laravel \u003c 5.5):\n```php\n'Youtube' =\u003e Alaouy\\Youtube\\Facades\\Youtube::class,\n```\n\nPublish config settings:\n```bach\n$ php artisan vendor:publish --provider=\"Alaouy\\Youtube\\YoutubeServiceProvider\"\n```\n\nSet your YouTube API key in the file:\n\n```shell\n/config/youtube.php\n```\n\nOr in the .env file\n```shell\nYOUTUBE_API_KEY = KEY\n```\n\nOr you can set the key programmatically at run time :\n```php\nYoutube::setApiKey('KEY');\n```\n\n## Usage\n\n```php\n// use Alaouy\\Youtube\\Facades\\Youtube;\n\n\n// Return an STD PHP object\n$video = Youtube::getVideoInfo('rie-hPVJ7Sw');\n\n// Get multiple videos info from an array\n$videoList = Youtube::getVideoInfo(['rie-hPVJ7Sw','iKHTawgyKWQ']);\n\n// Get localized video info\n$video = Youtube::getLocalizedVideoInfo('vjF9GgrY9c0', 'pl');\n\n// Get comment threads by videoId\n$commentThreads = Youtube::getCommentThreadsByVideoId('zwiUB_Lh3iA');\n\n// Get popular videos in a country, return an array of PHP objects\n$videoList = Youtube::getPopularVideos('us');\n\n// Search playlists, channels and videos. return an array of PHP objects\n$results = Youtube::search('Android');\n\n// Only search videos, return an array of PHP objects\n$videoList = Youtube::searchVideos('Android');\n\n// Search only videos in a given channel, return an array of PHP objects\n$videoList = Youtube::searchChannelVideos('keyword', 'UCk1SpWNzOs4MYmr0uICEntg', 40);\n\n// List videos in a given channel, return an array of PHP objects\n$videoList = Youtube::listChannelVideos('UCk1SpWNzOs4MYmr0uICEntg', 40);\n\n$results = Youtube::searchAdvanced([ /* params */ ]);\n\n// Get channel data by channel handle (like https://www.youtube.com/@google), return an STD PHP object\n$channel = Youtube::getChannelByHandle('google');\n\n// Get channel data by channel name, return an STD PHP object\n$channel = Youtube::getChannelByName('xdadevelopers');\n\n// Get channel data by channel ID, return an STD PHP object\n$channel = Youtube::getChannelById('UCk1SpWNzOs4MYmr0uICEntg');\n\n// Get playlist by ID, return an STD PHP object\n$playlist = Youtube::getPlaylistById('PL590L5WQmH8fJ54F369BLDSqIwcs-TCfs');\n\n// Get playlists by multiple ID's, return an array of STD PHP objects\n$playlists = Youtube::getPlaylistById(['PL590L5WQmH8fJ54F369BLDSqIwcs-TCfs', 'PL590L5WQmH8cUsRyHkk1cPGxW0j5kmhm0']);\n\n// Get playlist by channel ID, return an array of PHP objects\n$playlists = Youtube::getPlaylistsByChannelId('UCk1SpWNzOs4MYmr0uICEntg');\n\n// Get items in a playlist by playlist ID, return an array of PHP objects\n$playlistItems = Youtube::getPlaylistItemsByPlaylistId('PL590L5WQmH8fJ54F369BLDSqIwcs-TCfs');\n\n// Get channel activities by channel ID, return an array of PHP objects\n$activities = Youtube::getActivitiesByChannelId('UCk1SpWNzOs4MYmr0uICEntg');\n\n// Retrieve video ID from original YouTube URL\n$videoId = Youtube::parseVidFromURL('https://www.youtube.com/watch?v=moSFlvxnbgk');\n// result: moSFlvxnbgk\n```\n\n## Validation Rules\n\n```php\n// use Alaouy\\Youtube\\Rules\\ValidYoutubeVideo;\n\n\n// Validate a YouTube Video URL\n[\n    'youtube_video_url' =\u003e ['bail', 'required', new ValidYoutubeVideo]\n];\n```\n\nYou can use the bail rule in conjunction with this in order to prevent unnecessary queries.\n\n## Basic Search Pagination\n\n```php\n// Set default parameters\n$params = [\n    'q'             =\u003e 'Android',\n    'type'          =\u003e 'video',\n    'part'          =\u003e 'id, snippet',\n    'maxResults'    =\u003e 50\n];\n\n// Make intial call. with second argument to reveal page info such as page tokens\n$search = Youtube::searchAdvanced($params, true);\n\n// Check if we have a pageToken\nif (isset($search['info']['nextPageToken'])) {\n    $params['pageToken'] = $search['info']['nextPageToken'];\n}\n\n// Make another call and repeat\n$search = Youtube::searchAdvanced($params, true);\n\n// Add results key with info parameter set\nprint_r($search['results']);\n\n/* Alternative approach with new built-in paginateResults function */\n\n// Same params as before\n$params = [\n    'q'             =\u003e 'Android',\n    'type'          =\u003e 'video',\n    'part'          =\u003e 'id, snippet',\n    'maxResults'    =\u003e 50\n];\n\n// An array to store page tokens so we can go back and forth\n$pageTokens = [];\n\n// Make inital search\n$search = Youtube::paginateResults($params, null);\n\n// Store token\n$pageTokens[] = $search['info']['nextPageToken'];\n\n// Go to next page in result\n$search = Youtube::paginateResults($params, $pageTokens[0]);\n\n// Store token\n$pageTokens[] = $search['info']['nextPageToken'];\n\n// Go to next page in result\n$search = Youtube::paginateResults($params, $pageTokens[1]);\n\n// Store token\n$pageTokens[] = $search['info']['nextPageToken'];\n\n// Go back a page\n$search = Youtube::paginateResults($params, $pageTokens[0]);\n\n// Add results key with info parameter set\nprint_r($search['results']);\n```\n\nThe pagination above is quite basic. Depending on what you are trying to achieve you may want to create a recursive function that traverses the results.\n\n## Manual Class Instantiation\n\n```php\n// Directly call the YouTube constructor\n$youtube = new Youtube(config('YOUTUBE_API_KEY'));\n\n// By default, if the $_SERVER['HTTP_HOST'] header is set,\n// it will be used as the `Referer` header. To override\n// this setting, set 'use-http-host' to false during\n// object construction:\n$youtube = new Youtube(config('YOUTUBE_API_KEY'), ['use-http-host' =\u003e false]);\n\n// This setting can also be set after the object was created\n$youtube-\u003euseHttpHost(false);\n```\n\n## Run Unit Test\nIf you have PHPUnit installed in your environment, run:\n\n```bash\n$ phpunit\n```\n\nIf you don't have PHPUnit installed, you can run the following:\n\n```bash\n$ composer update\n$ ./vendor/bin/phpunit\n```\n\n## Format of returned data\nThe returned JSON is decoded as PHP objects (not Array).\nPlease read the [\"Reference\" section](https://developers.google.com/youtube/v3/docs/) of the Official API doc.\n\n\n## YouTube Data API v3\n- [YouTube Data API v3 Doc](https://developers.google.com/youtube/v3/)\n- [Obtain API key from Google API Console](https://console.developers.google.com)\n\n## Donation\nIf you find this project to be of use to you please consider buying me a cup of tea :)\n\n[![paypal](https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif)](https://www.paypal.me/malaouy)\n## Credits\nBuilt on code from Madcoda's [php-youtube-api](https://github.com/madcoda/php-youtube-api).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falaouy%2FYouTube","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falaouy%2FYouTube","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falaouy%2FYouTube/lists"}