Downloading YouTube Playlist in CLI using yt-dlp
yt-dlp is a handy CLI tool for downloading videos from YouTube, especially the playlists. We can download an entire playlist like so:
1. Get the playlist identifier from the URL
For example, the playlist identifier of Babbar's DSA course is the value of list
query parameter of its YouTube URL https://www.youtube.com/playlist?list=PLDzeHZWIZsTryvtXdMr6rPh4IDexB5NIA
PLAYLIST_ID=PLDzeHZWIZsTryvtXdMr6rPh4IDexB5NIA
mkdir DSA-Course && cd $_
2. Run yt-dlp
with --yes-playlist
switch
yt-dlp "https://www.youtube.com/playlist\?list=$PLAYLIST_ID" \
--yes-playlist \
--format 'bestvideo*+bestaudio' \
--output "%(playlist_index)02d-%(title)s.%(ext)s"
- -f bestvideo*+bestaudio ensures best possible quality video and audio format is selected.
-F
or--list-formats
will list all the available formats, from which we can select the custom format by specifying index (eg:-f '399+599'
)
- -o %(playlist_index)02d-%(title)s.%(ext)s saves the videos with two-digit index prefix. For example, the second video in the playlist will be saved as "02-Lecture 2: Write Your First Program in C++.webm".