GithubHelp home page GithubHelp logo

youtube's Introduction

Laravel Youtube Library

This library is used for fetching videos and channels from youtube using a URL.

Installation

  1. Include using Composer: "vinelab/youtube" : "*"
  2. Add the service provider 'Vinelab\Youtube\YoutubeServiceProvider'
  3. Add the Facade 'Youtube' => 'Vinelab\Youtube\Facades\Youtube'
  4. Publish the config file php artisan config:publish Vinelab/youtube
  5. Add your key to the config file

Usage

Use the Youtube Facade to access the package's functionalities.

Youtube::video($url)

To fetch a video use Youtube::video($url) this will return an object of type Najem\Videos\Video.

You can fetch multiple videos at once by passing an array of Url's, to Youtube::videos($urls) or even Youtube::video($urls).

Response:

object(Vinelab\Youtube\Video)[180]
  public 'kind' => string 'youtube#video' (length=13)
  public 'id' => string '1j1MBSwg44A' (length=11)
  public 'etag' => string '"ePFRUfYBkeQ2ncpP9OLHKB0fDw4/ZsQyzEl5gbrEkz55D3fNHwM1RUM"' (length=57)
  public 'sync_enabled' => boolean true
  public 'synced_at' => string '2014-05-08T15:55:06+00:00' (length=25)
  public 'snippet' => 
    array (size=5)
      'publishedAt' => string '2013-07-02T16:11:38.000Z' (length=24)
      'channelId' => string 'UCUuseKzXVxgBCnSy8KU90jg' (length=24)
      'title' => string 'Pink Floyd - Comfortably Numb (Cover by Hayajan)' (length=48)
      'description' => string 'Hayajan | Ya Bay: Lyrics of Comfortably Numb wr'... (length=675)
      'channelTitle' => string 'Alaa Wardi' (length=10)
  public 'thumbnails' => 
    array (size=5)
      'default' => string 'https://i1.ytimg.com/vi/1j1MBSwg44A/default.jpg' (length=47)
      'medium' => string 'https://i1.ytimg.com/vi/1j1MBSwg44A/mqdefault.jpg' (length=49)
      'high' => string 'https://i1.ytimg.com/vi/1j1MBSwg44A/hqdefault.jpg' (length=49)
      'standard' => string 'https://i1.ytimg.com/vi/1j1MBSwg44A/sddefault.jpg' (length=49)
      'maxres' => string 'https://i1.ytimg.com/vi/1j1MBSwg44A/maxresdefault.jpg' (length=53)

Youtube::channel($url)

To fetch a channel use Youtube::channel($url) this will return an object of type Najem\Videos\Channel.

Response:

