예제 #1
0
 /**
  * Returns the video thumb url from the video URL
  * @param $videoUrl
  * @return string
  */
 private static function get_thumb_url($videoUrl)
 {
     switch (self::detect_video_service($videoUrl)) {
         case 'youtube':
             $yt_1920_url = td_global::$http_or_https . '://img.youtube.com/vi/' . self::get_youtube_id($videoUrl) . '/maxresdefault.jpg';
             $yt_640_url = td_global::$http_or_https . '://img.youtube.com/vi/' . self::get_youtube_id($videoUrl) . '/sddefault.jpg';
             $yt_480_url = td_global::$http_or_https . '://img.youtube.com/vi/' . self::get_youtube_id($videoUrl) . '/hqdefault.jpg';
             if (!self::is_404($yt_1920_url)) {
                 return $yt_1920_url;
             } elseif (!self::is_404($yt_640_url)) {
                 return $yt_640_url;
             } elseif (!self::is_404($yt_480_url)) {
                 return $yt_480_url;
             } else {
                 td_log::log(__FILE__, __FUNCTION__, 'No suitable thumb found for youtube.', $videoUrl);
             }
             break;
         case 'dailymotion':
             $dailymotion_api_json = td_remote_http::get_page('https://api.dailymotion.com/video/' . self::get_dailymotion_id($videoUrl) . '?fields=thumbnail_url', __CLASS__);
             if ($dailymotion_api_json !== false) {
                 $dailymotion_api = @json_decode($dailymotion_api_json);
                 if ($dailymotion_api === null and json_last_error() !== JSON_ERROR_NONE) {
                     td_log::log(__FILE__, __FUNCTION__, 'json decaode failed for daily motion api', $videoUrl);
                     return '';
                 }
                 if (!empty($dailymotion_api) and !empty($dailymotion_api->thumbnail_url)) {
                     return $dailymotion_api->thumbnail_url;
                 }
             }
             break;
         case 'vimeo':
             //@todo e stricat nu mai merge de ceva timp cred
             $url = 'http://vimeo.com/api/oembed.json?url=https://vimeo.com/' . self::get_vimeo_id($videoUrl);
             $response = wp_remote_get($url, array('timeout' => 10, 'sslverify' => false, 'user-agent' => 'Mozilla/5.0 (Windows NT 6.3; WOW64; rv:35.0) Gecko/20100101 Firefox/35.0'));
             if (!is_wp_error($response)) {
                 $td_result = @json_decode(wp_remote_retrieve_body($response));
                 return $td_result->thumbnail_url;
             }
             break;
     }
     return '';
 }
예제 #2
0
 /**
  * Pulls information about multiple vimeo IDs but for each id it makes an api call
  * @param $video_ids
  *
  * @return array|bool
  */
 private static function vimeo_api_get_videos_info($video_ids)
 {
     $buffy_videos = array();
     foreach ($video_ids as $video_id) {
         $api_url = 'http://vimeo.com/api/v2/video/' . $video_id . '.php';
         // this is the old api vimeo maintained for thumbnail_small which should not be gotten without OAuth of the new api
         $php_serialized_api_response = td_remote_http::get_page($api_url, __CLASS__);
         // check for a response
         if ($php_serialized_api_response === false) {
             td_log::log(__FILE__, __FUNCTION__, 'api call failed', $api_url);
             continue;
             // try with the next one
         }
         // try to deserialize
         $api_response = @unserialize($php_serialized_api_response);
         if ($api_response === false) {
             td_log::log(__FILE__, __FUNCTION__, 'Error decoding the php serialized vimeo api', $api_response);
             continue;
         }
         @($buffy_videos[$video_id] = array('thumb' => $api_response[0]['thumbnail_small'], 'title' => $api_response[0]['title'], 'time' => gmdate("H:i:s", intval($api_response[0]['duration']))));
     }
     // return false on no videos
     if (!empty($buffy_videos)) {
         return $buffy_videos;
     }
     return false;
 }
예제 #3
0
 /**
  * curl download channel
  * @param $url
  * @param string $caller_id
  *
  * @return bool|mixed
  */
 private static function get_url_curl($url, $caller_id = '')
 {
     //return false;
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, $url);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     //mergem dupa redirecturi
     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
     curl_setopt($ch, CURLOPT_MAXREDIRS, 3);
     //max redirects
     curl_setopt($ch, CURLOPT_ENCODING, '');
     //folosim compresia - daca e empty trimite toate formele de compresie suportate
     //timeout? - 300 sec = 5 min
     curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, self::http_request_timeout);
     //Fail if a web server doesn’t respond to a connection within a time limit (seconds).
     curl_setopt($ch, CURLOPT_TIMEOUT, self::http_request_timeout);
     //Fail if a web server doesn’t return the web page within a time limit (seconds).
     curl_setopt($ch, CURLOPT_HEADER, false);
     // misc
     curl_setopt($ch, CURLOPT_AUTOREFERER, true);
     //The referer is a URL for the web page that linked to the requested web page. When following redirects, set this to true and CURL automatically fills in the URL of the page being redirected away from.
     curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 5.1; rv:31.0) Gecko/20100101 Firefox/31.0');
     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
     $data = curl_exec($ch);
     //error checking
     if ($data === false) {
         td_log::log(__FILE__, __FUNCTION__, 'caller_id:' . $caller_id . ' curl_exec returned FALSE (AKA Error) curl_error:' . curl_error($ch) . ' curl_getinfo attached to this message', curl_getinfo($ch));
         curl_close($ch);
         return false;
     }
     curl_close($ch);
     return $data;
 }