Youtube Video Download Code: Now Working & Source Posted

Discussion in 'PHP' started by imvain2, Jan 28, 2008.

  1. #1
    If anyone is interested, here is working code that takes a youtube url as input and redirects the user to download get_video file which is a flv.

    
    <?php
        if($_POST["youtubeurl"]!=""){
            $pagecontent = file_get_contents($_POST["youtubeurl"]);
            preg_match("/v=([^(\&|$)]*)/", $_POST["youtubeurl"],$matches);
            $VideoID = $matches[1];
            preg_match("/\"t\": \"([^(\\\"|$)]*)/", $pagecontent,$matches);
            $T_ID = $matches[1];
            $VideoURL = "http://youtube.com/get_video?video_id=$VideoID&t=$T_ID";
            header("Location: " . $VideoURL);
        }
    ?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    
    <html>
    <head>
        <title>YouTube Downloader</title>
    </head>
    <body>
    <form action="youtube.php" method="post">
    <b>YouTube URL:</b>
    <input type="Text" name="youtubeurl" size="35" value="http://youtube.com/watch?v=aFgJwRUojKw">
    <br>
    <input type="submit" value="Download Video">
    </form>
    </body>
    </html>
    
    PHP:
    **Updated thanks to Kaizoku
     
    imvain2, Jan 28, 2008 IP
  2. Kaizoku

    Kaizoku Well-Known Member

    Messages:
    1,261
    Likes Received:
    20
    Best Answers:
    1
    Trophy Points:
    105
    #2
    You don't need to assign a preg_match function to a string...
    
    preg_match("/v=([^(\&|$)]*)/", $_POST["youtubeurl"],$matches);
    
    PHP:
     
    Kaizoku, Jan 28, 2008 IP
  3. imvain2

    imvain2 Peon

    Messages:
    218
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I didn't want to explode it and try to loop through the results. Is that what you were talking about?

    Or are you talking about doing a strpos?
     
    imvain2, Jan 28, 2008 IP
  4. Kaizoku

    Kaizoku Well-Known Member

    Messages:
    1,261
    Likes Received:
    20
    Best Answers:
    1
    Trophy Points:
    105
    #4
    Instead of
    
    $findstr = preg_match("/v=([^(\&|$)]*)/", $_POST["youtubeurl"],$matches);
    
    PHP:
    You just need
    
    preg_match("/v=([^(\&|$)]*)/", $_POST["youtubeurl"],$matches);
    
    PHP:
     
    Kaizoku, Jan 28, 2008 IP
  5. imvain2

    imvain2 Peon

    Messages:
    218
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Oh cool thanks.

    I'm actually new to the regular expressions, so that is why I was confused. When you posted your first code, I wasn't paying attention to the beginning and looking at the regular expression part.

    Thanks Again!
     
    imvain2, Jan 28, 2008 IP
  6. mhancoc7

    mhancoc7 Guest

    Messages:
    182
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #6
    mhancoc7, Feb 3, 2008 IP
  7. pizzagreezi

    pizzagreezi Peon

    Messages:
    43
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Thanks for the code imvian2
     
    pizzagreezi, Feb 3, 2008 IP
  8. LloydFerg

    LloydFerg Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8

    Hey man, I downloaded your script and uploaded it onto my site to run it. There seems to be a problem with it. After I enter in a link, it goes to the index.php and does nothing.... I'm discombobulated.
     
    LloydFerg, Feb 7, 2008 IP
  9. mhancoc7

    mhancoc7 Guest

    Messages:
    182
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #9
    I am not sure why that is happening to you. The demo is still functioning fine. It may have something to do with your server. Maybe a php issue or something.

    Jereme
     
    mhancoc7, Feb 7, 2008 IP
  10. anisa_b

    anisa_b Peon

    Messages:
    191
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #10
    It's not working for me too.
     
    anisa_b, Feb 8, 2008 IP
  11. imvain2

    imvain2 Peon

    Messages:
    218
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #11
    Actually there is a minor bug.

    The page name in the zip is like ytdownloader.php or something but the page in the form action is index.php. Which by default wouldn't exist.

    If you rename the only php file that is in the zip to index.php, the code will work. I installed and fixed the bug with windows running XAMPP.
     
    imvain2, Feb 8, 2008 IP
  12. anisa_b

    anisa_b Peon

    Messages:
    191
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #12
    Thanks for the info. I was having trouble with this.

     
    anisa_b, Feb 8, 2008 IP
  13. mhancoc7

    mhancoc7 Guest

    Messages:
    182
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #13
    Thanks for catching that. I can't believe I overlooked it. :rolleyes:

    Jereme
     
    mhancoc7, Feb 10, 2008 IP
  14. WebbyCart

    WebbyCart Active Member

    Messages:
    138
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    73
    #14
    Hi,

    Where can I download the script? The source above seems not working or incomplete.

    Thanks
    Bob
     
    WebbyCart, Oct 12, 2008 IP
  15. Frankenfine

    Frankenfine Peon

    Messages:
    122
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #15
    This script does not download an flv, it goes to Youtube and hangs.

    Is there a better script out there?
     
    Frankenfine, Dec 13, 2009 IP
  16. chanceart

    chanceart Peon

    Messages:
    89
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #16
    thank's for this code.i am learning.
     
    chanceart, Dec 13, 2009 IP
  17. Frankenfine

    Frankenfine Peon

    Messages:
    122
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #17
    The script does not work!!
     
    Frankenfine, Dec 13, 2009 IP
  18. papa_face

    papa_face Notable Member

    Messages:
    2,237
    Likes Received:
    67
    Best Answers:
    1
    Trophy Points:
    285
    #18
    get_video? is being phased out my youtube. This will not work (if it does for some vids) for much longer.
     
    papa_face, Dec 13, 2009 IP
  19. Frankenfine

    Frankenfine Peon

    Messages:
    122
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #19
    Does anyone have a working script??
     
    Frankenfine, Dec 13, 2009 IP