我发现了一个名为oEmbed Featured Image的插件,除了输出最大尺寸的插件外,它绝对可以完成我想要的所有事情.
插件的默认YouTube输出尺寸为480×360.我需要至少在YouTube / Vimeo上使用完整分辨率.
我想我可以在插件的第68行开始编辑该功能.
这是我想出的:
public function oembed_dataparse( $return, $data, $url )
{
if ($yt = $data->provider_name == 'YouTube')
{
if(preg_match("/^(?:http(?:s)?:\/\/)?(?:www\.)?(?:m\.)?(?:youtu\.be\/|youtube\.com\/(?:(?:watch)?\?(?:.*&)?v(?:i)?=|(?:embed|v|vi|user)\/))([^\?&\"'>]+)/", $data->thumbnail_url, $youtube_id))
$ytvideo_id = $youtube_id;
$max = get_headers($data->thumbnail_url);
if (substr($max[0], 9, 3) !== '404')
{
$data->thumbnail_url = 'http://img.youtube.com/vi/$ytvideo_id/maxresdefault.jpg';
}
}
if ($vm = $data->provider_name == 'Vimeo')
{
if (preg_match("/https?:\/\/(?:www\.)?vimeo.com\/(?:channels\/(?:\w+\/)?|groups\/([^\/]*)\/videos\/|album\/(\d+)\/video\/|)(\d+)(?:$|\/|\?)/", $data->thumbnail_url, $vimeo_id))
$vmvideo_id = $vimeo_id[3];
$hash = unserialize(file_get_contents("http://vimeo.com/api/v2/video/$vmvideo_id.php"));
$data->thumbnail_url = $hash[0]['thumbnail_large'];
}
if ( ! empty( $data->thumbnail_url ) && ! $this->_thumb_id ) {
//if ( in_array( @ $data->type, array( 'video' ) ) ) // Only set for video embeds
$this->set_thumb_by_url( $data->thumbnail_url, @ $data->title );
}
}
解决方法:
您需要做的实际上是修改youtube if语句,使其显示为$url,而不是$data-> thumbnail_url.这将导致您的preg_match()正确匹配,并且将返回正确的$yt_videoid供您使用.