YouTube get_video_info 抛出限制错误

YouTube get_video_info throws restriction error

我已经为 joomla 创建了(是的另一个)YouTube Player-Module! 在模块后端中,我使用 this answer 中的代码来显示视频标题。不幸的是 get_video_info returns 大多数视频 ID 只是嵌入禁止文本,例如:"This video contains content from VEVO. It is restricted from playback on certain sites or applications. Watch on 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: 
   }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 ;
   }
}

解决方案是使用 noembed.com 服务获取视频信息:

示例 URL:“https://noembed.com/embed?url=https://www.youtube.com/watch?v=YXN_lNZZAZA

我有同样的问题,但不想像 noembed 那样使用外部站点。 图书馆chojnicki/video-platforms-parser解决所有问题。