Zimbabwe and regional technology news and updates


Ubuntu: Downloading YouTube videos

This article is part of a series of guest posts by Garikai Dzoma on helping new users migrate successfully to the Ubuntu operating system. Garikai started using Ubuntu Linux in 2007 and is an active member of the Zimbabwe Ubuntu LoCo team.

One of the good things about the good old Firefox 3 was that when in Ubuntu flash videos were downloaded to the /tmp directory. All you had to do was wait for the buffering to complete, minimize the Firefox window, got to the /tmp directory and copy and paste the video into the folder of your choosing. Playing the video is easy enough; vlc plays pretty much any format from .mp4 to .flv.

Imagine my shock when I visited YouTube using Firefox 4 for the first time  and could not find anything in the /tmp folder. After a lot of digging I found that the new browser uses a per user cache which is in the ~/.firefox  directory. After I spend 10 minutes exploring the tree I could still not find the video file and fuming I decided to Google  it. And then I met youtube-dl: the pedigree python based YouTube downloader.

I am aware that youtube-dl is in the repositories. However the upstream version is significantly up-to-date when compared with the version in the repositories. So the examples below are on the upstream version. If you want the easy way out just type the command:

  • sudo apt-get install youtube-dl

This is a command line program which works on all platforms including Windows and yet it is an amazing 103KB. To get youtube-dl:

  1. Visit the download page  in your browser and right click on the download link and select save as youtube-dl or
  2. Alternatively you can open the terminal and type the command:
  3. wget –tries=0

The first method saves the youtube-dl file in the ~/Downloads folder whilst the second method saves the youtube-dl file in the current directory most likely in the /home/user directory where user is the name of the current user. Preparing youtube-dl If you used the first method i.e. the browser method please open the terminal and type the command:

  • cd ~/Downloads/

This will take you to the directory where youtube-dl is i.e. this becomes the current directory. The following commands now apply to both method 1 and 2. Please note if you used method 2 above i.e. you used wget you should skip the cd ~/Downloads/ command above and follow the following commands.

  1. sudo chmod a+x youtube-dl
  2. This makes the file executable.

  3. sudo cp youtube-dl /usr/local/bin/
  4. This copies the youtube-dl file to the /usr/local/ directory where all locally installed and compiled programs are stored. This makes sure that the youtube-dl program is in everyone’s PATH i.e. any user on your system can now just type youtube-dl to access the program. Tip: In the command line you can save time by just typing yout and pressing the Tab key so the shell can autocomplete/expand the name.

  5. To download a video just open a terminal and type youtube-dl http://video.url where video.url is the web address of the video. For example youtube-dl this downloads a video to show you one of the reasons I love Ubuntu over Windows.
  6. The above command downloads the video into the current directory usually /home/usr. Open nautilus/dolphin or some other file manager and visit your home directory to copy the videos where you want them. You can use the pwd command to find the current directory in case it is not your home directory.
  7. Videos can be played using vlc/xine/totem/mplayer or any comatible video player of your choice. This works with other video sites too not just YouTube.
  8. Please check for regular updates. Whenever there is an update follow this guide from step 1 or 2 but before step 5 type the command:
  9. sudo rm -f youtube-dl

  10. Videos can be converted using ffmpeg.( I will be write a guide on this but the command man ffmpeg should give you a place to start.) ffmpeg can also extract audio from videos and convert them into mp3s.)  I must add that ffmpeg is a command line program also but several gui front ends exist.

Quick NetOne, Econet, And Telecel Airtime Recharge

16 thoughts on “Ubuntu: Downloading YouTube videos

  1. Garikai, i think its probably easier just to install something like the netvideohunter firefox addon. netvideohunter lets you download youtube vids directly from the web-browser using firefox’s download manager. it just a matter of point and click from there.

    good article though… a bit too technical for the average user though.

    1. I must admit it looks daunting to the average user. I had this idea I got from the Linux journal a while ago. To automate the download of music files from youtube and then convert them into mp3s using ffmpeg. I was attempting the same feat: a series  of these articles.

  2. I would recommend the add-on downloadhelper – downloads just about anything streaming and is somewhat easier than typing (knowing) long strings in the addressfield

    1. If there is one thing I have leant in Linux in general and Ubuntu in particular, it is that downloads never get better than wget. Most of the helpers dont really help. The best one so far is the Firefox addon downloadthemall. However this does not seem to work on flash videos. Besides once installed the youtube-dl works fine without the candy.

  3. It’s great to see some consistency in Linux related articles, very informative pieces that we have been getting of late. Keep up the good work flowing Mr (Guest Author).

  4. Good article Garikai but l think it does little to attract those simple users who are used to point and click.

    Just to clarify, what do you mean by:
    ”sudo apt-get install youtube-dl

    This is a command line program which works on all platforms including Windows and yet it is an amazing 103KB.”

    From my knowledge, the ”sudo” is unique to Debian not any other Linux OS, most use su. Do you mean this works on MicroShaft Windows as well???

    1. macd, the article is about ubuntu…clearly stated I think. Remember this is more like hacking, so anyone who needs to hack must cease to become a simple user like you i guess. Thanks Gari for such a brilliant documentation. I google no more, you have done a good job.

    2. @ea25193fe8b994b12d8d7ce0e892a1b6:disqus In fact the sudo utility is on almost all Linux distros! Pple just ignore it for the most part it’s there on Fedora,Centos,RHEL,openSUSE etc. Ubuntu however uses a setuid method i.e. root is locked by default. You will also notice that the su command simply means switch user and by default of course using su without arguments assumes switch user to root. This in my opinion is an abuse of the command since it lacks the refinement of sudo. To answer your other question. To make youtube-dl run on windows you just need to download and install the python interpreter, download and save youtube-dl in the system32 directory, press Windows key+r, type cmd and press enter (this should open the command prompt) type youtube-dl -o c:videosvideo_name_here (the tab key works here also to auto complete), copy and paste the url.

Comments are closed.