コード例 #1
0
 /**
  * Retrieve user's uploaded videos.
  *
  * @param $maxResults int
  *       	 Maximum number of YoutubeVideo to return.
  * @return array(YoutubeVideo) Videos retrieved.
  */
 public function getVideos($maxResults)
 {
     try {
         set_include_path(get_include_path() . PATH_SEPARATOR . dirname(WSW_Main::$plugin_dir) . '/lib/Youtube');
         if (!class_exists('Zend_Loader')) {
             require_once 'Zend/Loader.php';
         }
         Zend_Loader::loadClass('Zend_Gdata_Query');
         Zend_Loader::loadClass('Zend_Gdata_YouTube');
         // If the keyword is compoused, divide each word
         $key_phrase = $this->keyword;
         $key_phrase_arr = explode(' ', $key_phrase);
         $query_url = Zend_Gdata_YouTube::VIDEO_URI . "/-/";
         foreach ($key_phrase_arr as $key_phrase_item) {
             if (trim($key_phrase_item) != '') {
                 $query_url .= trim($key_phrase_item) . '/';
             }
         }
         //$query_url .= '?v=2';
         $query = new Zend_Gdata_Query($query_url);
         $query->setMaxResults($maxResults);
         $query->setParam('orderby', 'viewCount');
         $yt = new Zend_Gdata_YouTube();
         $yt->setMajorProtocolVersion(2);
         $videoFeed = $yt->getFeed($query, 'Zend_Gdata_YouTube_VideoFeed');
         // TODO See how this initialization must be done, I mean if is really neccesary
         $keyVideos = array();
         foreach ($videoFeed as $videoEntry) {
             $keyVideos[] = new WSW_YoutubeVideo($videoEntry);
         }
         return $keyVideos;
     } catch (Exception $e) {
         // Store to log
         $msg_to_log = 'Error while getVideos from Youtube, Url: ' . $query_url . ', Exception Msg: ' . $e->getMessage();
         return array();
     }
 }
コード例 #2
0
ファイル: YoutubeVideo.php プロジェクト: Kishor900/scrapboard
 /**
  *
  * @param $maxResults int
  *       	 Maximum number of YoutubeVideo to return.
  * @return array(YoutubeVideo) Videos retrieved.
  */
 public function getRelatedVideos($maxResults)
 {
     try {
         if (!class_exists('Zend_Loader')) {
             require_once WPPostsRateKeys::$plugin_dir . 'classes/YoutubeWordpress/Zend/Loader.php';
         }
         Zend_Loader::loadClass('Zend_Gdata_Query');
         Zend_Loader::loadClass('Zend_Gdata_YouTube');
         $query = new Zend_Gdata_Query(Zend_Gdata_YouTube::VIDEO_URI . "/{$this->videoEntry->getVideoId()}/" . Zend_Gdata_YouTube::RELATED_URI_SUFFIX);
         $query->setMaxResults($maxResults);
         $yt = new Zend_Gdata_YouTube();
         $yt->setMajorProtocolVersion(2);
         $relatedVideosFeed = $yt->getFeed($query, 'Zend_Gdata_YouTube_VideoFeed');
         // TODO See how this initialization must be done, I mean if is really neccesary.
         $relatedVideos = array();
         foreach ($relatedVideosFeed as $relatedVideoEntry) {
             $relatedVideos[] = new YoutubeVideo($relatedVideoEntry);
         }
         return $relatedVideos;
     } catch (Exception $e) {
         // Store to log
         $msg_to_log = 'Error while getRelatedVideos from Youtube' . ', Exception Msg: ' . $e->getMessage();
         // Add log
         WPPostsRateKeys_Logs::add_error('362', $msg_to_log);
         return array();
     }
 }