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
You don't need to assign a preg_match function to a string... preg_match("/v=([^(\&|$)]*)/", $_POST["youtubeurl"],$matches); PHP:
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?
Instead of $findstr = preg_match("/v=([^(\&|$)]*)/", $_POST["youtubeurl"],$matches); PHP: You just need preg_match("/v=([^(\&|$)]*)/", $_POST["youtubeurl"],$matches); PHP:
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!
Thanks for the code. I have used it as the base for a new YouTube Downloader Script at my site, www.ooglester.com. You can check out the demo here. www.ooglester.com/ytdownloader_demo/ Hope you enjoy! Jereme www.TheFreeTube.com
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.
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
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.
This script does not download an flv, it goes to Youtube and hangs. Is there a better script out there?
get_video? is being phased out my youtube. This will not work (if it does for some vids) for much longer.