Search code examples
videoyoutubegetinfo

YouTube get_video_info throws restriction error


I have created (yes another) YouTube Player-Module for joomla! In the Module Backend i used the Code from this answer to display the Videotitle. Unfortunately get_video_info returns for the most video ID's just the embedding forbidden text like : "This video contains content from VEVO. It is restricted from playback on certain sites or applications. Watch on YouTube".

Actually i take the info from videoinfo and search for title or reason if exists the module echo the value in the backend. My Question is - Anyone know why yt get_video_info throws this error even if its still possible to embed the Video?

an example: Video ID Y1_VsyLAGuk

if you try to get videoinfos from: http://youtube.com/get_video_info?video_id=Y1_VsyLAGuk you will get just the error that it is not possible.

but the module can create and play the video in an embedded youtube API v3 Player on the same host.

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 ;
   }
}


Solution

  • The solution was to use noembed.com service to get the video informations:

    Example URL: "https://noembed.com/embed?url=https://www.youtube.com/watch?v=YXN_lNZZAZA"