All Projects → alaouy → Youtube

alaouy / Youtube

Licence: mit
🔥 Laravel PHP Facade/Wrapper for the Youtube Data API

Projects that are alternatives of or similar to Youtube

Youtube
Upload a video to a single YouTube channel with Laravel 5.
Stars: ✭ 143 (-76.56%)
Mutual labels:  laravel, package, youtube
Laravel Acl
This package helps you to associate users with permissions and permission groups with laravel framework
Stars: ✭ 404 (-33.77%)
Mutual labels:  laravel, package
Larapi
An API-friendly fork of Laravel. Authentication, error handling, resource filtering, sorting, pagination and much more included
Stars: ✭ 397 (-34.92%)
Mutual labels:  api, laravel
Smartwiki
因个人精力有限,不在维护此项目,推荐用MinDoc代替
Stars: ✭ 486 (-20.33%)
Mutual labels:  api, laravel
Laravel Json Api Paginate
A paginator that plays nice with the JSON API spec
Stars: ✭ 351 (-42.46%)
Mutual labels:  api, laravel
Polr
🚡 A modern, powerful, and robust URL shortener
Stars: ✭ 4,147 (+579.84%)
Mutual labels:  api, laravel
Laravel Blade Javascript
A Blade directive to export variables to JavaScript
Stars: ✭ 485 (-20.49%)
Mutual labels:  api, laravel
Plans
Laravel Plans is a package for SaaS apps that need management over plans, features, subscriptions, events for plans or limited, countable features.
Stars: ✭ 326 (-46.56%)
Mutual labels:  laravel, package
Cms
Decoupled CMS for any Laravel app, gain control of: pages, blogs, galleries, events, images, custom modules and more.
Stars: ✭ 498 (-18.36%)
Mutual labels:  api, laravel
Restful Api Specification
RESTful API 设计规范
Stars: ✭ 498 (-18.36%)
Mutual labels:  api, laravel
Laravel Cascade Soft Deletes
Cascading deletes for Eloquent models that implement soft deletes
Stars: ✭ 498 (-18.36%)
Mutual labels:  laravel, package
Befriended
Eloquent Befriended brings social media-like features like following, blocking and filtering content based on following or blocked models.
Stars: ✭ 596 (-2.3%)
Mutual labels:  laravel, package
Socialreaper
Social media scraping / data collection library for Facebook, Twitter, Reddit, YouTube, Pinterest, and Tumblr APIs
Stars: ✭ 338 (-44.59%)
Mutual labels:  api, youtube
Comments
Native comments for your Laravel application.
Stars: ✭ 390 (-36.07%)
Mutual labels:  laravel, package
Seat
🌀✳️ SeAT: A Simple, EVE Online API Tool and Corporation Manager
Stars: ✭ 324 (-46.89%)
Mutual labels:  api, laravel
Laravel Api Response Builder
Builds nice, normalized and easy to consume Laravel REST API JSON responses.
Stars: ✭ 433 (-29.02%)
Mutual labels:  api, laravel
Laravel Ban
Laravel Ban simplify blocking and banning Eloquent models.
Stars: ✭ 572 (-6.23%)
Mutual labels:  laravel, package
Laravel5 Jsonapi
Laravel 5 JSON API Transformer Package
Stars: ✭ 313 (-48.69%)
Mutual labels:  api, laravel
Laravel Api Query Builder
Laravel & Lumen Api Query Builder Package
Stars: ✭ 324 (-46.89%)
Mutual labels:  api, laravel
Laravel Orion
The simplest way to create REST API with Laravel
Stars: ✭ 481 (-21.15%)
Mutual labels:  api, laravel

Youtube

Travis Youtube Build Donate

Laravel PHP Facade/Wrapper for the Youtube Data API v3 ( Non-OAuth )

Requirements

Looking for Youtube Package for either of these: PHP 5, Laravel 5.0, Laravel 4? Visit the php5-branch

Installation

Run in console below command to download package to your project:

composer require alaouy/youtube

Configuration

In /config/app.php add YoutubeServiceProvider:

Alaouy\Youtube\YoutubeServiceProvider::class,

Do not forget to add also Youtube facade there:

'Youtube' => Alaouy\Youtube\Facades\Youtube::class,

Publish config settings:

$ php artisan vendor:publish --provider="Alaouy\Youtube\YoutubeServiceProvider"

Set your Youtube API key in the file:

/config/youtube.php

Or in the .env file

YOUTUBE_API_KEY = KEY

Or you can set the key programmatically at run time :

Youtube::setApiKey('KEY');

Usage

// use Alaouy\Youtube\Facades\Youtube;


// Return an STD PHP object
$video = Youtube::getVideoInfo('rie-hPVJ7Sw');

// Get multiple videos info from an array
$videoList = Youtube::getVideoInfo(['rie-hPVJ7Sw','iKHTawgyKWQ']);

// Get localized video info
$video = Youtube::getLocalizedVideoInfo('vjF9GgrY9c0', 'pl');

// Get multiple videos related to a video
$relatedVideos = Youtube::getRelatedVideos('iKHTawgyKWQ');

