我试图从TED嵌入代码中提取视频缩略图。为什么?那么,我使用的WordPress主题使用自定义字段来处理视频,但该字段的缩略图功能不是为TED构建的。我试图重新调整它。从TED嵌入代码中提取视频缩略图
这里的视频缩略图检索功能(如YouTube和Vimeo的覆盖):
function woo_get_video_image($embed) {
$video_thumb = '';
/* Let's start by looking for YouTube, then Vimeo */
if (preg_match('/youtube/', $embed)) {
// YouTube - get the video code if this is an embed code (old embed)
preg_match('/youtube\.com\/v\/([\w\-]+)/', $embed, $match);
// YouTube - if old embed returned an empty ID, try capuring the ID from the new iframe embed
if(!isset($match[1]))
preg_match('/youtube\.com\/embed\/([\w\-]+)/', $embed, $match);
// YouTube - if it is not an embed code, get the video code from the youtube URL
if(!isset($match[1]))
preg_match('/v\=(.+)&/',$embed ,$match);
// YouTube - get the corresponding thumbnail images
if(isset($match[1]))
$video_thumb = "http://img.youtube.com/vi/".$match[1]."/0.jpg";
} else if (preg_match('/vimeo/', $embed)) {
// Vimeo - get the video thumbnail
preg_match('#http://player.vimeo.com/video/([0-9]+)#s', $embed, $match);
if (isset($match[1])) {
$video_id = $match[1];
// Try to get a thumbnail from Vimeo
$get_vimeo_thumb = unserialize(file_get_contents_curl('http://vimeo.com/api/v2/video/'. $video_id .'.php'));
$video_thumb = $get_vimeo_thumb[0]['thumbnail_large'];
}
}
// return whichever thumbnail image you would like to retrieve
return $video_thumb;
}
下面是一个典型的TED嵌入:
<iframe
src="http://embed.ted.com/talks/andy_puddicombe_all_it_takes_is_10_mindful_minutes.html"
width="560" height="315"
frameborder="0"
scrolling="no"
webkitAllowFullScreen mozallowfullscreen allowFullScreen>
</iframe>
而TED API文档有没有什么帮助所有: http://developer.ted.com/API_Docs
我似乎无法自定义preg_match和/或$ get_vimeo_thumb部分(至少这是我认为正在发生的事情)。基本上,我正在学习PHP的这一部分,它很颠簸。
如果在'src'属性具有单引号''',而不是双引号'“'?正则表达式休息。使用正则表达式来解析HTML文档是个不错的主意,请查看DomDocument .HTML不是“常规”的,所以REgex不应该是一个选项。 –