Video Import and YOutube

Discussion in 'PHP' started by rajivv, Jul 28, 2010.

  1. #1
    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
     
    rajivv, Jul 28, 2010 IP
  2. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #2
    You could loop through, the db, and then curl -> checking the header to see if found -> if not found DELETE from...
     
    danx10, Jul 28, 2010 IP
  3. Rainulf

    Rainulf Active Member

    Messages:
    373
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    85
    #3
    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?
     
    Rainulf, Jul 28, 2010 IP
  4. rajivv

    rajivv Peon

    Messages:
    335
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Hi,

    Youtube just show no video thumbnail so how to do that...
     
    rajivv, Jul 28, 2010 IP
  5. Rainulf

    Rainulf Active Member

    Messages:
    373
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    85
    #5
    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.
     
    Rainulf, Jul 28, 2010 IP
  6. rajivv

    rajivv Peon

    Messages:
    335
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Yes you are correct its the same thumbnail now please ellaborate your php i copy this server .. then ???
    Please help
     
    rajivv, Jul 29, 2010 IP
  7. Rainulf

    Rainulf Active Member

    Messages:
    373
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    85
    #7
    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.
     
    Rainulf, Jul 29, 2010 IP