object(Najem\Videos\Channel)[209]
  protected 'data' =>
    array (size=14)
      'kind' => string 'youtube#channel' (length=15)
      'etag' => string '"ePFRUfYBkeQ2ncpP9OLHKB0fDw4/53nIEDRhzjlzEN0ZZf1TQ5Oyr_0"' (length=57)
      'sync_enabled' => boolean true
      'id' => string 'UCBsKiXTgZrg0tqz4yz_R5Tw' (length=24)
      'synced_at' => string '2014-05-08T15:56:10+00:00' (length=25)
      'title' => string 'adib hanna' (length=10)
      'description' => string '' (length=0)
      'published_at' => string '2009-12-27T22:46:00.000Z' (length=24)
      'default_thumb' => string 'https://yt3.ggpht.com/-xRortO695HE/AAAAAAAAAAI/AAAAAAAAAAA/b2VPZd_ZNsk/s88-c-k-no/photo.jpg' (length=91)
      'medium_thumb' => string 'https://yt3.ggpht.com/-xRortO695HE/AAAAAAAAAAI/AAAAAAAAAAA/b2VPZd_ZNsk/s240-c-k-no/photo.jpg' (length=92)
      'high_thumb' => string 'https://yt3.ggpht.com/-xRortO695HE/AAAAAAAAAAI/AAAAAAAAAAA/b2VPZd_ZNsk/s240-c-k-no/photo.jpg' (length=92)
      'playlist_likes' => string 'LLBsKiXTgZrg0tqz4yz_R5Tw' (length=24)
      'playlist_uploads' => string 'UUBsKiXTgZrg0tqz4yz_R5Tw' (length=24)
      'google_plus_user_id' => string '113619238331121062947' (length=21)
      'videos' =>
        object(Najem\Videos\VideoCollection)[177]
          protected 'items' =>
            array (size=2)
      0 =>
        object(Najem\Videos\Video)[207]
          public 'kind' => string 'youtube#video' (length=13)
          public 'id' => string 'cdy2iLDznbI' (length=11)
          public 'etag' => string '"LFawZk2qAkq9bosMnzaQJqPHO_0/lXpe47wULVDBmjpY0A3wMuM2PpQ"' (length=57)
          public 'sync_enabled' => boolean true
          public 'snippet' =>
            array (size=5)
              ...
          public 'thumbnails' =>
            array (size=3)
              ...
      1 =>
        object(Najem\Videos\Video)[208]
          public 'kind' => string 'youtube#video' (length=13)
          public 'id' => string '4l5M0vvOnjc' (length=11)
          public 'etag' => string '"LFawZk2qAkq9bosMnzaQJqPHO_0/af1eeVp2yks5Z1PgoBwAtyQK578"' (length=57)
          public 'sync_enabled' => boolean true
          public 'snippet' =>
            array (size=5)
              ...
          public 'thumbnails' =>
            array (size=3)
              ...

Youtube::playlist($url)

To fetch a playlist use Youtube::playlist($url) this will return an object of type Najem\Videos\Playlist.

Response:

object(Vinelab\Youtube\Playlist)[811]
  protected 'data' => 
    array (size=12)
      'kind' => string 'youtube#playlist' (length=16)
      'etag' => string '"9Y5jTkxN1JET3y-M4wKMA5aK7Mk/Ed_sn_8oQKILYPBK-rRE431SEss"' (length=57)
      'sync_enabled' => boolean true
      'id' => string 'PLaMWTg0sIKTdOsNOI9h2AjKHUremHKGNZ' (length=34)
      'synced_at' => string '2015-02-27T14:12:18+00:00' (length=25)
      'title' => string 'Laravel 4.1 Tutorial | مدخل الى برمجة الوب بإستخدام لارافيل' (length=90)
      'description' => string '' (length=0)
      'published_at' => string '2014-06-02T00:47:12.000Z' (length=24)
      'default_thumb' => string 'https://i.ytimg.com/vi/FasdiQBlWwM/default.jpg' (length=46)
      'medium_thumb' => string 'https://i.ytimg.com/vi/FasdiQBlWwM/mqdefault.jpg' (length=48)
      'high_thumb' => string 'https://i.ytimg.com/vi/FasdiQBlWwM/hqdefault.jpg' (length=48)
      'videos' => 
        object(Vinelab\Youtube\VideoCollection)[695]
          protected 'items' => 
            array (size=9)
              0 => 
                object(Vinelab\Youtube\Video)[802]
                  public 'kind' => string 'youtube#playlistItem' (length=20)
                  public 'id' => string 'PLoqlw2-AY6NMK_3wSxsZieCVbVrh7I4ZUMlgYhD46jpk' (length=45)
                  public 'etag' => string '"9Y5jTkxN1JET3y-M4wKMA5aK7Mk/1CE9qGYaTyrvAf_cVZDngkiJNrI"' (length=57)
                  public 'sync_enabled' => boolean false
                  public 'synced_at' => string '2015-02-27T14:12:18+00:00' (length=25)
                  public 'snippet' => 
                    array (size=8)
                      'publishedAt' => string '2014-06-02T00:48:26.000Z' (length=24)
                      'channelId' => string 'UCpOLwC-MKK9STITTUAYlmVQ' (length=24)
                      'title' => string '1 - Laravel 4.1: Introduction | مقدمة الى لارافيل' (length=64)
                      'description' => string '- why Laravel
