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;
 }
 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;
 }