tinyapps.org / blog


Batch download YouTube videos from the command line #

UPDATE: See also Download videos from YouTube, Metacafe, Daily Motion, Vimeo, and more.

youtube-dl 2010.04.04: Written in Python; public domain license; excellent documentation; runs under *nix, OS X, Windows; works with latest YouTube changes. First attempt to batch download in bash returned an error:

$ youtube-dl.sh -o %(title)s.%(ext)s --batch-file urls.txt --best-quality --no-overwrites
-bash: syntax error near unexpected token `('
Just had to enclose the output template in single quotation marks:
$ youtube-dl.sh -o '%(title)s.%(ext)s' --batch-file urls.txt --best-quality --no-overwrites
The URLs for urls.txt were collected from a YouTube playlist webpage like so:
$ grep -o '/watch?v=.\{11\}' source.htm | sed 's/^/http:\/\/youtube.com/' | uniq > urls.txt
with sed prepending http://youtube.com to grep's output, and uniq culling the duplicates.

UPDATE 1: To specify the desired quality format, use -f #, where # is one of the format values shown in the first row below:

fmt value 5 6 34 35 18 22 37 38 83 82 85 84 43 44 45 46 100 101 46 102 13 17
Default container FLV MP4 WebM 3GP
Video Encoding Sorenson H.263 MPEG-4 AVC (H.264) VP8 MPEG-4 Visual
Profile Main Baseline High 3D 3D
Resolution progressive 224p 270p 360p 480p 360p 720p 1080p 2304p 240p 360p 520p 720p 360p 480p 720p 1080p 360p 480p 540p 720p
Resolution VGA WQVGA HVGA nHD FWVGA nHD WXGA WUXGA HXGA nHD FWVGA WXGA WUXGA
Max width (pixels) 400 480 640 854 640 1280 1920 4096 854 640 1920 1280 640 854 1280 1920 640 854 1920 1280 176
Max height (pixels) 240 270 360 480 360 720 1080 3072 240 360 520 720 360 480 720 1080 360 480 540 720 144
Bitrate (Mbit/s) 0.25 0.8 0.5 0.8–1 0.5 2–2.9 3–4.3 3.5–5 0.5 2-2.9 0.5 1 2 0.5 2
Audio Encoding MP3 AAC Vorbis AAC
Channels 1–2 2 (stereo) 1
Sampling rate (Hz) 22050 44100 22050
Bitrate (kbit/s) 64 128 96 152 96 152 128 192 128 192

(Above table is from Wikipedia's YouTube entry)

UPDATE 2: Video Backup Fusion offers an easy way to save all upload or playlist URLs to a text file (the download function seems to have broken as of May 2014). Source code and binaries available for Windows, Linux, and Haiku. You may want to uncheck "Show video thumbnails" in Settings and change the "Max. videos in list" value to 5000 (the maximum it will accept). Highlight all results, right click, select "Copy url(s)", and paste into your favorite text editor.

UPDATE 3: It's been almost 5 years since this post, but youtube-dl is still going strong, having just been updated yesterday (2015-03-28). Here are two more neat ideas from a HN thread:

/nix | Apr 11, 2010


Subscribe or visit the archives