- what is laravel 4
- walking through the top features
- system and knowlege requirement' (length=102)
                      'channelTitle' => string 'Mahmoud Zalt' (length=12)
                      'playlistId' => string 'PLaMWTg0sIKTdOsNOI9h2AjKHUremHKGNZ' (length=34)
                      'position' => int 0
                      'resourceId' => 
                        object(stdClass)[729]
                          public 'kind' => string 'youtube#video' (length=13)
                          public 'videoId' => string 'FasdiQBlWwM' (length=11)
                  public 'thumbnails' => 
                    array (size=5)
                      'default' => string 'https://i.ytimg.com/vi/FasdiQBlWwM/default.jpg' (length=46)
                      'medium' => string 'https://i.ytimg.com/vi/FasdiQBlWwM/mqdefault.jpg' (length=48)
                      'high' => string 'https://i.ytimg.com/vi/FasdiQBlWwM/hqdefault.jpg' (length=48)
                      'standard' => string 'https://i.ytimg.com/vi/FasdiQBlWwM/sddefault.jpg' (length=48)
                      'maxres' => string 'https://i.ytimg.com/vi/FasdiQBlWwM/maxresdefault.jpg' (length=52)
                  public 'url' => string 'https://www.youtube.com/watch?v=PLoqlw2-AY6NMK_3wSxsZieCVbVrh7I4ZUMlgYhD46jpk' (length=77)
              1 => 
                object(Vinelab\Youtube\Video)[803]
                  public 'kind' => string 'youtube#playlistItem' (length=20)
                  public 'id' => string 'PLoqlw2-AY6NMK_3wSxsZieCWxHwDW_yyZU5fw7We9j94' (length=45) ...
              2 => 
              ...

Youtube::sync($resource)

To sync any retrieved resource use Youtube::sync($resource).

  • You can sync Video|Channel|Playlist and it will return the changed object Video|Channel|Playlist.
  • if the saved data was changed manually, you won't be able to sync the data, this means that the sync_enabled value is set to false.
  • if a video and a channel were passed to the sync method, or an empty(deleted) channel or video an IncompatibleParametersObjectTypesException will be thrown.

URL Validation

  • To validate the given URLs, you can use use Vinelab\Youtube\Validators\VideoValidator Class.
  • Use the validate method and pass the urls to it.

Example:

$this->validator->validate(compact('url', 'url1', 'url2', 'url3'));

If the validation failes, an InvalidVideoException will be thrown.

Package dependacies:

youtube's People

Contributors

adibhanna avatar mahmoudz avatar mulkave avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

youtube's Issues

Bug in Api.php

Starting at line 159:

//validate if the youtube response satisfy what is expected.

$this->video_validator->validate($response);

$items = is_array($video_ids) ? $response->items : array_pop($response->items);

//check if the video hasn't been deleted, then return the result accordingly.
//$response->items will always exist in the response. however, if the video
//has been deleted, items would be empty. So, it would be valid to check if
//it's empty before returning the result.

return (! empty($response->items)) ? $this->video->make($items) : null;

When $video_ids is not an array, you are popping the items element off of the $response array.
Then, on the last line you are checking to see if $response->items is empty. But that will no longer exist after being popped off the array.

Therefore, you cannot ask for only one video, or you will always get back null

If you are intending to return a single object when there is not an array of videos passed in, this should do the trick:
$items = is_array($video_ids) ? $response->items : $response->items[0];

vinelab/youtube/src/Vinelab/Youtube/Api.php

Artisan command not found

In your instructions, you say to run php artisan config:publish Vinelab/youtube, but when I do, I get the following error. I'm running Laravel 5.2.

[Symfony\Component\Console\Exception\CommandNotFoundException]
Command "config:publish" is not defined.
Did you mean one of these?
vendor:publish
config:clear
config:cache

Am I perhaps doing something wrong, or does this command need to be different for the newer version of Laravel?

Improve docs

Rewrite the docs for this package, make it as clear as possible and use examples.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.