I have a script that downloads mp4 files from youtube. What it does is to generate link of the form http://youtube.com/get_video?video_id=*VIDEO_ID*&&t=*THE_TOKEN*=&fmt=18&asv=2, but it doesn't work anymore (noticed it today). What do you think?
4 Answers
Instead of trying to use get_video to get the video, try parsing fmt_url_map (format-url map) instead.
You should be able to find the fmt_url_map in the same place you found the token (like in the flashvars of the YouTube flash video player or inside the YouTube page somewhere). If you can't find it, send a request to http://www.youtube.com/get_video_info?video_id=VIDEO_ID and you should get a really long result that is in the format of name=value&name=value&...
Find "fmt_url_map" inside this result (search through the result for a string that starts with "&fmt_url_map=" and ends with "&").
After you get this value (you may have to url-decode it), it will be something like (without the line breaks):
22|http://blah.youtube.com/videoplayback?blah,
35|http://blah.youtube.com/videoplayback?blah,
...
where each comma-separated entry starts with the fmt value (22 or 35 in the example), followed by a pipe character, which is then followed by the URL where you can use to download the video in that format. (This URL is client-specific, so a URL for a certain client most likely won't work with another client due to YouTube checking IPs. Also, the URLs do expire after a while.)
For a list of the different fmt values, see: http://en.wikipedia.org/wiki/YouTube#Quality_and_formats and show the "Comarison of YouTube media encoding options". NOTE: not all formats may be available for all videos.
Deprecated: won't work anymore!
-
+10 if I could. Question though: you said it's client-specific, so that won't work if I'm generating the url for the user to download the file on his own? Any other solutions for that? – samquo Dec 12 '10 at 09:58
-
This might be a problem (although get_video had this problem as well). If you actually request the page and get the download URL on an outside server, YouTube associates the server's IP with that URL (just like how it would associate an IP with each token in the get_video method). Assuming you're trying to do it in a web browser, you could try and do it client-side with a Java applet (that is what many sites like clipnabber.com do, although it can be pretty clunky). If you are just writing an entirely client-side program, it should be fine because all the requests are sent with the client's IP – jhartz Dec 13 '10 at 00:57
-
I noticed today that this method doesn't work anymore. If anyone of you know a working method kindly post it here – Pavan K Sep 14 '12 at 12:18
-
1
I've created a node.js server that can stream YouTube videos directly to the client and it works. See https://github.com/licson0729/node-YouTubeStreamer for details.

- 2,231
- 18
- 26
Well it seems like they have removed the fmt option. See http://en.wikipedia.org/wiki/YouTube#Quality_and_codecs.

- 1
-
2If you parse fmt_url_map (from http://www.youtube.com/get_video_info?video_id=*VIDEO_ID*), you can get a more direct download URL, but they usually don't have all the possible formats... – jhartz Dec 10 '10 at 22:59
-