Пример #1
0
function searchAndPrint($searchTerms = 'sesame street')
{
    $yt = new Zend_Gdata_YouTube();
    $yt->setMajorProtocolVersion(2);
    $query = $yt->newVideoQuery();
    $query->setOrderBy('relevance');
    $query->setSafeSearch('moderate');
    $query->setVideoQuery($searchTerms);
    $query->setParam('caption', 'true');
    $query->setParam('start-index', $_GET['start_index']);
    $query->setParam('max-results', 8);
    //$query->setParam('max-results','2');
    // Note that we need to pass the version number to the query URL function
    // to ensure backward compatibility with version 1 of the API.
    //echo $query->getQueryUrl(2);
    //$videoFeed = $yt->getVideoFeed("http://gdata.youtube.com/feeds/api/videos?orderby=relevance&safeSearch=moderate&q=sesame+street");
    $videoFeed = $yt->getVideoFeed($query->getQueryUrl(2));
    $links = $videoFeed->getLink();
    $suggestFlag = null;
    foreach ($links as $link) {
        if ($link->getRel() == 'http://schemas.google.com/g/2006#spellcorrection') {
            $videoFeed = $yt->getVideoFeed($link->getHref());
            //print_r($link->getTitle());
            $suggestFlag = $link->getTitle();
            break;
        }
    }
    //if($links[1]){
    //}
    printVideoFeed($videoFeed, $suggestFlag);
    //'Search results for: ' . $searchTerms);
}
Пример #2
0
 public function getVideosByPlaylist($playlistId, $page = 0)
 {
     /* @var $ytq Zend_Gdata_YouTube_VideoQuery */
     $ytq = $this->yt->newVideoQuery("http://gdata.youtube.com/feeds/api/playlists/" . $playlistId);
     $page = $page * self::ITEMS_PER_PAGE;
     $ytq->setStartIndex($page == 0 ? $page : $page + 1);
     $ytq->setMaxResults(self::ITEMS_PER_PAGE);
     $ytq->setOrderBy('position');
     return $this->yt->getPlaylistVideoFeed($ytq);
 }
Пример #3
0
 /**
  * Функция получения результатов поиска по серверу YT в виде объекта VideoFeed.
  * @param string $searchString строка поиска.
  * @return VideoFeed - возвращает объект VideoFeed 
  */
 function searchOnYT($searchString, $startID = 0)
 {
     $yt = new Zend_Gdata_YouTube($this->authYT($username, $password));
     $query = $yt->newVideoQuery();
     $query->videoQuery = $searchString;
     $query->startIndex = $startID;
     $query->maxResults = VideoThing::FILES_COUNT;
     $query->orderBy = 'viewCount';
     //echo $query->queryUrl . "\n <br />";
     $videoFeed = $yt->getVideoFeed($query);
     return $videoFeed;
 }
Пример #4
0
/**
 * Returns a feed of videos related to the specified video
 *
 * @param string $videoId The video
 * @return Zend_Gdata_YouTube_VideoFeed The feed of related videos
 */
