YouTube Video Ripper in PHP
Hacks, Programming April 8th, 2007 - 40,519 viewsI found an interesting shell script today while browsing digg that allows you to download all the youtube videos for a particular user that match a certain pattern. This is a great example of the power of regular expressions, by the way… I wrote a quick PHP port (plaintext version) that you can use if you’re running Windows. It doesn’t have a progress bar (since it’s not using wget), but it gets the job done.
Update: if you don’t have the PHP interpreter installed either, you can go to this page to generate direct links to the videos that would have been downloaded by the script automatically. I just threw it together in 5 minutes, so it’s not pretty. But again, it works. Just right click and “save as.”
read more
April 8th, 2007 at 12:07 pm
[...] Mike wrote a PHP port! 08 Apr 07 | Software, Scripts, [...]
April 8th, 2007 at 1:44 pm
Mike,
I am currently testing your script, and it appears to succeed where Niklas’ failed. With Niklas’ script, in the regex processing, the script would encounter a major error with the XARGS processing. However, it APPEARS that yours processes the regex properly (the script is not done yet). Kudos to you!
Jason
April 8th, 2007 at 2:22 pm
Nice job! I needed the youtube url scheme xD
April 8th, 2007 at 4:51 pm
@Jason,
Thanks for the feedback. Let me know if you have any problems. I’d be interested in some info on the error you’re getting with Niklas’ script. Could you tell me how to reproduce it? Maybe we can figure out what’s going on.
To be fair, I had some more advanced facilities available to me since I was working with a programming language vs. the command line.
April 8th, 2007 at 8:12 pm
[...] can come in handy for client-side programs too from time to time. Take the PHP script I wrote to download YouTube videos, for example. The script connects to YouTube, finds the URLs of the relevant FLV files, and pushes [...]
April 9th, 2007 at 7:46 am
nice job, it works better imo then the shell script.
April 13th, 2007 at 4:11 pm
Could you please make “YouTube Video Ripper in PHP” script available to be download in ZIP format (including the submit form just like on your example page http://immike.net/scripts/youtube-links.php)?
I am very new in PHP and tried your script (youtube-user.phps) but did not work after all because I am confusing on $argv[2].
If I left $argv[2] empty then the script did not work.
But if it contains string (example: fun) then it did not return the video links, except this statement “Attempting to download all videos by user wieb matching the pattern ‘fun’”
That is the reason why I need your example submit form. Forgive me if I am so dumb in PHP because I am in early stage on learn it.
Thank you for your kindness.
April 13th, 2007 at 4:25 pm
@wieb
Sure, why not. Download both scripts at http://immike.net/files/youtube_ripper.zip
You were having trouble because there is no user named wieb on Youtube. The script couldn’t find any videos matching your query so it didn’t download anything.
The $argv variable is an array of command line arguments that are passed into the program. $argv[0] is the name of the script, $argv[1] is the first argument asfter the script name, $argv[2] is the next argument, and so on.
April 13th, 2007 at 6:49 pm
Thank you for your kindness, it is really helping me.
April 13th, 2007 at 8:01 pm
Sorry to bother you again.
I tried to get link from YouTube user ‘enriq2772′ which has 1200 videos and the videos link spread all over 50 pages. But this script only get all video link on the last page.
I modified the script like this:
file_get_contents(’http://www.youtube.com/profile?user=’.$user.’&page=5′);
But still did not change anything, it still get all video link on last page, and not all video link on page 5.
What should I do?
Please help.
April 13th, 2007 at 8:07 pm
Is there anyway to autorename the downloaded video based on the name of the original video using this script, instead of “get_video” file name?
April 18th, 2007 at 9:20 am
i had the same problem, i want to download videos from a user that has like 300 videos, but when i use the script you configurated here: http://immike.net/scripts/youtube-links.php it only finds like 6-7 videos, so it’s not of much use right now…there’s nothing you can do about it?
the videos in question are all named similiar so it shouldn’t be an issue
April 19th, 2007 at 4:10 pm
[...] y el dueño de Canonical, por cierto muy acorde con el día de hoy verdad? Por cierto, el script ha sido adaptado a PHP por si alguien está pensando utilizarlo dentro de una aplicación [...]
May 5th, 2007 at 10:33 pm
@PJ & wieb
The problem is that the script only grabs videos from the user’s home page. I’ll have to take a look at it and modify it to follow page links.
May 19th, 2007 at 6:59 pm
well, regex matching aint efficient.
i have a similar service which indexes all youtube user videos in my vidoe index @ http://youclipit.net/bulkimport
well, you can also index individual videos at http://youclipit.net/mashup
if you noitcie the way my script runs, i index all user videos even if the video count of a specific user in in thousands… and not stop at the first 10 videos as what happens when you use regex matching…
cheers. comments welcome
July 2nd, 2007 at 8:10 pm
jazz, can you share some pointers on how you doing that?
thx.
August 2nd, 2007 at 8:09 am
If flash sucks as you contend in your inane latest post, then sorry but eat your own bullshit and don’t use youtube.
Asshole.
August 24th, 2007 at 7:38 pm
YouTube just changed the format of their HTML in their individual pages. You can’t search for swfobject anymore unless you can fool the javascript into thinking you have a valid Flash player. However, the unique video ID can be found by regexp-ing for /watch_fullscreen.+?”/
September 30th, 2007 at 1:16 am
so how do we get all the vidoes such as Jazz did?
i tested his site and it imports everything into his site, very nicely done!
Jazz any way of helping others with that?
December 5th, 2007 at 6:32 am
Hey I did something similar and your code helped me a lil so I decided to post it here:
http://ninjaretarded.com/?postid=7
March 11th, 2008 at 10:31 pm
Didnt work for me at all for some reason. I put in the username and got a blank page. I got the following in the error log.
PHP Warning: file_get_contents(http://www.youtube.com/profile?user=blyster1) [function.file-get-contents]: failed to open stream: no suitable wrapper could be found in /hermes/bosweb/web131/b1314/sl.dstantler/public_html/youtube-links.php on line 14
PHP Warning: file_get_contents() [function.file-get-contents]: URL file-access is disabled in the server configuration in /hermes/bosweb/web131/b1314/sl.dstantler/public_html/youtube-links.php on line 14
Any thoughts?
March 18th, 2008 at 3:40 pm
What about just giving the url of a single video and downloading it? Thanks
March 23rd, 2008 at 2:40 am
could you please gv me the php code to download the movie?? it should download it when i give the url i get when i watch the movie on youtube?
rgds
Tanya de silva
April 8th, 2008 at 7:20 pm
great blog always happy to find another blog in my industry to read with php coding and knowledge on building web tools.
I’ve written my own class for this using exec. Suppose I should have done some poking around first.