从Vimeo获取图像缩略图?

339

16
没问题,这是翻译的结果:是合法的——两个网站都以非常公开的方式提供这些详细信息,因为他们希望你使用他们的内容!毕竟所有嵌入的视频链接最终都会回到托管站点。 - Magnus Smith
1
如果您想确保页面不依赖于vimeo服务器,并且性能得到优化,我建议您使用JavaScript来实现。缺点是对于没有启用JavaScript的用户,它将无法显示缩略图,但适当的占位符和链接应该足够友好。(在您的vimeo API请求中将“.xml”更改为“.json”) - Myster
1
尝试这个答案:https://dev59.com/yXPYa4cB1Zd3GeqPimsy#17156853 - 它使得仅凭URL就能轻松获取有关任何vimeo视频的信息/数据。 - phirschybar
2
以这种方式,您可以获取视频图像:https://i.vimeocdn.com/video/528073804_200x200.webp - Pus
@Pus,不调用API是否有可能获取Vimeo视频的缩略图?我的意思是,是否有任何URL可以只传递ID,然后它就会返回.jpg缩略图。当我这样做时 http://i.vimeocdn.com/video/201990344.webp 它会返回错误的缩略图。这是我的测试视频链接 https://vimeo.com/201990344 - Farmer
@shailesh的解决方案不再起作用了。 - Shalev Levi
26个回答

12

这是一个快速巧妙的方法,也可以选择自定义尺寸。

我去这里:

http://vimeo.com/api/v2/video/[VIDEO ID].php

下载该文件,打开后找到宽为 640 像素的缩略图,格式应如下所示:

https://i.vimeocdn.com/video/[LONG NUMBER HERE]_640.jpg

您取得这个链接,将其中的640更改为1400(例如),然后您就可以得到类似于以下内容:

https://i.vimeocdn.com/video/[LONG NUMBER HERE]_1400.jpg
将其粘贴到您的浏览器搜索栏中并享受。祝福。

1
我刚刚尝试了vimeo.com/api/v2/video/193641463.php,https://i.vimeocdn.com/video/605393384_640.jpg,https://i.vimeocdn.com/video/605393384_2000.jpg,它确实可以工作。干杯! - Peanuts

10

