HI, I have a site where users can import youtube videos via url or embed code. Problem is now I have close to 10000 videos. But many are dead videos (that is the youtube no video thumb shows) or thumb shows and then video open says not found.. How do I find these in DB need to delete the same dead videos. Little confusing since the videos are from youtube. But have a whole lot of dead videos. Regards
You could loop through, the db, and then curl -> checking the header to see if found -> if not found DELETE from...
One way I could think of is to use file_get_contents and preg_match. Like this: <?php $lol = file_get_contents("http://www.youtube.com/watch?v=8PYFbu9nkff"); if (preg_match("/not available/", $lol)) echo "this video is not available"; else echo "this video is available"; ?> PHP: First, grab the youtube links from your database. Then visit each of those links and look for keyword "not available" or "violation" or whatever keyword messages they show on dead videos. If it is, delete it from the database or mark it dead?
I think it's much easier my way, but your way is also possible, I think... I believe every dead youtube videos show the same 404 thumbnail like this -> http://i1.ytimg.com/vi/PT47mdE7qff/default.jpg . Try to compare thumbnails with md5. Like this: <?php $dead = md5(file_get_contents("http://i1.ytimg.com/vi/PT47mdE7zff/default.jpg")); // PT47mdE7zff is the youtube id $youtube = md5(file_get_contents("http://i1.ytimg.com/vi/IHuowSV8XHY/default.jpg")); // IHuowSV8XHY is the youtube id if ($dead == $youtube) echo "video is dead"; else echo "video is alive~~ hooray"; ?> PHP: http://i4.ytimg.com/vi/IHuowSV8XHY/default.jpg is not equal to http://i1.ytimg.com/vi/PT47mdE7zff/default.jpg - therefore, it's alive.
Yes you are correct its the same thumbnail now please ellaborate your php i copy this server .. then ??? Please help
md5 calculates the md5 hash value of those jpg images and put them in a variable. We compare the values in those variable if they're the same. If they're the same, it means that the image are the same, so we can assume that the video is dead because it has the same default 404 jpg images. My code up there is just to illustrate my idea, it won't work if you just simply copy and paste it to your website. You need to incorporate that idea to your PHP, thus, you need to have at least the basic knowledge of PHP and mysql.