Skip to content

Instantly share code, notes, and snippets.

@valentindotxyz
Created February 12, 2014 06:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save valentindotxyz/8950918 to your computer and use it in GitHub Desktop.
Save valentindotxyz/8950918 to your computer and use it in GitHub Desktop.
// Get the post image
if(!function_exists('get_post_video_thumbnail')){
function get_post_video_thumbnail( $post_id, $size = 'maxresdefault' ) {
$video_url = get_post_meta( $post_id, 'blu_video_url', true );
if($video_url) {
$video_url = html_entity_decode($video_url);
$url = $video_url;
$urls = parse_url($url);
if ($urls['host'] == 'youtu.be') :
$imgPath = ltrim($urls['path'],'/');
elseif ($urls['host'] == 'vimeo.com') :
$imgId = end(explode('/',$urls['path']));
return get_vimeo_thumbnail($imgId);
elseif (strpos($urls['path'],'embed') == 1) :
$imgPath = end(explode('/',$urls['path']));
elseif (strpos($url,'/') === false):
$imgPath = $url;
else :
parse_str($urls['query']);
$imgPath = $v;
endif;
return 'http://img.youtube.com/vi/'.$imgPath.'/'.$size.'.jpg';
} else {
return false;
}
}
}
// Get the vimeo thumbnail
if(!function_exists('get_vimeo_thumbnail')) {
function get_vimeo_thumbnail($id) {
if (!function_exists('curl_init')) die('CURL is not installed!');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://vimeo.com/api/v2/video/$id.php");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$output = unserialize(curl_exec($ch));
$output = $output[0];
curl_close($ch);
return $output['thumbnail_large'];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment