defroster Posted September 25, 2010 Share Posted September 25, 2010 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 https://forums.phpfreaks.com/topic/214347-checking-validity-of-youtube-video-with-php/ Share on other sites More sharing options...
defroster Posted September 25, 2010 Author Share Posted September 25, 2010 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 https://forums.phpfreaks.com/topic/214347-checking-validity-of-youtube-video-with-php/#findComment-1115438 Share on other sites More sharing options...
Hate Posted September 25, 2010 Share Posted September 25, 2010 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 https://forums.phpfreaks.com/topic/214347-checking-validity-of-youtube-video-with-php/#findComment-1115517 Share on other sites More sharing options...
defroster Posted September 25, 2010 Author Share Posted September 25, 2010 Thanks a million! Very nice That worked great. I wonder if there is a way to check for embedding.. Hmm Link to comment https://forums.phpfreaks.com/topic/214347-checking-validity-of-youtube-video-with-php/#findComment-1115585 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.