Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// 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
You can’t perform that action at this time.