function getRelatedVideos($videoId)
{
    $yt = new Zend_Gdata_YouTube();
    $ytQuery = $yt->newVideoQuery();
    // show videos related to the specified video
    $ytQuery->setFeedType('related', $videoId);
    // order videos by rating
    $ytQuery->setOrderBy('rating');
    // retrieve a maximum of 5 videos
    $ytQuery->setMaxResults(5);
    // retrieve only embeddable videos
    $ytQuery->setFormat(5);
    return $yt->getVideoFeed($ytQuery);
}
function searchAndPrint($searchTerms)
{
    $yt = new Zend_Gdata_YouTube();
    $yt->setMajorProtocolVersion(2);
    $query = $yt->newVideoQuery();
    $query->setOrderBy('relevance');
    //$query->setSafeSearch('moderate');
    $query->settime('today');
    $query->setMaxResults(6);
    $query->setVideoQuery($searchTerms);
    // Note that we need to pass the version number to the query URL function
    // to ensure backward compatibility with version 1 of the API.
    $videoFeed = $yt->getVideoFeed($query->getQueryUrl(2));
    printVideoFeed($videoFeed);
    //, 'Search results for: ' . $searchTerms);
}
Пример #6
0
 /**
  * Retrieve video of based upon a given category
  *
  * @access public
  * @param int $maxResults
  * @return gVideo
  */
 public function getCategoryVideos($maxResults = 15)
 {
     if ($this->getCategory() == '') {
         throw new Exception("Empty categories are not allowed");
     } else {
         try {
             $yt = new Zend_Gdata_YouTube();
             $query = $yt->newVideoQuery();
             $query->category = $this->getCategory();
             $query->maxResults = $maxResults;
             $videoFeed = $yt->getVideoFeed($query);
             foreach ($videoFeed as $videoEntry) {
                 $gVideo = new CW_Google_Video_YouTube('', $videoEntry->mediaGroup->title->text, $videoEntry->getPublished(), $videoEntry->getId(), $videoEntry->updated->text, $videoEntry->mediaGroup->duration->seconds, $videoEntry->mediaGroup->content[0]->medium, $videoEntry->comments->feedLink->getHref(), $videoEntry->mediaGroup->content[0]->url, $videoEntry->mediaGroup->keywords->text, $videoEntry->mediaGroup->thumbnail[0]->url, $videoEntry->mediaGroup->thumbnail[0]->width, $videoEntry->mediaGroup->thumbnail[0]->height, $videoEntry->mediaGroup->thumbnail[0]->time, $videoEntry->mediaGroup->player[0]->url, $videoEntry->mediaGroup->category[0]->text, $videoEntry->getContent(), $videoEntry->mediaGroup->description->text, $videoEntry->getRating(), $videoEntry->getRacy(), $videoEntry->getStatistics()->getViewCount());
                 $this->setVideos($gVideo);
             }
         } catch (Zend_Gdata_App_Exception $ex) {
             print $ex->getMessage();
         } catch (Exception $e) {
             print $e->getMessage();
         }
     }
     return $this->getVideos();
 }
 function video()
 {
     $videoId = $this->params['id'];
     $yt = new Zend_Gdata_YouTube();
     $entry = $yt->getVideoEntry($videoId);
     $this->set('videoTitle', $entry->mediaGroup->title);
     $this->set('description', $entry->mediaGroup->description);
     $this->set('authorUsername', $entry->author[0]->name);
     $this->set('authorUrl', 'http://www.youtube.com/profile?user='******'tags', $entry->mediaGroup->keywords);
     $this->set('duration', $entry->mediaGroup->duration->seconds);
     $this->set('watchPage', $entry->mediaGroup->player[0]->url);
     $this->set('viewCount', $entry->statistics->viewCount);
     $this->set('rating', $entry->rating->average);
     $this->set('numRaters', $entry->rating->numRaters);
     /* Get related Videos */
     $ytQuery = $yt->newVideoQuery();
     $ytQuery->setFeedType('related', $videoId);
     $ytQuery->setOrderBy('rating');
     $ytQuery->setMaxResults(5);
     $ytQuery->setFormat(5);
     $this->set('videoId', $videoId);
     $this->set('related', $yt->getVideoFeed($ytQuery));
 }
Пример #8
0
 /**
  * youtube search
  * using Zend_Gdate_YouTube() class
  *
  */
 public function youtubeSearch($keyword = null, $per_page = '25', $start_index = '1')
 {
     $yt = new Zend_Gdata_YouTube();
     $yt_query = $yt->newVideoQuery();
     $yt_query->videoQuery = urlencode($keyword);
     $yt_query->startIndex = $start_index;
     $yt_query->maxResults = $per_page;
     $yt_query->orderBy = 'viewCount';
     $yt_query->Format = '5';
     $request = $yt->getVideoFeed($yt_query);
     if (!$request) {
         throw new Exception("There was an error loading the youtubeSearch Data ");
     }
     return $request;
 }
