Download YouTube Videos from the Command Line

📢 This article was translated by gemini-2.5-flash

Intro

What dev doesn’t want to run stuff from the command line just to look cool? I knew about youtube-dl before but thought it looked too complicated to bother with. Tried it today and it’s actually super slick!

Setup

Install Python 3.7+

Just head to the Python official site and install it. Make sure to check Add Python x.x to PATH during installation.

Install yt-dlp

yt-dlp is a fork of youtube-dl , and from my tests, it’s noticeably faster.

Download

Go to the releases page and grab yt-dlp.exe.

Setup Path

Drop the downloaded file into a fixed location. Open This PC’s Properties, then go to Advanced system settings -> Environment Variables -> System variables. Select Path, click Edit, then in the new window, click New and enter the path where your yt-dlp.exe file is.

Click OK three times to close all windows.

Test It Out

Hit Win+R, type cmd, and press Enter.

In cmd, type yt-dlp. If you see Usage: yt-dlp [OPTIONS] URL [URL...], you’re good to go.

Update

Just type yt-dlp -U in cmd.

Download Videos

In cmd, simply type yt-dlp + space + YouTube video link to start downloading.

Default download is 720P, saved to C:/Users/%UserName%/.

Change Download Location

Create a new folder named yt-dlp in C:\Users\%UserName%\AppData\Roaming. Go into this new folder and create a file called config.txt.

Add this line to the file:

1
-o 'C:/Users/%UserName%/Downloads/Video/%(title)s.%(ext)s'

Here, C:/Users/%UserName%/Downloads/Video/ is your download directory.

%(title)s.%(ext)s defines the filename format; here, it’s video title.extension.

Download 1080P

For 1080P and higher videos, audio and video are separate streams, so you’ll need to download ffmpeg first.

ffmpeg

Head to the official site , pick your system type from the bottom left, then download.

I went with Releases · BtbN/FFmpeg-Builds and downloaded ffmpeg-n5.0-latest-win64-gpl-5.0.zip.

Then put it in a fixed folder and add the bin directory to your system’s Path.

Test It Out

Open cmd, type ffmpeg -version. If you see the version number, you’re set.

Check Available Formats

Enter yt-dlp -D [URL] to see all available formats for the current video (query only, no download).

Download Command

Use yt-dlp -f [ID] [URL] to download a specific format. You can combine [ID]+[ID] to download video and audio separately; yt-dlp -f [ID]+[ID] [URL]. They’ll merge automatically after downloading.

Note: To download the best quality video and audio: -f "bv+ba/b"

Integrate aria2

Just add --external-downloader aria2c --external-downloader-args "-x 16 -k 1M" to your download command.

Download Subtitles

1
2
3
4
5
6
7
youtube-dl --write-sub [url] // This downloads an English subtitle file in VTT format and a 1080p video in MKV format.

youtube-dl --write-sub --skip-download [url] // Downloads only the VTT subtitle file, without the video.

youtube-dl --write-sub --all-subs [url] // Downloads all available subtitles (if any).

youtube-dl --write-auto-sub [url] // Downloads auto-generated subtitles (YouTube only).

Download Playlists

1
2
3
4
5
6
7
youtube-dl -f [format code] [palylist_url] // This method downloads MP4 videos at a specified quality.

youtube-dl [playlist_url] // Downloads the video playlist. Videos might be in MKV or WebM format.

youtube-dl -cit [playlist_url] // Downloads the video playlist. Videos might be in MKV or WebM format.

youtube-dl --yes-playlist [url] // If the link is a playlist, this downloads all videos in it, similar to the above, potentially in MKV or WebM format.

GUI Option

Releases · jely2002/youtube-dl-gui

References

yt-dlp GitHub Page

【Backup】youtube-dl Usage Guide - Jianshu

A Quick Dive into Windows System [Directory Variables] - Heijiuheidaodi’s Blog - CSDN Blog - username variable

This post is licensed under CC BY-NC-SA 4.0 by the author.