In the past I’ve published some articles regarding how to download music from youtube with the program YouTube to MP3, or videos with the programs xVideoServiceThief and flareget, they all accomplish the work with graphical interfaces, and this can be a great plus for many users, but others could prefer a simple command line program that can easily download videos and optionally extract the audio in a specific format: youtube-dl.
youtube-dl is a small command-line program to download videos from YouTube.com and a lot more sites. It requires the Python interpreter (2.6, 2.7, or 3.3+), and it is not platform specific. It should work in your Linux box, in Windows or in Mac OS X. It is released to the public domain, which means you can modify it, redistribute it or use it however you like.
Installation
youtube-dl it’s available on the repository of the main distribution so, if you want, you can install the package with your package manager, for Debian based distributions such as Ubuntu and Mint the command is:
sudo apt-get install youtube-dl |
But these packages could not keep the pace with the changes/update made on the youtube website, so in this particular case I suggest to download the binary directly from the official website
Looking at that page today the command to download the latest version it’s:
sudo curl https://yt-dl.org/downloads/2014.01.03/youtube-dl -o /usr/local/bin/youtube-dl sudo chmod a+x /usr/local/bin/youtube-dl |
If you do not have curl, you can alternatively use a recent wget:
sudo wget https://yt-dl.org/downloads/2014.01.03/youtube-dl -O /usr/local/bin/youtube-dl sudo chmod a+x /usr/local/bin/youtube-dl |
As example today I could use the official Mint 16 version, that it’s based on a release of the 29 of august 2013:
mint-desktop ~ # apt-cache policy youtube-dl youtube-dl: Installed: 2013.08.29-1 Candidate: 2013.08.29-1 Version table: *** 2013.08.29-1 0 500 http://archive.ubuntu.com/ubuntu/ saucy/universe amd64 Packages 100 /var/lib/dpkg/status |
While the direct download give me the latest version of this software.
So this method will guarantee that you’ll have the latest version youtube-dl and you’ll be able to use the “upgrade feature” available with the command.
Basic Usage
To download a video
1- Go to youtube and search the video you want to download
2- Copy the Video URL from the browser’s navigation(address) bar (As shown in the image)
3- Open up terminal and type in
youtube-dl {video URL} |
~ Don’t forget to replace ‘{video URL}’ with the URL you copied from the browser’s navigation(address) bar and your video will start downloading
Change video Format
This will download the video at the highest resolution available, something that perhaps you don’t want/need, so it’s possibile to see which formats are available with the option -F, in my case:
linuxaria@mint-desktop ~/Downloads $ ./youtube-dl -F http://www.youtube.com/watch?v=22UiGcxrbu8 [youtube] Setting language [youtube] 22UiGcxrbu8: Downloading webpage [youtube] 22UiGcxrbu8: Downloading video info webpage [youtube] 22UiGcxrbu8: Extracting video information [youtube] 22UiGcxrbu8: Encrypted signatures detected. [info] Available formats for 22UiGcxrbu8: format code extension resolution note 139 m4a audio only DASH audio , audio@ 48k (worst) 140 m4a audio only DASH audio , audio@128k 160 mp4 192p DASH video 133 mp4 240p DASH video 134 mp4 360p DASH video 135 mp4 480p DASH video 136 mp4 720p DASH video 17 3gp 176x144 36 3gp 320x240 5 flv 400x240 43 webm 640x360 18 mp4 640x360 22 mp4 1280x720 (best) |
Now I can choose which format download with the flag -f, so to download the webm at 640×360 I can use the command:
./youtube-dl -f 43 http://www.youtube.com/watch?v=22UiGcxrbu8 |
Extracting Audio of Youtube Videos
If you just want the audio of the youtube video, you can issue the following 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 (keep).
Hence all together to download the video http://www.youtube.com/watch?v=22UiGcxrbu8 and extract the audio in mp3 format with a bitrate of 176kbps and keep the video, you can use the command:
youtube-dl http://www.youtube.com/watch?v=22UiGcxrbu8 --audio-format mp3 --audio-quality 176 -k |
From the man page:
-x, –extract-audio convert video files to audio-only files (requires ffmpeg or avconv and ffprobe or avprobe)
–audio-format FORMAT “best”, “aac”, “vorbis”, “mp3”, “m4a”, “opus”, or “wav”; best by default
-k, –keep-video keeps the video file on disk after the post-processing; the video is erased by default
As noted in the man page I’ve had to install some extra software to extract the audio in mp3 format, for my mint 16 (aka Ubuntu 13.10) the packages are:
libav-tools
libavcodec-extra-53:amd64
libavdevice53:amd64
libavfilter2:amd64
libavcodec53:amd64
libmp3lame-dev:amd64 |
Other Useful options:
Autoupdate the software at the latest version, this is not possible if you installed the software via the distribution package:
linuxaria@mint-desktop ~/Downloads $ ./youtube-dl -U youtube-dl is up-to-date (2014.01.03) |
Pausing and Resuming downloads:
To pause or cancel the download, use Control-C. You can resume downloading the video using the following command
youtube-dl -c |
Conclusions
youtube-dl
it’s a powerful tool that allow you to download easily video from youtube and many more websites with ease, and included in the program there is also the option to extract only the audio tracks, really useful for music video.
Popular Posts:
- None Found
On ArchLinux, can be found too.
I posted a script that can simplify youtube-dl downloading at http://blog.mpshouse.com/?p=855
Thanks for sharing it.
When you say “To pause or cancel the download, use Control-C.”, do you mean Press Ctrl + c while a terminal emulator (like Konsole) is open?
I wish I was a computer geek with a photographic memory so I could remember all the required command characters to type. It was so nice when DownLoad Helper was still working…….sigh
You have not included the -x parameter the example command for Extracting Audio of Youtube Videos
youtube-dl http://www.youtube.com/watch?v=22UiGcxrbu8 --audio-format mp3 --audio-quality 176 -k
It should be
youtube-dl http://www.youtube.com/watch?v=22UiGcxrbu8 -x --audio-format mp3 --audio-quality 176 -k
I downloaded the video but cannot find where it goes