function YoutubeVideosPerPage($pp)
 {
     if ($this->_cachedVideos) {
         return $this->_cachedVideos;
     }
     $youtube = new YoutubeService();
     $page = isset($_GET['page']) ? (int) $_GET['page'] : 1;
     $start_index = ($page - 1) * $pp + 1;
     switch ($this->Method) {
         case 1:
             $videos = $youtube->getVideosByQuery($this->Query, $pp, $start_index, $this->Sortby);
             break;
         case 2:
             $videos = $youtube->getVideosByCategoryTag($this->CategoryTag, $pp, $start_index, $this->Sortby);
             break;
         case 3:
             $videos = $youtube->getVideosUploadedByUser($this->User, $pp, $start_index, $this->Sortby);
             break;
         case 4:
             $videos = $youtube->getFavoriteVideosByUser($this->User, $pp, $start_index, $this->Sortby);
             break;
         case 5:
             $videos = $youtube->getPlaylist($this->Playlist, $pp, $start_index, $this->Sortby);
             break;
     }
     // caching
     $this->_cachedVideos = $videos;
     if (!$videos->First()) {
         if ($this->Method == 3) {
             $videos = $youtube->getFavoriteVideosByUser($this->User, $pp, $start_index, $this->Sortby);
         }
     }
     return $videos;
 }
 function Videos()
 {
     $youtube = new YoutubeService();
     try {
         switch ($this->Method) {
             case 1:
                 $videos = $youtube->getVideosUploadedByUser($this->User);
                 break;
             case 2:
                 $videos = $youtube->getFavoriteVideosByUser($this->User);
                 break;
         }
     } catch (Exception $e) {
         return false;
     }
     $output = new DataObjectSet();
     foreach ($videos as $video) {
         $videoId = array_pop(explode("/", $video->id));
         $output->push(new ArrayData(array("Title" => $video->title, "Link" => $video->player_url, "Image" => $video->thumbnail_url, "Duration" => round((double) $video->content_duration / 60, 2))));
     }
     return $output;
 }
Пример #3
0
 function getLatestYoutubeVideos($num)
 {
     $username = '******';
     $youtube = new YoutubeService();
     $videos1 = $youtube->getVideosUploadedByUser($username, $num, 1, 'published');
     $videos2 = $youtube->getFavoriteVideosByUser($username, $num, 1, 'published');
     $videos = new DataObjectSet();
     $videos->merge($videos1);
     $videos->merge($videos2);
     return $videos;
 }
 /**
  * Gets data about this video from youtube. Needs to get the file ID, and then query details about that ID
  * 
  * @param string $video Either the URL to a video (e.g. http://www.youtube.com/watch?v=EQ2vLdFTaT0) or the video ID (EQ2vLdFTaT0). 
  */
 function getDataFromService($videoStr)
 {
     // Parse the ID number out of the url only if we have to
     if (preg_match('/watch\\?v\\=/', $videoStr)) {
         preg_match('/watch\\?v\\=([^&]*)/', $videoStr, $matches);
         if (!isset($matches[1])) {
             return "ERROR";
         }
         $videoStr = $matches[1];
     }
     // Now that we have a number, look it up with youtube
     $youtubeService = new YoutubeService();
     $response = $youtubeService->getVideoInfo($videoStr);
     // Returns all pertinent information about one video, identified by the video ID
     if (isset($response)) {
         $this->response = $response;
     } else {
         $this->response = "ERROR";
     }
 }