// Get comment threads by videoId
$commentThreads = Youtube::getCommentThreadsByVideoId('zwiUB_Lh3iA');

// Get popular videos in a country, return an array of PHP objects
$videoList = Youtube::getPopularVideos('us');

// Search playlists, channels and videos. return an array of PHP objects
$results = Youtube::search('Android');

// Only search videos, return an array of PHP objects
$videoList = Youtube::searchVideos('Android');

// Search only videos in a given channel, return an array of PHP objects
$videoList = Youtube::searchChannelVideos('keyword', 'UCk1SpWNzOs4MYmr0uICEntg', 40);

// List videos in a given channel, return an array of PHP objects
$videoList = Youtube::listChannelVideos('UCk1SpWNzOs4MYmr0uICEntg', 40);

$results = Youtube::searchAdvanced([ /* params */ ]);

// Get channel data by channel name, return an STD PHP object
$channel = Youtube::getChannelByName('xdadevelopers');

// Get channel data by channel ID, return an STD PHP object
$channel = Youtube::getChannelById('UCk1SpWNzOs4MYmr0uICEntg');

// Get playlist by ID, return an STD PHP object
$playlist = Youtube::getPlaylistById('PL590L5WQmH8fJ54F369BLDSqIwcs-TCfs');

// Get playlists by multiple ID's, return an array of STD PHP objects
$playlists = Youtube::getPlaylistById(['PL590L5WQmH8fJ54F369BLDSqIwcs-TCfs', 'PL590L5WQmH8cUsRyHkk1cPGxW0j5kmhm0']);

// Get playlist by channel ID, return an array of PHP objects
$playlists = Youtube::getPlaylistsByChannelId('UCk1SpWNzOs4MYmr0uICEntg');

// Get items in a playlist by playlist ID, return an array of PHP objects
$playlistItems = Youtube::getPlaylistItemsByPlaylistId('PL590L5WQmH8fJ54F369BLDSqIwcs-TCfs');

// Get channel activities by channel ID, return an array of PHP objects
$activities = Youtube::getActivitiesByChannelId('UCk1SpWNzOs4MYmr0uICEntg');

// Retrieve video ID from original YouTube URL
$videoId = Youtube::parseVidFromURL('https://www.youtube.com/watch?v=moSFlvxnbgk');
// result: moSFlvxnbgk

Validation Rules

// use Alaouy\Youtube\Rules\ValidYoutubeVideo;


// Validate a YouTube Video URL
[
    'youtube_video_url' => ['bail', 'required', new ValidYoutubeVideo]
];

You can use the bail rule in conjunction with this in order to prevent unnecessary queries.

Basic Search Pagination

// Set default parameters
$params = [
    'q'             => 'Android',
    'type'          => 'video',
    'part'          => 'id, snippet',
    'maxResults'    => 50
];

// Make intial call. with second argument to reveal page info such as page tokens
$search = Youtube::searchAdvanced($params, true);

// Check if we have a pageToken
if (isset($search['info']['nextPageToken'])) {
    $params['pageToken'] = $search['info']['nextPageToken'];
}

// Make another call and repeat
$search = Youtube::searchAdvanced($params, true);

// Add results key with info parameter set
print_r($search['results']);

/* Alternative approach with new built-in paginateResults function */

// Same params as before
$params = [
    'q'             => 'Android',
    'type'          => 'video',
    'part'          => 'id, snippet',
    'maxResults'    => 50
];

// An array to store page tokens so we can go back and forth
$pageTokens = [];

// Make inital search
$search = Youtube::paginateResults($params, null);

// Store token
$pageTokens[] = $search['info']['nextPageToken'];

// Go to next page in result
$search = Youtube::paginateResults($params, $pageTokens[0]);

// Store token
$pageTokens[] = $search['info']['nextPageToken'];

// Go to next page in result
$search = Youtube::paginateResults($params, $pageTokens[1]);

// Store token
$pageTokens[] = $search['info']['nextPageToken'];

// Go back a page
$search = Youtube::paginateResults($params, $pageTokens[0]);

// Add results key with info parameter set
print_r($search['results']);

The 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.

Manual Class Instantiation

// Directly call the YouTube constructor
$youtube = new Youtube(config('YOUTUBE_API_KEY'));

// By default, if the $_SERVER['HTTP_HOST'] header is set,
// it will be used as the `Referer` header. To override
// this setting, set 'use-http-host' to false during
// object construction:
$youtube = new Youtube(config('YOUTUBE_API_KEY'), ['use-http-host' => false]);

// This setting can also be set after the object was created
$youtube->useHttpHost(false);

Run Unit Test

If you have PHPUnit installed in your environment, run:

$ phpunit

If you don't have PHPUnit installed, you can run the following:

$ composer update
$ ./vendor/bin/phpunit

Format of returned data

The returned JSON is decoded as PHP objects (not Array). Please read the "Reference" section of the Official API doc.

Youtube Data API v3

Donation

If you find this project to be of use to you please consider buying me a cup of tea :)

paypal

Credits

Built on code from Madcoda's php-youtube-api.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].