我已经为joomla创建了(是的另一个) YouTube播放器-模块!在模块后端,我使用来自this answer的代码来显示视频标题。不幸的是,get_video_info返回的大多数视频ID只是嵌入禁止文本:“此视频包含来自VEVO的内容。它在某些网站或应用程序上被限制播放。请在YouTube上观看”。
实际上,我从videoinfo中获取信息,并搜索标题或原因,如果存在,则模块在后端回显该值。我的问题是-有人知道为什么yt get_video_info会抛出这个错误,即使仍然可以嵌入视频吗?
示例:视频ID Y1_VsyLAGuk
如果你试图从:http://youtube.com/get_video_info?video_id=Y1_VsyLAGuk获取视频信息,你会得到一个错误,这是不可能的。
但该模块可以在同一主机上的嵌入式youtube API v3播放器中创建和播放视频。
if (isset($formID)){
$cleanedID = cleanUp($id);
// Some Magic to get the Video Title, Thanks to Stack Overflow User Cruel for this nice Hint
$content = file_get_contents("http://youtube.com/get_video_info?video_id=".$cleanedID);
parse_str($content, $ytarr);
if(array_key_exists('title', $ytarr)){
return '<div style="width:220px;"><h4>'.$ytarr['title'].'</h4><img style="border-radius:4px;" src="https://img.youtube.com/vi/'.$cleanedID.'/hqdefault.jpg" width="100%" /></div>';
// Credits: https://stackoverflow.com/a/5151862/4708062
}elseif(array_key_exists('reason', $ytarr)){
return '<div class="alert alert-danger" style="width:170px;"><p style="text-align:center">'.$ytarr['reason'].'</p></div><img style="border-radius:4px;" src="https://img.youtube.com/vi/'.$cleanedID.'/hqdefault.jpg" width="220px" />';
}else{
//print_r($ytarr);
return ;
}
}
发布于 2017-12-12 16:16:59
解决方案是使用noembed.com服务获取视频信息:
示例网址:"https://noembed.com/embed?url=https://www.youtube.com/watch?v=YXN_lNZZAZA“
发布于 2019-12-19 22:59:22
我有同样的问题,但它不想使用外部网站,如noembed。库chojnicki/video-platforms parser解决了所有的问题。
https://stackoverflow.com/questions/45190533
复制相似问题