Youtube GData APIYoutube the largest video sharing site has millions of videos, all around the world these videos are embedded into various web pages which are viewed using browser from a desktop computer , tablets or mobile devices. From time to time users remove videos, make them private, or Google deletes them for copyright issues. So for webmasters who build their site around Youtube videos it is essential to find out if the video will work on Website or iPhone and it not Private. For sure if you have few videos you can check manually but if you have hundreds or more an automated tool would be required.

The Script

Fortunately checking the status of a Youtube video is very straightforward using Google GDATA API. This API is REST based and with a simple HTTP GET with  Youtube video id as a parameter you can find out the video status. The following PHP Script expects to pass the Youtube video id as a query string parameter. <?php  $vid = $_GET['vid'];  if (empty($vid))  {      echo "VID=NULL";  }  else  {       $yt_video_info_url = "" . $vid;      $input = @file_get_contents($yt_video_info_url);     $support_mobile = 0;     $support_website = 0;      if (strlen(strstr($input,"format='1'"))>0) {         $support_mobile=1;         echo "IPhone=YES";     }     else     {         echo "IPhone=NO";            }      if (strlen(strstr($input,"format='5'"))>0) {         $support_mobile=1;         echo ",FLASH=YES";     }      else     {         echo ",FLASH=NO";     }     if (!$input) {         echo ",Private=YES";            }  }  ?> It is as simple as that. You can build this into a function and invoke it for all the videos that you have in your database and update the status of the video to say Enabled or Disabled based on whether its Private or Not. Likewise you can mark them available for devices like iPhone or not. This automated script can be run as often you like to keep your video database current helping in improving customer experience as they would never see a broken video any more.Cool