YouTube is an online video-sharing platform that contains a vast repository of videos covering a wide range of topics such as music videos, educational content, vlogs, tutorials, movie trailers, gaming videos, and live streams.
While the platform offers the convenience of streaming, there are certain scenarios where you might want to download these videos for offline viewing.
In the Linux command-line environment, yt-dlp
is a powerful and versatile command-line program that allows users to download 1080p or 4K YouTube videos from YouTube.com and other video sites.
In this article, we will guide you through the process of installing and using yt-dlp
to download YouTube videos on a Linux command line.
What is yt-dlp?
yt-dlp is a Python-based command line and fork of the well-known youtube-dl program that is created for downloading videos from popular video streaming platforms such as YouTube, Facebook, Twitter, Reddit, Imgur, Dailymotion, Hotstar, and various other video sites.
It is developed in Python and requires only Python 3.8+ and it is platform-specific, and designed to function seamlessly on Unix, Windows, or macOS environments.
It also supports many options, allowing users to customize their downloads based on preferences. One notable feature is downloading videos in different resolutions, including high-quality formats like 1080p or 4K.
Additionally, youtube-dl supports downloading entire playlists, extracting only the audio from videos, bypassing YouTube geo-restrictions, pausing and resuming video downloads, and splitting videos into multiple files.
How to Install yt-dlp on Linux
yt-dlp is the most widely used command-line tool that is easily available to install from the default repositories in most Linux distributions, if not all.
To install yt-dlp on Linux, use the following appropriate command for your specific Linux distribution.
sudo apt install yt-dlp [On Debian, Ubuntu and Mint]
sudo yum install yt-dlp [On RHEL/CentOS/Fedora and Rocky/AlmaLinux]
sudo emerge -a sys-apps/yt-dlp [On Gentoo Linux]
sudo apk add yt-dlp [On Alpine Linux]
sudo pacman -S yt-dlp [On Arch Linux]
sudo zypper install yt-dlp [On OpenSUSE]
To install the most recent version of yt-dlp, you can use the following curl command.
sudo curl -L https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp -o /usr/local/bin/yt-dlp sudo chmod a+rx /usr/local/bin/yt-dlp
If you do not have curl installed, you can alternatively use the following wget command.
sudo wget https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp -O /usr/local/bin/yt-dlp sudo chmod a+rx /usr/local/bin/yt-dlp
Once installed, you can use the following command to update it to the latest version.
yt-dlp -U
Downloading a YouTube Video on Linux
To download a YouTube video, use the following command, where <video_url>
is the URL of the YouTube video that you want to download.
yt-dlp <video_url>
For example, to download a YouTube video replace <video_url>
with the actual URL of the YouTube video you intend to download.
yt-dlp https://www.youtube.com/watch?v=60ItHLz5WEA
You can also download multiple videos at once by specifying a list of URLs separated by spaces.
yt-dlp <video_url_1> <video_url_2> ...
Downloading a YouTube Playlist on Linux
To download a YouTube playlist, simply run the following command to download the entire playlist. Make sure to replace the <playlist_url>
of the YouTube playlist URL that you want to download.
yt-dlp -i --yes-playlist
Downloading YouTube Videos in Different Formats
yt-dlp provides several options for downloading YouTube videos in various formats, allowing you to tailor the process to your specific needs.
To download a specific format, you first need to list the available format codes for a video by running.
yt-dlp -F https://www.youtube.com/watch?v=60ItHLz5WEA
To download high-quality YouTube video and audio, use the following command.
yt-dlp -f best https://www.youtube.com/watch?v=60ItHLz5WEA
To download YouTube videos in 1080 resolution, use the following command.
yt-dlp -f 'bestvideo[height=1080]+bestaudio/best[height=1080]' <video_url>
To download a YouTube video in 4K resolution, use the following command.
yt-dlp -f 'bestvideo[height=2160]+bestaudio/best[height=2160]' <video_url>
To download audio only (mp3 format) from a Youtube video, use the following command.
yt-dlp -x --audio-format mp3 <video_url>
To download a YouTube video in a specific format, use the following command.
yt-dlp -f mp4 <video_url>
Download Subtitles of YouTube Videos
yt-dlp provides the easiest way to download subtitles of videos directly alongside the video itself.
To list all available subtitles for a specific YouTube video, use the following command, which will show a list of available subtitles along with their language codes.
yt-dlp --list-subs https://www.youtube.com/watch?v=60ItHLz5WEA
To download subtitles along with a video, use the -S
option.
yt-dlp -S <video_url>
To download only specific subtitles, you can specify the language code after the -S
option.
yt-dlp -S en,es <video_url>
If you only want to download subtitles without the video, you can use the –write-sub option with the -S option.
yt-dlp -S –write-sub <video_url>
Conclusion
yt-dlp is a versatile and efficient command-line tool for downloading YouTube videos in the Linux environment. It comes with a broad range of customization options and supports various video and audio formats.
By following the steps outlined in this article, you can harness the power of yt-dlp to easily download and enjoy your favorite YouTube content offline on your Linux system.
Resources:
- GitHub – ytdl-org/youtube-dl: Command-line program to download videos from YouTube.com and other video sites
- GitHub – yt-dlp/yt-dlp: A youtube-dl fork with additional features and fixes
- Stacher
Source: techMint