Jump to content

Checking validity of YouTube video with PHP


defroster

Recommended Posts

Hello,

 

I embed some YouTube videos on my site. Sometimes a video is deleted from YouTube and I have no way of knowing. Does anyone know if there is some php script or by using their API you can check if a video has:

 

- video has been removed

- video is not embeddable any more

 

any ideas? Thanks

/df

Link to comment
Share on other sites

I see if I use this I can get a lot of information from the video but not if it is embeddable or not.

http://gdata.youtube.com/feeds/api/videos/i9gucBfZ1qg

 

and if a video is invalid and I use the link above I get a page that says

'Video not found'

 

- How could I use this information to loop through a set of links (from own database) and it would tell me if it is valid or not?

- Any ideas how to check also if it is embeddable?

 

Thanks

Link to comment
Share on other sites

Here's something I just came up with just messing around. I know it's probably not the best to use, but hopefully it will give you an idea on what to do.

 

$video_ids = array("vg0x0pUXEKE", "8eDmYGXHzdQ", "87654321", "_ElORM9O-0U", "12345678", "Fr777bGKD9g");

foreach($video_ids as $video_id)
{

    $curl = curl_init("http://gdata.youtube.com/feeds/api/videos/" . $video_id);
    curl_setopt($curl, CURLOPT_HEADER, true);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    curl_exec($curl);
    $request = curl_getinfo($curl);
    curl_close($curl);

    $result = explode(";", $request["content_type"]);
    
    if($result[0] == "application/atom+xml")
    {

        // Video exists

    } else {

        // Video doesn't exist

    }

}

 

I'm not sure how to check if embedding is allowed on the video, but I'm sure you would probably have to use their API for that.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.