Пример #9
0
 public function getYoutubeVideoSuggestions()
 {
     if (Mage::helper('videogallery')->isVideoSuggestionsEnabled() == false) {
         return array();
     }
     if (!$this->_youtubeFeed) {
         try {
             $product = $this->getProduct();
             if (!$product->getId()) {
                 return array();
             }
             $yt = new Zend_Gdata_YouTube();
             $yt->getHttpClient()->setConfig(array('timeout' => 10));
             $query = $yt->newVideoQuery();
             $query->videoQuery = $product->getName() . ' ' . $product->getSku();
             $query->startIndex = 0;
             $query->maxResults = 5;
             $results = $yt->getVideoFeed($query);
             $this->_youtubeFeed = array();
             foreach ($results as $video) {
                 if ($this->videoAlreadyAdded($video->getVideoId())) {
                     continue;
                 }
                 $this->_youtubeFeed[] = $video;
             }
         } catch (Exception $e) {
             return "Error Retrieving Video Suggestions from Youtube: " . $e->getMessage();
         }
     }
     return $this->_youtubeFeed;
 }
 /**
  * @group ZF-8720
  */
 public function testQueryExclamationMarkRemoveBug()
 {
     $yt = new Zend_Gdata_YouTube();
     $query = $yt->newVideoQuery();
     $location = '37.42307,-122.08427';
     $this->assertNull($query->setLocation($location));
     $this->assertEquals($location, $query->getLocation());
     $location = '37.42307,-122.08427!';
     $this->assertNull($query->setLocation($location));
     $this->assertEquals($location, $query->getLocation());
 }
Пример #11
0
function searchRandomVideo($searchTerms)
{
    global $maxSearchResults;
    //error_log("max results " . $maxSearchResults);
    $yt = new Zend_Gdata_YouTube();
    $yt->setMajorProtocolVersion(2);
    $query = $yt->newVideoQuery();
    // $query->setOrderBy('relevance');
    // $query->setOrderBy('viewCount');
    //  $query->setOrderBy('random');
    $query->setSafeSearch('none');
    $query->setVideoQuery($searchTerms);
    $query->setMaxResults($maxSearchResults);
    // Note that we need to pass the version number to the query URL function
    // to ensure backward compatibility with version 1 of the API.
    $videoFeed = $yt->getVideoFeed($query->getQueryUrl(2));
    // printVideoFeed($videoFeed, 'Search results for: ' . $searchTerms);
    $randVideoEntry = getRandomVideo($videoFeed);
    return $randVideoEntry;
}
Пример #12
0
 public function executeSearchYoutube(sfWebRequest $request)
 {
     ini_set('display_errors', false);
     $util = new Util();
     $yt = new Zend_Gdata_YouTube();
     $yt->setMajorProtocolVersion(2);
     $query = $yt->newVideoQuery();
     $query->setSafeSearch('none');
     $query->setMaxResults(10);
     $query->setVideoQuery($request->getPostParameter('data'));
     // Note that we need to pass the version number to the query URL function
     // to ensure backward compatibility with version 1 of the API.
     $videoFeed = $yt->getVideoFeed($query->getQueryUrl(2));
     $html = $util->printVideoFeed($videoFeed);
     echo $html;
     return sfView::NONE;
 }
