Fero Fero - 3 months ago 67
PHP Question

How do I check if a video exists on YouTube, using PHP?

How do I check if a video exists on YouTube, using PHP?

Answer

What about using Youtube's API ?
After all, that would mean using some official, which is less likely to change than going with parsing some HTML page.

For more informations : YouTube APIs and Tools - Developer's Guide: PHP


The Retrieving a specific video entry seems quite interesting : if you send a request to an URL like this one :

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

(Replacing "videoID" by the idea of the video, of course -- "GeppLPQtihA" in your example)

You'll get some ATOM feed if the video is valid ; and "Invalid id" if it's not


And, I insist : this way, you rely on a documented API, and not on some kind of behavior that exists today, but is not garanteed.