Example #1
0
 /**
  * Get videos info.
  *
  * @param string|array $video_ids
  *
  * @return stdClass
  */
 public function video($video_ids)
 {
     //set the url used for the api call
     $api_url = $this->uris['videos.list'];
     //set the parameters passed with the api call
     $params = ['id' => is_array($video_ids) ? implode(',', $video_ids) : $video_ids, 'key' => $this->key, 'part' => 'id, snippet'];
     // NOTE: When Debugging uncomment the code below to cache the response
     //--////////////////////////////////////--//
     //                $key = 'koukou123';
     //                if(! Cache::has($key)){
     // make the api call
     $response = $this->get($api_url, $params);
     //                    Cache::put($key, $response, 60);
     //                }else{
     //                    $response = Cache::get($key, null);
     //                }
     //--////////////////////////////////////--//
     //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;
 }
Example #2
0
 /**
  * Parse the given video and playlist data.
  *
  * @param array $video_pages
  * @param array $playlist
  *
  * @return Vinelab\Youtube\Playlist
  */
 public function parsePlaylist($video_pages, $playlist)
 {
     $videos = new VideoCollection();
     //loop through the pages return from the api call
     //and add all the video to the Video Collection to
     //be passed to the 'channel make method'.
     foreach ($video_pages as $page) {
         foreach ($page->items as $video) {
             $videos->push($this->video->make($video));
         }
     }
     //return a new channel with the new data.
     return $this->playlist->make($playlist, $videos);
 }