我想从Vimeo获得视频的缩略图。
当从Youtube上获得图像时,我只是这样做:
http://img.youtube.com/vi/HwP5NG-3e8I/2.jpg
你知道如何处理Vimeo吗?
同样的问题,没有答案。
我想从Vimeo获得视频的缩略图。
当从Youtube上获得图像时,我只是这样做:
http://img.youtube.com/vi/HwP5NG-3e8I/2.jpg
你知道如何处理Vimeo吗?
同样的问题,没有答案。
当前回答
你可能想看看马特·胡克斯的宝石。https://github.com/matthooks/vimeo
它为api提供了一个简单的vimeo包装器。
所有你需要的是存储video_id(和提供商,如果你也做其他视频网站)
你可以像这样提取vimeo视频id
def
get_vimeo_video_id (link)
vimeo_video_id = nil
vimeo_regex = /http:\/\/(www\.)?vimeo.com\/(\d+)($|\/)/
vimeo_match = vimeo_regex.match(link)
if vimeo_match.nil?
vimeo_regex = /http:\/\/player.vimeo.com\/video\/([a-z0-9-]+)/
vimeo_match = vimeo_regex.match(link)
end
vimeo_video_id = vimeo_match[2] unless vimeo_match.nil?
return vimeo_video_id
end
如果你需要你的试管,你可能会发现这个很有用
def
get_youtube_video_id (link)
youtube_video_id = nil
youtube_regex = /^(https?:\/\/)?(www\.)?youtu.be\/([A-Za-z0-9._%-]*)(\&\S+)?/
youtube_match = youtube_regex.match(link)
if youtube_match.nil?
youtubecom_regex = /^(https?:\/\/)?(www\.)?youtube.com\/watch\?v=([A-Za-z0-9._%-]*)(\&\S+)?/
youtube_match = youtubecom_regex.match(link)
end
youtube_video_id = youtube_match[3] unless youtube_match.nil?
return youtube_video_id
end
其他回答
这似乎是一个老问题,但我有几个与Vimeo缩略图相关的项目,所以在前几个月,它与我非常相关。所有的API V2都不适合我,i.vimeocdn.com链接每个月都被弃用。我需要这个可持续的解决方案,为此我使用了oEmbed API: https://developer.vimeo.com/api/oembed
注意:当试图从禁止域访问时,您将得到403错误。只使用目标域或将登台/本地域列入白名单。
下面是我如何用JS得到图像:
async function getThumb (videoId) {
var url = 'https://vimeo.com/api/oembed.json?url=https%3A//vimeo.com/'+videoId+'&width=480&height=360';
try {
let res = await fetch(url);
return await res.json();
} catch (error) {
console.log(error);
}
Result变量将从oEmbed API获得一个JSON。
接下来,在我自己的用例中,我需要这些作为视频存档的缩略图。我为每个缩略图包装器DIV添加了一个ID, ID为“thumbnail-{{ID}}”(例如,“thumbnail-123456789”),并将图像插入到DIV中。
getThumb(videoId).then(function(result) {
var img = document.createElement('img');
img.src = result.thumbnail_url;
document.getElementById('thumbnail-'+videoId).appendChild(img);
});
如果您不需要自动解决方案,您可以通过在这里输入vimeo ID: http://video.depone.eu/来找到缩略图URL
你可能想看看马特·胡克斯的宝石。https://github.com/matthooks/vimeo
它为api提供了一个简单的vimeo包装器。
所有你需要的是存储video_id(和提供商,如果你也做其他视频网站)
你可以像这样提取vimeo视频id
def
get_vimeo_video_id (link)
vimeo_video_id = nil
vimeo_regex = /http:\/\/(www\.)?vimeo.com\/(\d+)($|\/)/
vimeo_match = vimeo_regex.match(link)
if vimeo_match.nil?
vimeo_regex = /http:\/\/player.vimeo.com\/video\/([a-z0-9-]+)/
vimeo_match = vimeo_regex.match(link)
end
vimeo_video_id = vimeo_match[2] unless vimeo_match.nil?
return vimeo_video_id
end
如果你需要你的试管,你可能会发现这个很有用
def
get_youtube_video_id (link)
youtube_video_id = nil
youtube_regex = /^(https?:\/\/)?(www\.)?youtu.be\/([A-Za-z0-9._%-]*)(\&\S+)?/
youtube_match = youtube_regex.match(link)
if youtube_match.nil?
youtubecom_regex = /^(https?:\/\/)?(www\.)?youtube.com\/watch\?v=([A-Za-z0-9._%-]*)(\&\S+)?/
youtube_match = youtubecom_regex.match(link)
end
youtube_video_id = youtube_match[3] unless youtube_match.nil?
return youtube_video_id
end
使用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
对于像我这样最近正试图弄清楚这个问题的人来说,
https://i.vimeocdn.com/video/[video_id]_[dimension].webp适合我。
(其中尺寸= 200x150 | 640)