我想从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
其他回答
你可能想看看马特·胡克斯的宝石。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
这是一种快速巧妙的方法,也是一种选择自定义大小的方法。
我去这里:
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
把它粘贴到你的浏览器搜索栏上,享受吧。
欢呼,
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;
}
使用jQuery jsonp请求:
<script type="text/javascript">
$.ajax({
type:'GET',
url: 'http://vimeo.com/api/v2/video/' + video_id + '.json',
jsonp: 'callback',
dataType: 'jsonp',
success: function(data){
var thumbnail_src = data[0].thumbnail_large;
$('#thumb_wrapper').append('<img src="' + thumbnail_src + '"/>');
}
});
</script>
<div id="thumb_wrapper"></div>
这里有一个完美的解决方案
URL Example : https://vumbnail.com/226020936.jpg
URL method : https://vumbnail.com/{video_id}.jpg
这对我很有效。