This tutorial will help you download YouTube videos in practical ways, easy and useful using youtube-dl command line. We compile here eight most needed command lines you can everyone can quickly practice without any you don't need. Now let's try it out and happy downloading!
Subscribe to UbuntuBuzz Telegram Channel to get article updates.
1. Read video information
This command:
$ youtube-dl -F URL
will show output like below in Terminal:
which means this selected video is available in several different choices particularly audio-only, video-only, or full video in different quality and different file size. You can observe as it offers webm and mp4 choices, up to 3000x2000 quality, and up to 3 GigaByte file size. Please note that other videos could be different in these choices.
2. Download a video
This is the basic command:
$ youtube-dl URL
and it will show output like below in Terminal:
and as a result the video file is found in your file manager:
And finally you can play the video like our first screenshot above.
3. Download several videos
This command:
$ youtube-dl URL URL URL URL ... URL
will download all mentioned videos one by one. For example, if you want to grab recipe videos of pancake, cupcake and fruit cake you can do it as the following example:
4. Download audio only or a select video quality
First, read the detailed information of a video:
$ youtube-dl -F URL
Second, download a select video by its code to the left column. Notice the difference between uppercase 'F' and lowercase 'f'.
$ youtube-dl -f CODE URL
for example if you want to download video+audio in small size:
and in case you want to download audio only:
Please note that not all videos will have full options like video above as some do not offer 'audio-only' options. You may find some of them sooner of later.
5. Download an entire playlist and specify max file size
These commands:
$ youtube-dl PLAYLIST_URL
$ youtube-dl -f 'bestvideo[filesize<10M]' PLAYLIST_URL
will download all videos in a playlist. The difference is that the first one will do it in best quality and biggest file size (longest time to finish) while the second one do it with a specified file size treshold as small as possible (quickest time to finish). In this example, we grab an entire playlist only for videos under 10 MegaBytes. These are very useful to grab multiple videos from your favorite playlist.
6. Download subtitles
You can also download subtitle of the video, if any.
$ youtube-dl --list-subs URL
$ youtube-dl --write-sub URL
$ youtube-dl --write-auto-sub URL
First command prints out available subtitles of a video. If none available, it prints none. Second command will download the subtitle as a file (choices of format: .vtt .ttml .srv .json). Third command will download the subtitle if second one cannot. You can add --sub-lang en to grab specifically English language only. For other language, you can swap 'en' with other language code like 'id' or 'jp' if any. See picture below.
Above is VLC Media Player playing the video originally in English by adding Indonesian subtitle (ID). To do it like this, after you have the subtitle file, open the video in VLC -> pick menu Subtitle -> Add subtitle file -> pick the file -> OK -> video now plays with subtitle.
7. Download a list of multiple videos
You can also download all videos mentioned in a text file.
$ youtube-dl -a FILE.TXT
For example, below we created a text file (list.txt) containing five lines of URLs (top-right) highlighted in blue and we call it with youtube-dl. As a result, we downloaded five videos about yummy donut cooking.
8. Update youtube-dl
Lastly, because it deals with a service, youtube-dl (as the software) must be updated to the latest. Otherwise, YouTube (as the service) might change its behavior making older version of youtube-dl could not download it anymore. To do so, the developer team explained an easy command line:
$ pip install --upgrade --force-reinstall "git+https://github.com/ytdl-org/youtube-dl.git"
References
This article is licensed under CC BY-SA 3.0.