April 15, 2012

Check if a YouTube video has been removed using PHP?

Question by user1334448

Possible Duplicate:
Check if Youtube and Vimeo-clips are valid

I have a website which links to a lot of YouTube videos but a lot of the time these videos are removed by either the user or YouTube. This means my site has a lot of dead videos on it and there are so many it would be a nightmare to check them all manually.

So I am looking for a way to check if the YouTube video is still valid using PHP. I have seen a lot of threads with people asking the same question but I can’t get any of the posted solutions to work.

Answer by Starx

Send request to this URL, to verify the existence of a video

http://gdata.youtube.com/feeds/api/videos/<videoid>

Here is an usage of it.

$headers = get_headers('http://gdata.youtube.com/feeds/api/videos/' . $videoId);
if (!strpos($headers[0], '200')) {
    echo "The YouTube video you entered does not exist";
    return false;
}

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!