Youtube is a media streaming and video sharing service available to anyone on any browser. It allows people to create their own videos and share them with others on the website. All this is done by creating what is known as a Youtube Channel.YouTube can be accessed from any device, a mobile phone, tablet, desktop, laptop, and TV. It is free to use and people can earn money from the platform by sharing videos.
These YouTube videos are accessed when one is online only but can also be downloaded to watch later on the platform. You can also download them to your device storage for easier access or share the video with other people. There are a number of tools and software used to download videos from YouTube including Lux, YouTube-dl, yt-dlp, video downloader, and PyTube.
YouTube-dl
YoutTube-dl is a command-line program that allows you to download videos from YouTube and other sites like Bili Bili. It downloads the best format quality of the video without passing any options.
yt-dlp
yt-dlp is a Youtube-dl fork-based program with additional features and fixes while keeping up to date with the original project. The features include;
- Format sorting options have been changed to a higher resolution.
- SponsorBlock API is integrated to mark or remove sponsor sections of Youtube vidoes.
- Cookies can be automatically extracted from major browsers.
- Subtitles can be extracted from streaming media manifests.
- Multiple download paths and output templates.
- Configuration files are automatically loaded from the home/root directories.
- The new releases are automatically updated.
- Videos can be split into multiple chapters.
There are a number of features that make yt-dlp different from the original Youtube-dl, they include;
- Stores configuration files in a different location.
- Some options have been removed like –auto-number (-A), –title (-t), and –literal (-l)
- The default output template has been changed.
- The format sorting prefers higher resolution and better codecs than high bitrates.
- Does not allow the merging of multiple audio/video files due to conflict.
This guide will show you how to install yt-dlp on Ubuntu/Debian and download videos from YouTube.
Install yt-dlp on Ubuntu/Debian
Update your system packages
sudo apt update && sudo apt upgrade -y
Method 1. Install yt-dlp using release binary
Download the release binary file to an installation directory using the following command.
sudo wget https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp -O /usr/local/bin/yt-dlp
Make the file executable.
sudo chmod a+rx /usr/local/bin/yt-dlp
To update it, use the following command.
$ yt-dlp -U
Latest version: 2022.04.08, Current version: 2022.04.08
yt-dlp is up to date (2022.04.08)
Method 2. Install yt-dlp with Pip package manager
Install PIP if you do not have it on your system.
sudo apt install python3-pip
Then install the file yt-dlp using the following command
$ python3 -m pip install -U yt-dlp
Successfully installed brotli-1.0.9 mutagen-1.45.1 pycryptodomex-3.14.1 websockets-10.3 yt-dlp-2022.4.8
To update it, simply re-run the install command that you used.
$ python3 -m pip install -U yt-dlp
Requirement already up-to-date: yt-dlp in ./.local/lib/python3.8/site-packages (2022.4.8)
Requirement already satisfied, skipping upgrade: pycryptodomex in ./.local/lib/python3.8/site-packages (from yt-dlp) (3.14.1)
Requirement already satisfied, skipping upgrade: certifi in /usr/lib/python3/dist-packages (from yt-dlp) (2019.11.28)
Requirement already satisfied, skipping upgrade: mutagen in ./.local/lib/python3.8/site-packages (from yt-dlp) (1.45.1)
Requirement already satisfied, skipping upgrade: websockets in ./.local/lib/python3.8/site-packages (from yt-dlp) (10.3)
Requirement already satisfied, skipping upgrade: brotli; platform_python_implementation == "CPython" in ./.local/lib/python3.8/site-packages (from yt-dlp) (1.0.9)
Usage Examples
Some commands require external dependencies. Install them if you do not have them in your system.
sudo apt install ffmpeg
There are different options used with yt-dlp to download and view YouTube videos. I will use a Youtube video URL as an example on all the commands.
To view the available formats and resolutions of a video with the –list-formats option
$ yt-dlp --list-formats "https://www.youtube.com/watch?v=f2OGhJoypPw"
To download a video or playlist with default options use the following command
$ yt-dlp "https://www.youtube.com/watch?v=f2OGhJoypPw"
[youtube] f2OGhJoypPw: Downloading webpage
[youtube] f2OGhJoypPw: Downloading android player API JSON
[info] f2OGhJoypPw: Downloading 1 format(s): 22
[download] Destination: The Mystery of Marilyn Monroe - The Unheard Tapes _ Official Trailer _ Netflix [f2OGhJoypPw].mp4
[download] 100% of 8.18MiB in 00:00
To download a video with a defined format by default which is the best video and best studio stream, use the following command
$ yt-dlp --format "bv*+ba/b" "https://www.youtube.com/watch?v=f2OGhJoypPw"
[youtube] f2OGhJoypPw: Downloading webpage
[youtube] f2OGhJoypPw: Downloading android player API JSON
[info] f2OGhJoypPw: Downloading 1 format(s): 248+251
[download] Destination: The Mystery of Marilyn Monroe - The Unheard Tapes _ Official Trailer _ Netflix [f2OGhJoypPw].f248.webm
[download] 100% of 20.92MiB in 00:00
[download] Destination: The Mystery of Marilyn Monroe - The Unheard Tapes _ Official Trailer _ Netflix [f2OGhJoypPw].f251.webm
[download] 100% of 1.87MiB in 00:00
[Merger] Merging formats into "The Mystery of Marilyn Monroe - The Unheard Tapes _ Official Trailer _ Netflix [f2OGhJoypPw].webm"
Deleting original file The Mystery of Marilyn Monroe - The Unheard Tapes _ Official Trailer _ Netflix [f2OGhJoypPw].f248.webm (pass -k to keep)
Deleting original file The Mystery of Marilyn Monroe - The Unheard Tapes _ Official Trailer _ Netflix [f2OGhJoypPw].f251.webm (pass -k to keep)
To download, let’s say a 720p video with the best audio stream, use the following command
$ yt-dlp --format "bv*[heigh=720]+ba/b" "https://www.youtube.com/watch?v=f2OGhJoypPw"
[youtube] f2OGhJoypPw: Downloading webpage
[youtube] f2OGhJoypPw: Downloading android player API JSON
[info] f2OGhJoypPw: Downloading 1 format(s): 22
[download] Destination: The Mystery of Marilyn Monroe - The Unheard Tapes _ Official Trailer _ Netflix [f2OGhJoypPw].mp4
[download] 100% of 8.18MiB in 00:00
To extract audio from a video, use the following command
$ yt-dlp --extract-audio "https://www.youtube.com/watch?v=f2OGhJoypPw"
[youtube] f2OGhJoypPw: Downloading webpage
[youtube] f2OGhJoypPw: Downloading android player API JSON
[info] f2OGhJoypPw: Downloading 1 format(s): 251
[download] Destination: The Mystery of Marilyn Monroe - The Unheard Tapes _ Official Trailer _ Netflix [f2OGhJoypPw].webm
[download] 100% of 1.87MiB in 00:00
[ExtractAudio] Destination: The Mystery of Marilyn Monroe - The Unheard Tapes _ Official Trailer _ Netflix [f2OGhJoypPw].opus
Deleting original file The Mystery of Marilyn Monroe - The Unheard Tapes _ Official Trailer _ Netflix [f2OGhJoypPw].webm (pass -k to keep)
To download subtitles of a video as a default .vtt file, use the following command.
$ yt-dlp --write-subs en "https://www.youtube.com/watch?v=f2OGhJoypPw"
To list the available formats of subtitles available, use the following command.
$ yt-dlp --list-subs "https://www.youtube.com/watch?v=f2OGhJoypPw"
Language Name Formats
en-US English (United States) vtt, ttml, srv3, srv2, srv1, json3
To specify the format to download the subtitles, use the –sub-format option.
$ yt-dlp --write-subs en --sub-format json3 "https://www.youtube.com/watch?v=f2OGhJoypPw"
Download all playlists of YouTube channel/user keeping each playlist in a separate directory:
$ yt-dlp -o "%(uploader)s/%(playlist)s/%(playlis-index)s - %(title)s.%(ext)s" "https://www.youtube.com/c/LinuxfoundationOrg/playlists"
Conclusion
From this guide, we have discussed a little bit of Youtube-dl and yt-dlp tools used to download YouTube Videos. We have also gone through the steps of installing the yt-dlp on Ubuntu\Debian systems using the binary release file and with PIP. yt-dlp being a command-line program makes it callable in any programming language.