使用Vimeo网址(https://player.vimeo.com/video/30572181),这是我的示例

<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
    <title>Vimeo</title>
</head>
<body>
    <div>
        <img src="" id="thumbImg">
    </div>
    <script>
        $(document).ready(function () {
            var vimeoVideoUrl = 'https://player.vimeo.com/video/30572181';
            var match = /vimeo.*\/(\d+)/i.exec(vimeoVideoUrl);
            if (match) {
                var vimeoVideoID = match[1];
                $.getJSON('http://www.vimeo.com/api/v2/video/' + vimeoVideoID + '.json?callback=?', { format: "json" }, function (data) {
                    featuredImg = data[0].thumbnail_large;
                    $('#thumbImg').attr("src", featuredImg);
                });
            }
        });
    </script>
</body>
</html>


你是最棒的。 - Alexandr Kazakov

9

看起来api/v2已经失效了。
为了使用新的API,您需要注册您的应用程序,并将client_idclient_secret进行base64编码,并作为授权头部传递。

$.ajax({
    type:'GET',
    url: 'https://api.vimeo.com/videos/' + video_id,
    dataType: 'json',
    headers: {
        'Authorization': 'Basic ' + window.btoa(client_id + ":" + client_secret);
    },
    success: function(data) {
        var thumbnail_src = data.pictures.sizes[2].link;
        $('#thumbImg').attr('src', thumbnail_src);
    }
});

为了安全起见,你可以从服务器返回已编码的client_idclient_secret


1
Base64不是哈希。在服务器上对数据进行Base64编码并不比在客户端上进行编码更“安全”。尽管如此,它可能会更快一些。 - Sumurai8

6

将Karthikeyan P的答案分解,以便在更广泛的场景中使用:

// Requires jQuery

function parseVimeoIdFromUrl(vimeoUrl) {
  var match = /vimeo.*\/(\d+)/i.exec(vimeoUrl);
  if (match)
    return match[1];

  return null;
};

function getVimeoThumbUrl(vimeoId) {
  var deferred = $.Deferred();
  $.ajax(
    '//www.vimeo.com/api/v2/video/' + vimeoId + '.json',
    {
        dataType: 'jsonp',
        cache: true
    }
  )
  .done(function (data) {
    // .thumbnail_small 100x75
    // .thumbnail_medium 200x150
    // 640 wide
        var img = data[0].thumbnail_large;
        deferred.resolve(img);  
    })
  .fail(function(a, b, c) {
    deferred.reject(a, b, c);
  });
  return deferred;
};

使用方法

从 Vimeo 视频 URL 获取 Vimeo Id:

var vimeoId = parseVimeoIdFromUrl(vimeoUrl);

从 Vimeo Id 获取 Vimeo 缩略图 URL:
getVimeoThumbUrl(vimeoIds[0])
.done(function(img) {
    $('div').append('<img src="' + img + '"/>');
});

https://jsfiddle.net/b9chris/nm8L8cc8/1/


6
function parseVideo(url) {
    // - Supported YouTube URL formats:
    //   - http://www.youtube.com/watch?v=My2FRPA3Gf8
    //   - http://youtu.be/My2FRPA3Gf8
    //   - https://youtube.googleapis.com/v/My2FRPA3Gf8
    // - Supported Vimeo URL formats:
    //   - http://vimeo.com/25451551
    //   - http://player.vimeo.com/video/25451551
    // - Also supports relative URLs:
    //   - //player.vimeo.com/video/25451551

    url.match(/(http:|https:|)\/\/(player.|www.)?(vimeo\.com|youtu(be\.com|\.be|be\.googleapis\.com))\/(video\/|embed\/|watch\?v=|v\/)?([A-Za-z0-9._%-]*)(\&\S+)?/);

    if (RegExp.$3.indexOf('youtu') > -1) {
        var type = 'youtube';
    } else if (RegExp.$3.indexOf('vimeo') > -1) {
        var type = 'vimeo';
    }

    return {
        type: type,
        id: RegExp.$6
    };
}

function getVideoThumbnail(url, cb) {
    var videoObj = parseVideo(url);
    if (videoObj.type == 'youtube') {
        cb('//img.youtube.com/vi/' + videoObj.id + '/maxresdefault.jpg');
    } else if (videoObj.type == 'vimeo') {
        $.get('http://vimeo.com/api/v2/video/' + videoObj.id + '.json', function(data) {
            cb(data[0].thumbnail_large);
        });
    }
}

5
function getVimeoInfo($link)
 {
    if (preg_match('~^http://(?:www\.)?vimeo\.com/(?:clip:)?(\d+)~', $link, $match)) 
    {
        $id = $match[1];
    }
    else
    {
        $id = substr($link,10,strlen($link));
    }

    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;
}`

//在下面的函数中传递缩略图的URL。

function save_image_local($thumbnail_url)
    {

         //for save image at local server
         $filename = time().'_hbk.jpg';
         $fullpath = '../../app/webroot/img/videos/image/'.$filename;

         file_put_contents ($fullpath,file_get_contents($thumbnail_url));

        return $filename;
    }

5

更新:此解决方案于2018年12月已停止使用。

我也在寻找同样的内容,看起来大多数答案都已过时,因为Vimeo API v2已被弃用。

我的php建议:

$vidID     = 12345 // Vimeo Video ID
$tnLink = json_decode(file_get_contents('https://vimeo.com/api/oembed.json?url=https%3A//vimeo.com/' . $vidID))->thumbnail_url;

通过上述操作,您将获得Vimeo默认缩略图的链接。

如果您想使用不同尺寸的图片,可以添加类似以下内容:

$tnLink = substr($tnLink, strrpos($tnLink, '/') + 1);
$tnLink = substr($tnLink, 0, strrpos($tnLink, '_')); // You now have the thumbnail ID, which is different from Video ID

// And you can use it with link to one of the sizes of crunched by Vimeo thumbnail image, for example:
$tnLink = 'https://i.vimeocdn.com/filter/overlay?src0=https%3A%2F%2Fi.vimeocdn.com%2Fvideo%2F' . $tnLink    . '_1280x720.jpg&src1=https%3A%2F%2Ff.vimeocdn.com%2Fimages_v6%2Fshare%2Fplay_icon_overlay.png';

请问您能帮我找到任何官方公告链接,其中提到v2 vimeo已被弃用吗? - Deepak Yadav

5

如果您不需要自动化解决方案,可以在此处输入vimeo ID以查找缩略图URL:http://video.depone.eu/


这个页面上面已经有一个和这个答案一样的回答了。 - alphapilgrim

5

2020解决方案:

我编写了一个使用Vimeo Oembed API的PHP函数。

/**
 * Get Vimeo.com video thumbnail URL
 *
 * Set the referer parameter if your video is domain restricted.
 * 
 * @param  int    $videoid   Video id
 * @param  URL    $referer   Your website domain
 * @return bool/string       Thumbnail URL or false if can't access the video
 */
function get_vimeo_thumbnail_url( $videoid, $referer=null ){

    // if referer set, create context
    $ctx = null;
    if( isset($referer) ){
        $ctxa = array(
            'http' => array(
                'header' => array("Referer: $referer\r\n"),
                'request_fulluri' => true,
            ),
        );
        $ctx = stream_context_create($ctxa);
    }

    $resp = @file_get_contents("https://vimeo.com/api/oembed.json?url=https://vimeo.com/$videoid", False, $ctx);
    $resp = json_decode($resp, true);

return $resp["thumbnail_url"]??false;
}

使用方法:

echo get_vimeo_thumbnail_url("1084537");

5

实际上,提出这个问题的人发布了自己的答案。

“Vimeo似乎希望我发出HTTP请求,并从他们返回的XML中提取缩略图URL...”

Vimeo API文档在此处:http://vimeo.com/api/docs/simple-api

简而言之,您的应用程序需要向以下URL发出GET请求:

http://vimeo.com/api/v2/video/video_id.output

解析返回的数据以获取所需的缩略图URL,然后下载该URL上的文件。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接