从Vimeo获取img缩略图?

本文翻译自:Get img thumbnails from Vimeo?

I want to get a thumbnail image for videos from Vimeo. 我想从Vimeo获取视频的缩略图。

When getting images from Youtube I just do like this: 从Youtube获取图像时,我只是这样做:

http://img.youtube.com/vi/HwP5NG-3e8I/2.jpg

Any idea how to do for Vimeo? 知道如何为Vimeo做点什么吗?

Here is same question, without any answer. 这是同一个问题,没有任何答案。


#1楼

参考:https://stackoom.com/question/5i61/从Vimeo获取img缩略图


#2楼

You should parse Vimeo's API's response. 您应该解析Vimeo的API响应。 There is no way to it with URL calls (like dailymotion or youtube). URL调用没有办法(比如dailymotion或youtube)。

Here is my PHP solution: 这是我的PHP解决方案:

/**
 * Gets a vimeo thumbnail url
 * @param mixed $id A vimeo id (ie. 1185346)
 * @return thumbnail's url
*/
function getVimeoThumb($id) {
    $data = file_get_contents("http://vimeo.com/api/v2/video/$id.json");
    $data = json_decode($data);
    return $data[0]->thumbnail_medium;
}

#3楼

Actually the guy who asked that question posted his own answer. 实际上问这个问题的人发表了自己的答案。

"Vimeo seem to want me to make a HTTP request, and extract the thumbnail URL from the XML they return..." “Vimeo似乎希望我发出HTTP请求,并从他们返回的XML中提取缩略图URL ......”

The Vimeo API docs are here: http://vimeo.com/api/docs/simple-api Vimeo API文档位于: http//vimeo.com/api/docs/simple-api

In short, your app needs to make a GET request to an URL like the following: 简而言之,您的应用需要向以下网址发出GET请求:

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

and parse the returned data to get the thumbnail URL that you require, then download the file at that URL. 并解析返回的数据以获取所需的缩略图URL,然后下载该URL的文件。


#4楼

From the Vimeo Simple API docs : 来自Vimeo Simple API文档

Making a Video Request 发出视频请求

To get data about a specific video, use the following url: 要获取有关特定视频的数据,请使用以下网址:

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

video_id The ID of the video you want information for. video_id您想要信息的视频的ID。

output Specify the output type. output指定输出类型。 We currently offer JSON, PHP, and XML formats. 我们目前提供JSON,PHP和XML格式。

So getting this URL http://vimeo.com/api/v2/video/6271487.xml 所以获取此URL http://vimeo.com/api/v2/video/6271487.xml

    <videos> 
      <video> 
        [skipped]
        <thumbnail_small>http://ts.vimeo.com.s3.amazonaws.com/235/662/23566238_100.jpg</thumbnail_small> 
        <thumbnail_medium>http://ts.vimeo.com.s3.amazonaws.com/235/662/23566238_200.jpg</thumbnail_medium> 
        <thumbnail_large>http://ts.vimeo.com.s3.amazonaws.com/235/662/23566238_640.jpg</thumbnail_large> 
        [skipped]
    </videos>

Parse this for every video to get the thumbnail 为每个视频解析此内容以获取缩略图

Here's approximate code in PHP 这是PHP中的近似代码

<?php

$imgid = 6271487;

$hash = unserialize(file_get_contents("http://vimeo.com/api/v2/video/$imgid.php"));

echo $hash[0]['thumbnail_medium'];  

#5楼

With Ruby, you can do the following if you have, say: 使用Ruby,如果您有,请执行以下操作,例如:

url                      = "http://www.vimeo.com/7592893"
vimeo_video_id           = url.scan(/vimeo.com\/(\d+)\/?/).flatten.to_s               # extract the video id
vimeo_video_json_url     = "http://vimeo.com/api/v2/video/%s.json" % vimeo_video_id   # API call

# Parse the JSON and extract the thumbnail_large url
thumbnail_image_location = JSON.parse(open(vimeo_video_json_url).read).first['thumbnail_large'] rescue nil

#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);
        });
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值