How To Download Youtube Videos in Linux in Desired Format

In this tutorial I will show you how you can download Youtube videos in your desired format, batch download videos from a file, or extract the audio only from the downloaded video in Linux (Ubuntu, Fedora Arch Linux etc).

As everyone knows Youtube is the largest source of online videos in the world. There are many Youtube Video downloaders available in Windows platform, but most of them don’t work or are slow or require you to pay for downloading videos. Today I will show how you can download a Youtube  video  in  your  Linux  machine  for free also in desired format using a open source software known as youtube-dl. This will work on all popular Linux distros such as Ubuntu, Fedora, Arch Linux, Linux Mint etc.

Installing youtube-dl

Check your distro’s repositories if youtube-dl is available there. For Debian based distros such as Ubuntu or Linux Mint, you can use the following command.

sudo apt-get install youtube-dl
 
For RPM based
sudo yum install youtube-dl
 
Arch Linux users can use pacman to install it as follows
sudo pacman -S youtube-dl
 

You can also compile from source by downloading it from this page.

Using youtube-dl : Downloading videos, Pausing and Resuming downloads

To download a video, go to youtube.com and search the video you want to download. Open the video page and copy the URL from the address bar as shown below.

Copying Youtube URL

Make sure you have installed youtube-dl using the above steps. Issue the following command to start downloading the video

youtube-dl

eg. if the video URL is https://www.youtube.com/watch?v=Yc0CVEuUvRs, type

youtube-dl https://www.youtube.com/watch?v=Yc0CVEuUvRs

You will see some information as shown in the screenshot below, after which the video will start downloading and you will see the current speed and time remaining.

Downloading Youtube videos using youtube-dl

To pause or cancel the download, use Control-C. You can resume downloading the video using the following command

youtube-dl -c

Batch Downloading Youtube Videos from a file

You can also write URLs of the videos in a file to be downloaded and issue a single command to download it at once. To do that, search all the videos you want to download and copy paste the URLs in a text file, each URL in a separate line. Then issue this command to download all the videos at once. This is especially useful if you want to download a lot of videos and don’t have time enough to issue the command separately.

youtube-dl -a filename.txt
 

Where filename.txt is the file where the video URLs are saved.

Batch Download Youtube videos from a file -youtube-dl

Downloading Youtube videos in Preferred format

Often it may happen that you may want to download a video in a format different from the default one, or in a different resolution. To know what format a video is availiable, use the following command.

youtube-dl -F

Make sure you typed capital F. It will display the formats and resolutions the video is available in and their specific code in the first column.

Download video in a different format – youtube-dl
To download the file in your preferred format, type
youtube-dl -f


Eg. I want to download the file in .flv format with resolution 240×400, so I use this command

youtube-dl -f 5 https://www.youtube.com/watch?v=Yc0CVEuUvRs

The lower the resolution, the smaller will be the size of the file hence will save your data usage. By default, youtube-dl downloads the file in the best quality format.

Extracting Audio of Youtube Videos

If you just want the audio of the youtube video, you can issue this command to get it. The default is 128kbps. If you want to keep the video file too after the audio has been extracted, you can use the -k option. Hence all together to download my video http://www.youtube.com/watch?v=Yc0CVEuUvRs and extract the audio in mp3 format with a bitrate of 176kbps and keep the video, I use:

youtube-dl https://www.youtube.com/watch?v=Yc0CVEuUvRs –audio-format mp3 –audio-quality 176 -k

For more options, type

youtube-dl -h

19 comments

  1. Thanks! Works great. FYI: as of right now (01-28-2013) there is a problem. Youtube changed something to make it incompatible with youtube-dl, it’s been fixed in the latest version. According to this post http://leeunderwood.org/r/07 you will need to do the following to update youtube-dl until the package system gets the updated version (i.e., you will need to do it a few times):

    sudo youtube-dl -U

  2. Not Working :
    [youtube] Setting language
    [youtube] Yc0CVEuUvRs: Downloading video info webpage
    [youtube] Yc0CVEuUvRs: Extracting video information
    ERROR: format not available for video

  3. Though downloading youtube videos is not legal and it’s not permitted by youtube but if you and i were producers ,we can follow youtube downloading only if intended for fair use also you gona find many videos which is under creative common license and reuse is permitted.So you can download those kind of videos and also reuse it.You can follow the above method for downloading videos or here is the youtube downloader which i use.

  4. hey,

    Though downloading YouTube videos is not legal & it’s not permitted by YouTube but If you and I were producers,we can allow YouTube downloading only if intended for fair use. Also you gonna find many youtube videos which is under creative common license and reuse is permitted. So you can download those kind of videos and also reuse it.
    You can follow the above method for downloading videos or here is the youtube downloader which I follow

  5. To download youtube videos is very simple, all you need id type in “ss” just after leaving www. in the url of the video and then click enter and doing this will redirect you to savefrom.net where you can choose the format of the video and your video will start downloading. Know here How to download youtube videos

  6. Hi
    I am getting the following error:

    youtube-dl https://www.youtube.com/watch?v=Ym1-rI0SdaA
    [youtube] Setting language
    [youtube] Ym1-rI0SdaA: Downloading video webpage
    [youtube] Ym1-rI0SdaA: Downloading video info webpage
    [youtube] Ym1-rI0SdaA: Extracting video information
    Traceback (most recent call last):
    File “/usr/lib/python2.7/runpy.py”, line 162, in _run_module_as_main
    “__main__”, fname, loader, pkg_name)
    File “/usr/lib/python2.7/runpy.py”, line 72, in _run_code
    exec code in run_globals
    File “/usr/bin/youtube-dl/__main__.py”, line 7, in
    File “/usr/bin/youtube-dl/__init__.py”, line 536, in main
    File “/usr/bin/youtube-dl/__init__.py”, line 520, in _real_main
    File “/usr/bin/youtube-dl/FileDownloader.py”, line 475, in download
    File “/usr/bin/youtube-dl/InfoExtractors.py”, line 80, in extract
    File “/usr/bin/youtube-dl/InfoExtractors.py”, line 405, in _real_extract
    File “/usr/bin/youtube-dl/InfoExtractors.py”, line 405, in
    KeyError: ‘sig’

    Any ideas?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.