How to Download YouTube Videos in Linux

There is a python script available that can download YouTube videos as .flv files called youtube-dl. The script can be installed in an Ubuntu based Linux distribution by using a graphical package manager or with the following command:

sudo apt-get install youtube-dl

The script did not work correctly for me when I Installed it from the Ubuntu repository.  I received the following error:

bill@K11:~/Desktop/tmp$ youtube-dl 4GmdR49wLJE
[youtube] Setting language
[youtube] 4GmdR49wLJE: Downloading video webpage
[youtube] 4GmdR49wLJE: Downloading video info webpage
[youtube] 4GmdR49wLJE: Extracting video information
ERROR: no fmt_url_map or conn information found in video info

The script can be updated to the latest stable version with the following command:

sudo youtube-dl --update

The output of the command should look like this:

bill@K11:~/Desktop/tmp$ sudo youtube-dl --update
Updating to latest stable version...
Updated to version 2011.08.04

Another problem I had with the script was I had to set an output file and path or it would not work. Here are my attempts to get the script to download a video without setting the full path and file for the downloaded video:

bill@K11:~/Desktop/tmp$ youtube-dl 4GmdR49wLJE
[youtube] Setting language
[youtube] 4GmdR49wLJE: Downloading video webpage
[youtube] 4GmdR49wLJE: Downloading video info webpage
[youtube] 4GmdR49wLJE: Extracting video information
ERROR: unable to open for writing: [Errno 2] No such file or directory: u'4GmdR49wLJE.flv.part'
bill@K11:~/Desktop/tmp$ ls
bill@K11:~/Desktop/tmp$ youtube-dl http://www.youtube.com/watch?v=4GmdR49wLJE
[youtube] Setting language
[youtube] 4GmdR49wLJE: Downloading video webpage
[youtube] 4GmdR49wLJE: Downloading video info webpage
[youtube] 4GmdR49wLJE: Extracting video information
ERROR: unable to open for writing: [Errno 2] No such file or directory: u'4GmdR49wLJE.flv.part'
bill@K11:~/Desktop/tmp$ youtube-dl -o video.flv 4GmdR49wLJE
[youtube] Setting language
[youtube] 4GmdR49wLJE: Downloading video webpage
[youtube] 4GmdR49wLJE: Downloading video info webpage
[youtube] 4GmdR49wLJE: Extracting video information
ERROR: unable to open for writing: [Errno 2] No such file or directory: u'video.flv.part'

After setting the the full path and file name for the downloaded video file it works. The file and path can be set with the -o option. This is the output of youtube-dl working correctly:

bill@K11:~/Desktop/tmp$ youtube-dl -o ~/Desktop/tmp/video.flv 4GmdR49wLJE
[youtube] Setting language
[youtube] 4GmdR49wLJE: Downloading video webpage
[youtube] 4GmdR49wLJE: Downloading video info webpage
[youtube] 4GmdR49wLJE: Extracting video information
[download] Destination: /home/bill/Desktop/tmp/video.flv
[download] 100.0% of 6.90M at  392.88k/s ETA 00:00

The script seems to work fine if used like this:

youtube-dl -o <full path and file for downloaded video> <youtube video id>

The video id can be found in the page URL. If the URL for the video is ‘http://www.youtube.com/watch?v=4GmdR49wLJE’ then the video id which is 4GmdR49wLJE can be found after the ?v=. If the page URL has extra information in it like this ‘http://www.youtube.com/watch?v=4GmdR49wLJE&feature=channel_video_title’, the video id which is still 4GmdR49wLJE is between ?v= and the & character.

If it is a little hard to find the video id then youtube-dl can take the entire page URL and do the hard work for you by extracting the video id.

bill@K11:~/Desktop/tmp$ youtube-dl -o ~/Desktop/tmp/video.flv http://www.youtube.com/watch?v=4GmdR49wLJE&feature=channel_video_title
[youtube] Setting language
[youtube] 4GmdR49wLJE: Downloading video webpage
[youtube] 4GmdR49wLJE: Downloading video info webpage
[youtube] 4GmdR49wLJE: Extracting video information
[download] Destination: /home/bill/Desktop/tmp/video.flv
[download] 100.0% of 6.90M at  407.22k/s ETA 00:00

Tags: , , , , , , ,

3 Responses to "How to Download YouTube Videos in Linux"

Leave a Comment