Skip to content

Instantly share code, notes, and snippets.

@valentindotxyz
Created February 12, 2014 06:31
Show Gist options
  • Select an option

  • Save valentindotxyz/8950918 to your computer and use it in GitHub Desktop.

Select an option

Save valentindotxyz/8950918 to your computer and use it in GitHub Desktop.

Revisions

  1. Valentin created this gist Feb 12, 2014.
    45 changes: 45 additions & 0 deletions Vimeo-thumbnail
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,45 @@
    // 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'];
    }
    }