예제 #1
0
 /**
  * @return VideoCollection
  */
 public function videos()
 {
     $videoCollection = new VideoCollection();
     foreach ($this->allVideoUrls() as $url) {
         $videoCollection->add(new Video($this->client, $url));
     }
     return $videoCollection;
 }
예제 #2
0
파일: Parser.php 프로젝트: vinelab/youtube
 /**
  * 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);
 }
예제 #3
0
 /**
  * Sync the videos inside the channel.
  *
  * @param $request from our code
  * @param $response from youtube
  *
  * @return \Vinelab\Youtube\VideoCollection
  */
 protected function syncVideos($request, $response)
 {
     $response_videos = $response->videos;
     $request_videos = $request->videos;
     // this will hold all the Video objects that needs to be returned
     $results_holder = new VideoCollection();
     foreach ($response_videos as $response_video) {
         foreach ($request_videos as $request_video) {
             // if the youtube video id doesn't not exist locally (means it's a new video on youtube)
             if ($this->are_different_videos($request_video, $response_video)) {
                 var_dump($request_video->title, $response_video->snippet['title']);
                 // add the youtube video to the result
                 $results_holder->push($response_video);
             } else {
                 // if the etag is the same (means video have not been updated locally or online)
                 if ($this->is_modified($request_video, $response_video)) {
                     // add the local video to the result
                     $results_holder->push($request_video);
                 } else {
                     // if the sync is enabled then add the youtube video to the result else add the local video
                     $results_holder->push($this->is_syncable($request_video) ? $response_video : $request_video);
                 }
             }
         }
     }
     $this->data->setVideos($results_holder);
     return $results_holder;
 }