Пример #13
0
    $crawl_string .= ($i == 0 ? '' : ' OR ') . 'matchdate BETWEEN FROM_UNIXTIME(' . ($period - CRAWLER_REPEAT_PERIOD * $i - CRAWLER_RANGE) . ") AND FROM_UNIXTIME(" . ($period - CRAWLER_REPEAT_PERIOD * $i) . ")";
}
$matches = array();
$result = mysql_query("SELECT * FROM matchids WHERE " . $crawl_string . " or sessionid = 680462533 LIMIT 0, 10");
while ($row = mysql_fetch_array($result)) {
    if ($row['sessionid'] > 1000000) {
        $matches["match_" . strtolower(dechex($row['sessionid']))] = $row;
    }
}
echo 'Crawling ' . count($matches) . ' match(es)<br/>';
$matchlist = implode(' | ', array_keys($matches));
if (empty($matchlist)) {
    die;
}
echo $matchlist . "<br/>";
$query = $yt->newVideoQuery();
$query->setVideoQuery($matchlist);
$query->setMaxResults(50);
$videoFeed = $yt->getVideoFeed($query->getQueryUrl(2));
foreach ($videoFeed as $videoEntry) {
    preg_match_all("/(Scout|Soldier|Pyro|Demoman|Heavy|Engineer|Medic|Sniper|Spy)|match_([0-9a-f]{6,})/", implode("|", $videoEntry->getVideoTags()), $matchid);
    $authobj = $videoEntry->getAuthor();
    $matchinfo = $matches[$matchid[0][1]];
    if (mysql_num_rows(mysql_query("SELECT youtubeid FROM videos WHERE youtubeid = '" . $videoEntry->getVideoId() . "'")) != 0) {
        mysql_query("UPDATE videos SET title = '" . mysql_real_escape_string($videoEntry->getVideoTitle()) . "', description = '" . mysql_real_escape_string($videoEntry->getVideoDescription()) . "' WHERE youtubeid = '" . $videoEntry->getVideoId() . "'");
        echo mysql_error();
    } else {
        $nextmatch = mysql_fetch_array(mysql_query("SELECT * FROM matchids WHERE matchdate > '" . $matchinfo['matchdate'] . "' AND serverid = " . $matchinfo['serverid'] . " LIMIT 1"));
        mysql_query("INSERT INTO videos ( youtubeid, youtubeuser, map, sessionid, matchdate, matchduration, role, serverid, duration, title, description ) VALUES ( '" . $videoEntry->getVideoId() . "', '" . $authobj[0]->getName() . "', '" . $matchinfo['mapname'] . "', '" . $matchinfo['sessionid'] . "', '" . $matchinfo['matchdate'] . "', '" . (strtotime($nextmatch['matchdate']) - strtotime($matchinfo['matchdate'])) . "', '" . $matchid[0][0] . "', '" . $matchinfo['serverid'] . "', '" . $videoEntry->getVideoDuration() . "', '" . mysql_real_escape_string($videoEntry->getVideoTitle()) . "', '" . mysql_real_escape_string($videoEntry->getVideoDescription()) . "' )");
        echo mysql_error();
        $yt->insertEntry($videoEntry, $yt->getUserFavorites("LethalZone")->getSelfLink()->href);
Пример #14
0
 * DEPENDENCIES: PHP 5.2.4+, ZEND FRAMEWORK, GDATA API
 *
 * This script expects an operation variable from the URI.
 * This can include: search, confirm, submit
 *
 */
if (isset($_GET['search'])) {
    /*
     * Loading the Zend GDATA API.
     */
    require_once 'Zend/Loader.php';
    Zend_Loader::loadClass('Zend_Gdata_YouTube');
    Zend_Loader::loadClass('Zend_Gdata_AuthSub');
    Zend_Loader::loadClass('Zend_Gdata_App_Exception');
    $youTubeService = new Zend_Gdata_YouTube();
    $query = $youTubeService->newVideoQuery();
    $query->setQuery($_POST['search']);
    $query->setStartIndex(0);
    $query->setMaxResults(9);
    $query->setFormat('5');
    $feed = $youTubeService->getVideoFeed($query);
    /* Grabs the data received from Gdata and converts it into a nice array
    	for people like me to work with. Its just so I handle the data better.
    	It basically puts in the title of the video, the ID of the video,
    	the link to the video and the URL of the largest thumbnail possible */
    $i = 0;
    $youtubeData = array();
    foreach ($feed as $entry) {
        $youtubeData[$i]['title'] = $entry->getVideoTitle();
        $youtubeData[$i]['id'] = $entry->getVideoId();
        $youtubeData[$i]['video'] = $entry->getFlashPlayerUrl();
Пример #15
0
 function getRelevantVideos($searchTerms, $maxResults = 50)
 {
     if ($maxResults > 50) {
         $maxResults = 50;
         // No more than 50 results allowed by Youtube.com
     }
     try {
         $yt = new Zend_Gdata_YouTube();
         $yt->setMajorProtocolVersion(2);
         $query = $yt->newVideoQuery();
         $query->setOrderBy('relevance');
         $query->setSafeSearch('none');
         $query->setMaxResults($maxResults);
         $query->setVideoQuery($searchTerms);
         // Note that we need to pass the version number to the query URL function
         // to ensure backward compatibility with version 1 of the API.
         $videoFeed = $yt->getVideoFeed($query->getQueryUrl(2));
         return $videoFeed;
     } catch (Zend_Gdata_App_HttpException $httpException) {
         //echo ("App HttpException Thrown<br>\n");
         $response = $httpException->getRawResponseBody();
     } catch (Zend_Gdata_App_Exception $e) {
         //echo ("App Exception Thrown<br>\n");
         $response = $e->getMessage();
     } catch (Exception $except) {
         //echo ("Exception Thrown<br>\n");
         $response = $except->getMessage();
     }
     echo "Error: {$response}<br>";
     return null;
 }
Пример #16
0
 /**
  * getvideoselectAction
  * @author Thomas Schedler <*****@*****.**>
  * @version 1.0
  */
 public function getvideoselectAction()
 {
     $this->core->logger->debug('core->controllers->VideoController->getvideoselectAction()');
     try {
         $arrVideos = array();
         $objRequest = $this->getRequest();
         $intChannelId = $objRequest->getParam('channelId');
         $strChannelUserId = $objRequest->getParam('channelUserId');
         $strElementId = $objRequest->getParam('elementId');
         $strValue = $objRequest->getParam('value');
         $strSearchQuery = $objRequest->getParam('searchString');
         switch ($intChannelId) {
             /*
              * Vimeo Controller
              */
             case $this->core->sysConfig->video_channels->vimeo->id:
                 /**
                  * Requires simplevimeo base class
                  */
                 require_once GLOBAL_ROOT_PATH . 'library/vimeo/vimeo.class.php';
                 $arrChannelUser = $this->core->sysConfig->video_channels->vimeo->users->user->toArray();
                 $intVideoTypeId = 1;
                 $arrVideos = array();
                 /**
                  * Get the vimeo video list
                  */
                 if ($strChannelUserId !== '' && $strChannelUserId !== 'publicAccess' && $strSearchQuery == '') {
                     if (is_array($arrChannelUser)) {
                         foreach ($arrChannelUser as $chUser) {
                             if ($chUser['id'] == $strChannelUserId) {
                                 $objResponse = VimeoVideosRequest::getList($strChannelUserId);
                             }
                         }
                     }
                     $arrVideos = $objResponse->getVideos();
                 } else {
                     if ($strChannelUserId !== '' && isset($strSearchQuery)) {
                         if ($strChannelUserId == 'publicAccess') {
                             $objResponse = VimeoVideosRequest::search($strSearchQuery);
                         } else {
                             $objResponse = VimeoVideosRequest::search($strSearchQuery, $strChannelUserId);
                         }
                         $arrVideos = $objResponse->getVideos();
                     }
                 }
                 // Set channel Users
                 $this->view->channelUsers = array_key_exists('id', $arrChannelUser) ? array(0 => $arrChannelUser) : $this->core->sysConfig->video_channels->vimeo->users->user->toArray();
                 break;
                 /**
                  * Youtube Controller
                  */
             /**
              * Youtube Controller
              */
             case $this->core->sysConfig->video_channels->youtube->id:
                 $arrChannelUser = $this->core->sysConfig->video_channels->youtube->users->user->toArray();
                 $intVideoTypeId = 2;
                 $objResponse = new Zend_Gdata_YouTube();
                 $objResponse->setMajorProtocolVersion(2);
                 if ($strChannelUserId !== '' && $strSearchQuery == '' && $strChannelUserId !== 'publicAccess') {
                     $arrVideos = $objResponse->getuserUploads($strChannelUserId);
                 } else {
                     if (isset($strChannelUserId) && isset($strSearchQuery)) {
                         if ($strChannelUserId !== 'publicAccess') {
                             $arrVideos = $objResponse->getVideoFeed('http://gdata.youtube.com/feeds/api/users/' . $strChannelUserId . '/uploads?q=' . urlencode($strSearchQuery));
                         } else {
                             $objQuery = $objResponse->newVideoQuery();
                             $objQuery->setOrderBy('viewCount');
                             $objQuery->setSafeSearch('none');
                             $objQuery->setVideoQuery($strSearchQuery);
                             $arrVideos = $objResponse->getVideoFeed($objQuery->getQueryUrl(2));
                         }
                     }
                 }
                 // Set Channel Users
                 $this->view->channelUsers = array_key_exists('id', $arrChannelUser) ? array(0 => $arrChannelUser) : $this->core->sysConfig->video_channels->youtube->users->user->toArray();
                 break;
         }
         $this->view->videoTypeId = $intVideoTypeId;
         $this->view->elements = $arrVideos;
         $this->view->channelUserId = $strChannelUserId;
         $this->view->value = $strValue;
         $this->view->elementId = $strElementId;
         $this->view->SearchQuery = $strSearchQuery;
     } catch (Exception $exc) {
         $this->core->logger->err($exc);
         exit;
     }
 }
Пример #17
0
 /**
  * @group ZF-12500
  */
 public function testQueryUrlForFeedTypComments()
 {
     $yt = new Zend_Gdata_YouTube();
     // Query
     $query = $yt->newVideoQuery();
     $query->setFeedType('comments', 'foo');
     // Test
     $this->assertSame('https://gdata.youtube.com/feeds/api/videos/foo/comments', $query->getQueryUrl());
 }
Пример #18
0
 /**
  * getvideoselectAction
  * @author Thomas Schedler <*****@*****.**>
  * @version 1.0
  */
 public function getvideoselectAction()
 {
     $this->core->logger->debug('core->controllers->VideoController->getvideoselectAction()');
     try {
         $arrVideos = array();
         $objRequest = $this->getRequest();
         $intChannelId = $objRequest->getParam('channelId');
         $strChannelUserId = $objRequest->getParam('channelUserId', '');
         $strElementId = $objRequest->getParam('elementId');
         $strValue = $objRequest->getParam('value');
         $strSearchQuery = $objRequest->getParam('searchString');
         switch ($intChannelId) {
             /*
              * Vimeo Controller
              */
             case $this->core->sysConfig->video_channels->vimeo->id:
                 /**
                  * Requires simplevimeo base class
                  */
                 require_once GLOBAL_ROOT_PATH . 'library/vimeo/vimeo.class.php';
                 $arrChannelUser = $this->core->sysConfig->video_channels->vimeo->users->user->toArray();
                 $intIdVideoType = 1;
                 if (array_key_exists('id', $arrChannelUser)) {
                     // Now lets do the user search query. We will get an response object containing everything we need
                     $objResponse = VimeoVideosRequest::getList($this->core->sysConfig->video_channels->vimeo->users->user->id);
                     // We want the result videos as an array of objects
                     $arrVideos = $objResponse->getVideos();
                 } else {
                     if ($strChannelUserId !== '') {
                         if (is_array($arrChannelUser)) {
                             foreach ($arrChannelUser as $chUser) {
                                 if ($chUser['id'] == $strChannelUserId) {
                                     // Now lets do the user search query. We will get an response object containing everything we need
                                     $objResponse = VimeoVideosRequest::getList($strChannelUserId);
                                     // We want the result videos as an array of objects
                                     $arrVideos = $objResponse->getVideos();
                                 }
                             }
                         }
                     }
                 }
                 // Set Channel Users
                 $this->view->channelUsers = array_key_exists('id', $arrChannelUser) ? array() : $this->core->sysConfig->video_channels->vimeo->users->user->toArray();
                 break;
                 /**
                  * Youtube Controller
                  */
             /**
              * Youtube Controller
              */
             case $this->core->sysConfig->video_channels->youtube->id:
                 $arrChannelUser = $this->core->sysConfig->video_channels->youtube->users->user->toArray();
                 $intIdVideoType = 2;
                 $objResponse = new Zend_Gdata_YouTube();
                 $objResponse->setMajorProtocolVersion(2);
                 if (array_key_exists('id', $arrChannelUser) && $strSearchQuery === '') {
                     $arrVideos = $objResponse->getuserUploads($this->core->sysConfig->video_channels->youtube->users->user->id);
                 } else {
                     if ($strChannelUserId !== '') {
                         $arrVideos = $objResponse->getuserUploads($strChannelUserId);
                     } else {
                         if ($strSearchQuery !== '') {
                             $query = $objResponse->newVideoQuery();
                             $query->setOrderBy('viewCount');
                             $query->setSafeSearch('none');
                             $query->setVideoQuery($strSearchQuery);
                             $arrVideos = $objResponse->getVideoFeed($query->getQueryUrl(2));
                         }
                     }
                 }
                 // Set Channel Users
                 $this->view->channelUsers = array_key_exists('id', $arrChannelUser) ? array() : $this->core->sysConfig->video_channels->youtube->users->user->toArray();
                 break;
         }
         $this->view->idVideoType = $intIdVideoType;
         $this->view->elements = $arrVideos;
         $this->view->channelUserId = $strChannelUserId;
         $this->view->value = $strValue;
         $this->view->elementId = $strElementId;
     } catch (Exception $exc) {
         $this->core->logger->err($exc);
         exit;
     }
 }
/**
 * Returns a feed of top rated videos for the specified user
 *
 * @param string $user The username
 * @return Zend_Gdata_YouTube_VideoFeed The feed of top rated videos
 */
function getTopRatedVideosByUser($user)
{
    $userVideosUrl = 'http://gdata.youtube.com/feeds/users/' . $user . '/uploads';
    $youTubeService = new Zend_Gdata_YouTube();
    $ytQuery = $youTubeService->newVideoQuery($userVideosUrl);
    // order by the rating of the videos
    $ytQuery->setOrderBy('rating');
    // retrieve a maximum of 5 videos
    $ytQuery->setMaxResults(5);
    // retrieve only embeddable videos
    $ytQuery->setFormat(5);
    return $youTubeService->getVideoFeed($ytQuery);
}
Пример #20
0
function searchYoutube($cat, $searchTerm, $page, $queryType, $maxResults, $startIndex)
{
    $retval = array();
    $data = array();
    if ($queryType === null) {
        /* display the entire interface */
        include '../home.html';
    } else {
        if ($queryType == 'show_video') {
            /* display an individual video */
            if (array_key_exists('videoId', $_REQUEST)) {
                $videoId = $_REQUEST['videoId'];
                $data = echoVideoPlayer($videoId);
            } else {
                echo 'No videoId found.';
                exit;
            }
        } else {
            /* display a list of videos */
            //$searchTerm = $_REQUEST['searchTerm'];
            //$startIndex = $_REQUEST['startIndex'];
            //$maxResults = $_REQUEST['maxResults'];
            $yt = new Zend_Gdata_YouTube();
            $query = $yt->newVideoQuery();
            $query->setQuery($searchTerm);
            $query->setStartIndex($startIndex);
            $query->setMaxResults($maxResults);
            //print_r($query);
            /* check for one of the standard feeds, or list from 'all' videos */
            switch ($queryType) {
                case 'most_viewed':
                    $query->setFeedType('most viewed');
                    $query->setTime('this_week');
                    $feed = $yt->getVideoFeed($query);
                    break;
                case 'most_recent':
                    $query->setFeedType('most recent');
                    $feed = $yt->getVideoFeed($query);
                    break;
                case 'recently_featured':
                    $query->setFeedType('recently featured');
                    $feed = $yt->getVideoFeed($query);
                    break;
                case 'top_rated':
                    $query->setFeedType('top rated');
                    $query->setTime('this_week');
                    $feed = $yt->getVideoFeed($query);
                    break;
                case 'all':
                    $feed = $yt->getVideoFeed($query);
                    break;
                default:
                    echo 'ERROR - unknown queryType - "' . $queryType . '"';
                    break;
            }
            $data = echoVideoList($feed);
            //youtube won't allow search item beyond 1000, namely no page beyond 100 if 10 items/page.
            $totalpages = min(100, $feed->getTotalResults()->text);
        }
    }
    $retval['status'] = 'OK';
    $retval['statusmsg'] = 'OK';
    $retval['data'] = $data;
    $retval['totalpages'] = $totalpages;
    return $retval;
}