Joh*_*han 295 html thumbnails vimeo
我想从Vimeo获取视频的缩略图.
从Youtube获取图像时,我只是这样做:
http://img.youtube.com/vi/HwP5NG-3e8I/2.jpg
Run Code Online (Sandbox Code Playgroud)
知道如何为Vimeo做点什么吗?
Flu*_*ffy 356
发出视频请求
要获取有关特定视频的数据,请使用以下网址:
http://vimeo.com/api/v2/video/video_id.output
video_id您想要信息的视频的ID.
output指定输出类型.我们目前提供JSON,PHP和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>
Run Code Online (Sandbox Code Playgroud)
为每个视频解析此内容以获取缩略图
这是PHP中的近似代码
<?php
$imgid = 6271487;
$hash = unserialize(file_get_contents("http://vimeo.com/api/v2/video/$imgid.php"));
echo $hash[0]['thumbnail_medium'];
Run Code Online (Sandbox Code Playgroud)
Nat*_*tim 59
在javascript(使用jQuery):
function vimeoLoadingThumb(id){
var url = "http://vimeo.com/api/v2/video/" + id + ".json?callback=showThumb";
var id_img = "#vimeo-" + id;
var script = document.createElement( 'script' );
script.src = url;
$(id_img).before(script);
}
function showThumb(data){
var id_img = "#vimeo-" + data[0].id;
$(id_img).attr('src',data[0].thumbnail_medium);
}
Run Code Online (Sandbox Code Playgroud)
要显示它:
<img id="vimeo-{{ video.id_video }}" src="" alt="{{ video.title }}" />
<script type="text/javascript">
vimeoLoadingThumb({{ video.id_video }});
</script>
Run Code Online (Sandbox Code Playgroud)
小智 44
使用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>
Run Code Online (Sandbox Code Playgroud)
Erd*_* G. 39
您应该解析Vimeo的API响应.URL调用没有办法(比如dailymotion或youtube).
这是我的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;
}
Run Code Online (Sandbox Code Playgroud)
小智 22
使用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
Run Code Online (Sandbox Code Playgroud)
小智 21
这是一个如何使用C#在ASP.NET中执行相同操作的示例.随意使用不同的错误捕获图像:)
public string GetVimeoPreviewImage(string vimeoURL)
{
try
{
string vimeoUrl = System.Web.HttpContext.Current.Server.HtmlEncode(vimeoURL);
int pos = vimeoUrl.LastIndexOf(".com");
string videoID = vimeoUrl.Substring(pos + 4, 8);
XmlDocument doc = new XmlDocument();
doc.Load("http://vimeo.com/api/v2/video/" + videoID + ".xml");
XmlElement root = doc.DocumentElement;
string vimeoThumb = root.FirstChild.SelectSingleNode("thumbnail_medium").ChildNodes[0].Value;
string imageURL = vimeoThumb;
return imageURL;
}
catch
{
//cat with cheese on it's face fail
return "http://bestofepicfail.com/wp-content/uploads/2008/08/cheese_fail.jpg";
}
}
Run Code Online (Sandbox Code Playgroud)
注意:您的API请求在请求时应如下所示:http://vimeo.com/api/v2/video/32660708.xml
Sam*_*ton 20
对于那些仍然想要仅通过 URL 获取缩略图的人,就像 Youtube 一样,我构建了一个小应用程序,它只使用 Vimeo ID 来获取缩略图。
https://vumbnail.com/358629078.jpg
Run Code Online (Sandbox Code Playgroud)
只需插入您的视频 ID,它就会将其拉出并缓存 28 天,以便快速投放。
以下是 HTML 中的几个示例:
Simple Image Example
<img src="https://vumbnail.com/358629078.jpg" />
<br>
<br>
Modern Responsive Image Example
<img srcset="https://vumbnail.com/358629078.jpg 640w, https://vumbnail.com/358629078_large.jpg 640w, https://vumbnail.com/358629078_medium.jpg 200w, https://vumbnail.com/358629078_small.jpg 100w" sizes="(max-width: 640px) 100vw, 640px" src="https://vumbnail.com/358629078.jpg" />Run Code Online (Sandbox Code Playgroud)
如果你想启动你自己的,你可以在这里这样做。
Roy*_*hoa 12
在没有搜索视频ID的情况下,我发现获取缩略图的最简单的JavaScript方法是使用:
//Get the video thumbnail via Ajax
$.ajax({
type:'GET',
url: 'https://vimeo.com/api/oembed.json?url=' + encodeURIComponent(url),
dataType: 'json',
success: function(data) {
console.log(data.thumbnail_url);
}
});
Run Code Online (Sandbox Code Playgroud)
注意:如果有人需要获取与视频ID相关的视频缩略图,则可以将视频ID替换$id为视频ID,并获取包含视频详细信息的XML:
http://vimeo.com/api/v2/video/$id.xml
Run Code Online (Sandbox Code Playgroud)
例:
http://vimeo.com/api/v2/video/198340486.xml
Run Code Online (Sandbox Code Playgroud)
如果您想通过纯js/jquery no api使用缩略图,您可以使用此工具从视频中捕获帧并瞧!插入您喜欢的源头的url thumb.
这是一个代码笔:
<img src="https://i.vimeocdn.com/video/531141496_640.jpg"` alt="" />
Run Code Online (Sandbox Code Playgroud)
这是获取缩略图的网站:
使用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>Run Code Online (Sandbox Code Playgroud)
似乎api/v2已经死了.
要使用新API,您需要注册您的应用程序,并对base64进行编码client_id并将其client_secret作为Authorization标头.
$.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);
}
});
Run Code Online (Sandbox Code Playgroud)
为了安全起见,你可以返回client_id,并client_secret从服务器已经编码.
我创建了一个 CodePen 来为你获取图像。
HTML
<input type="text" id="vimeoid" placeholder="257314493" value="257314493">
<button id="getVideo">Get Video</button>
<div id="output"></div>
Run Code Online (Sandbox Code Playgroud)
JavaScript:
const videoIdInput = document.getElementById('vimeoid');
const getVideo = document.getElementById('getVideo');
const output = document.getElementById('output');
function getVideoThumbnails(videoid) {
fetch(`https://vimeo.com/api/v2/video/${videoid}.json`)
.then(response => {
return response.text();
})
.then(data => {
const { thumbnail_large, thumbnail_medium, thumbnail_small } = JSON.parse(data)[0];
const small = `<img src="${thumbnail_small}"/>`;
const medium = `<img src="${thumbnail_medium}"/>`;
const large = `<img src="${thumbnail_large}"/>`;
output.innerHTML = small + medium + large;
})
.catch(error => {
console.log(error);
});
}
getVideo.addEventListener('click', e => {
if (!isNaN(videoIdInput.value)) {
getVideoThumbnails(videoIdInput.value);
}
});
Run Code Online (Sandbox Code Playgroud)
事实上,问这个问题的人发表了自己的答案。
“Vimeo 似乎希望我发出 HTTP 请求,并从它们返回的 XML 中提取缩略图 URL...”
Vimeo API 文档位于: http: //vimeo.com/api/docs/simple-api
简而言之,您的应用需要向如下 URL 发出 GET 请求:
http://vimeo.com/api/v2/video/video_id.output
Run Code Online (Sandbox Code Playgroud)
并解析返回的数据以获取您需要的缩略图 URL,然后从该 URL 下载文件。
小智 5
我用 PHP 编写了一个函数来让我做到这一点,我希望它对某人有用。缩略图的路径包含在视频页面上的链接标签内。这似乎对我有用。
$video_url = "http://vimeo.com/7811853"
$file = fopen($video_url, "r");
$filedata = stream_get_contents($file);
$html_content = strpos($filedata,"<link rel=\"videothumbnail");
$link_string = substr($filedata, $html_content, 128);
$video_id_array = explode("\"", $link_string);
$thumbnail_url = $video_id_array[3];
echo $thumbnail_url;
Run Code Online (Sandbox Code Playgroud)
希望它对任何人都有帮助。
福格森
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;
}`
Run Code Online (Sandbox Code Playgroud)
//在下面的函数中传递缩略图 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;
}
Run Code Online (Sandbox Code Playgroud)
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);
});
}
}
Run Code Online (Sandbox Code Playgroud)
分解 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;
};
Run Code Online (Sandbox Code Playgroud)
从 Vimeo 视频 URL 获取 Vimeo Id:
var vimeoId = parseVimeoIdFromUrl(vimeoUrl);
Run Code Online (Sandbox Code Playgroud)
从 Vimeo Id 获取 vimeo 缩略图 URL:
getVimeoThumbUrl(vimeoIds[0])
.done(function(img) {
$('div').append('<img src="' + img + '"/>');
});
Run Code Online (Sandbox Code Playgroud)
https://jsfiddle.net/b9chris/nm8L8cc8/1/
更新:该解决方案自 2018 年 12 月起停止工作。
\n\n我一直在寻找同样的东西,由于 Vimeo API v2 已被弃用,这里的大多数答案似乎都已过时。
\n\n我的 php 2\xc2\xa2:
\n\n$vidID = 12345 // Vimeo Video ID\n$tnLink = json_decode(file_get_contents('https://vimeo.com/api/oembed.json?url=https%3A//vimeo.com/' . $vidID))->thumbnail_url;\nRun Code Online (Sandbox Code Playgroud)\n\n通过以上内容,您将获得 Vimeo 默认缩略图的链接。
\n\n如果你想使用不同尺寸的图像,你可以添加类似的内容:
\n\n$tnLink = substr($tnLink, strrpos($tnLink, '/') + 1);\n$tnLink = substr($tnLink, 0, strrpos($tnLink, '_')); // You now have the thumbnail ID, which is different from Video ID\n\n// And you can use it with link to one of the sizes of crunched by Vimeo thumbnail image, for example:\n$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';\nRun Code Online (Sandbox Code Playgroud)\n
这是一种快速的技巧,也是一种选择自定义尺寸的方法。
我去这里:
http://vimeo.com/api/v2/video/[VIDEO ID].php
Run Code Online (Sandbox Code Playgroud)
下载文件,将其打开,然后找到640像素宽的缩略图,其格式如下:
https://i.vimeocdn.com/video/[LONG NUMBER HERE]_640.jpg
Run Code Online (Sandbox Code Playgroud)
您选择了链接,将640更改为-例如-1400,最后得到的是这样的内容:
https://i.vimeocdn.com/video/[LONG NUMBER HERE]_1400.jpg
Run Code Online (Sandbox Code Playgroud)
将其粘贴到您的浏览器搜索栏中,即可享受。
干杯,
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;
}
Run Code Online (Sandbox Code Playgroud)
用法:
echo get_vimeo_thumbnail_url("1084537");
Run Code Online (Sandbox Code Playgroud)