Youtube-DL (YT-DLP)

To download a single video or an entire playlist from YouTube, simply enter the URL in the following format:

yt-dlp https://www.youtube.com/watch?v=t5b20oLaIaw

To download a video or playlist to a specific location, use the -o flag followed by the target directory. For example:

yt-dlp -o '~/Downloads/Abdul Kalam Biography' https://www.youtube.com/watch?v=t5b20oLaIaw

To include additional details in the filename, such as the title, uploader name, upload date, and playlist name, use the following format:

yt-dlp -o '%(title)s by %(uploader)s on %(upload_date)s in %(playlist)s.%(ext)s' https://www.youtube.com/watch?v=t5b20oLaIaw

    Here is a breakdown of the different options used in the above commands:
    • yt-dlp: The name of the command-line tool used to download videos and playlists.
    • -o: The flag used to specify the output filename or directory.
    • %(title)s: The title of the video or playlist.
    • %(uploader)s: The name of the video or playlist uploader.
    • %(upload_date)s: The date on which the video or playlist was uploaded.
    • %(playlist)s: The name of the playlist, if the video is part of a playlist.
    • %(ext)s: The file extension of the downloaded video or audio file.

You can download multiple videos by specifying their URLs in the command, separated by spaces like so:

yt-dlp
or use a text file
yt-dlp -a url.txt

Download Audio-only from a Video:

To download a video as Audio i.e. extract audio from a video, use -x flag like below.

yt-dlp -x https://www.youtube.com/watch?v=t5b20oLaIaw

You can also specify the output audio format using the -x --audio-format flag.

yt-dlp -x --audio-format mp3 https://www.youtube.com/watch?v=t5b20oLaIaw

To download a video along with its accompanying details, including description, metadata, annotations, subtitles, and thumbnail, use the following command:

yt-dlp --write-description --write-info-json --write-annotations --write-sub --write-thumbnail

These commands provide you with an overview of the various formats in which the content is accessible, assisting you in making an informed selection.

To view a comprehensive list of all the available formats for a video or playlist, utilize the following command:

yt-dlp --list-formats https://www.youtube.com/watch?v=t5b20oLaIaw
Alternatively, you can achieve the same result with -F flag:
yt-dlp -F https://www.youtube.com/watch?v=t5b20oLaIaw

      As you see from the output, yt-dlp presents a comprehensive display of all the accessible video formats in an organized tabular column. Moving from left to right, this display includes essential details such as
    • ID,
    • Extension (EXT),
    • Resolution,
    • Frames Per Second (FPS),
    • Channel (CH),
    • Filesize,
    • Total Bitrate (TBR),
    • Protocol (PROTO),
    • Video Codec (VCODEC),
    • Video Bitrate (VBR),
    • Audio Codec (ACODEC),
    • Audio Bitrate (ABR),
    • Audio Sampling Rate (ASR),
    • and additional information.

Download vidoes by ID or video format:

By ID:
yt-dlp -f 247 https://www.youtube.com/watch?v=t5b20oLaIaw
using -f 22/17/18 means it will attempt to download format 22 if available, then format 17 if format 22 is not available, and so on.

By Format:
To download video(s) in your preferred format, such as MP4, simply execute the following command:
yt-dlp -f mp4 https://www.youtube.com/watch?v=t5b20oLaIaw
yt-dlp -f 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best' https://www.youtube.com/watch?v=t5b20oLaIaw
yt-dlp -f mp4 -o '%(title)s.f%(format_id)s.%(ext)s' https://www.youtube.com/watch?v=t5b20oLaIaw

Source: