跳到正文
yt-dlp

yt-dlp 速查表

值得记住的 yt-dlp 命令:选画质、提取 MP3、播放列表、字幕、cookies,以及真正会遇到的报错怎么解决。

这篇文章还没有翻译,所以以英文显示。界面部分仍是你的语言。

Basic downloads

With no options at all, yt-dlp picks the best combination it can merge and names the file after the title. This is the right command surprisingly often.

yt-dlp URL

Before downloading something large, it is worth seeing what is actually on offer. This prints the format table and exits without downloading anything.

yt-dlp -F URL

The left column of that table is the format id, which you can then request directly. Two ids joined with + means "download both and merge them".

yt-dlp -f 137+140 URL

Quality and format selection

Hard-coded format ids break as soon as a site changes its encoding ladder. A selector expression is the durable version: ask for the properties you want and let yt-dlp find the best match.

yt-dlp -f "bv*[height<=1080]+ba/b[height<=1080]" URL

Read it as: the best video stream no taller than 1080 plus the best audio, and if that pair does not exist, the best single file no taller than 1080. That fallback after the slash is what stops the command failing on sites that publish only progressive streams.

Merging two streams produces a container yt-dlp has to choose. MP4 plays everywhere; MKV accepts anything you throw at it, which matters once subtitles and chapters are involved.

yt-dlp -f "bv*+ba" --merge-output-format mp4 URL

To express a preference rather than a hard limit, sort instead of filter. This prefers 1080p and MP4 but still downloads something when neither is available.

yt-dlp -S "res:1080,ext:mp4" URL

Audio and MP3

Extracting audio needs ffmpeg — this is the single most common reason the command below fails on a fresh install.

yt-dlp -x --audio-format mp3 URL

Adding cover art and tags takes two more flags and makes the result usable in a music library rather than a folder of anonymous files.

yt-dlp -x --audio-format mp3 --audio-quality 0 --embed-thumbnail --embed-metadata URL

--audio-quality 0 is variable bitrate at the best setting, not "zero quality". If you need a fixed bitrate, give it one: --audio-quality 320K.

When the source is already AAC or Opus, converting to MP3 re-encodes and loses quality for nothing. Keeping the original is both faster and better.

yt-dlp -x --audio-format best URL

Subtitles

Embedded subtitles travel with the file; separate .srt files are easier to edit and to feed to something else.

yt-dlp --embed-subs --sub-langs en URL
yt-dlp --write-subs --sub-langs en,vi --convert-subs srt URL

Machine-generated captions are a separate switch. Without it, a video with no human subtitles produces nothing at all and no error.

yt-dlp --write-auto-subs --sub-langs en --convert-subs srt --skip-download URL

Playlists and channels

A YouTube URL often belongs to both a video and a playlist, and yt-dlp has to guess which you meant. Say so explicitly.

yt-dlp --no-playlist URL
yt-dlp --yes-playlist URL

For anything long, the archive file matters more than any other option here: it records what has been downloaded so a re-run picks up where it stopped instead of starting over.

yt-dlp --yes-playlist -i \
  --download-archive archive.txt \
  -o "%(playlist_index)02d - %(title)s.%(ext)s" \
  URL

Combined with -i, one region-locked or deleted video no longer aborts the other two hundred. To grab a slice rather than everything, -I takes ranges and lists: -I 1:10, -I "1,3,7-10".

Clips, chapters and sponsors

You can download part of a video instead of all of it. The leading asterisk marks a timestamp rather than a chapter name, and the quotes are mandatory — bash expands a bare * against your filenames.

yt-dlp --download-sections "*00:01:30-00:03:00" URL

SponsorBlock uses community-submitted markers to cut segments out entirely, or to leave them in as chapters you can skip yourself.

yt-dlp --sponsorblock-remove default URL
yt-dlp --sponsorblock-mark all --embed-chapters URL

Logins, cookies and bot checks

Private, age-restricted and members-only content needs your session. Reading it straight from the browser is the least error-prone route.

yt-dlp --cookies-from-browser chrome URL
yt-dlp --cookies-from-browser "firefox:Profile 1" URL

Close the browser first: Chrome and Edge hold a lock on the cookie database while running, and the resulting error message does not say so.

When a site starts returning 403 or asking you to confirm you are not a bot, making the request look like a real browser usually clears it.

yt-dlp --impersonate chrome URL

File names and folders

The output template controls both. A slash creates a directory, so one template can lay out an entire archive.

yt-dlp -o "%(uploader)s/%(upload_date>%Y-%m-%d)s - %(title)s.%(ext)s" URL

Titles routinely contain characters some filesystems reject. --restrict-filenames reduces everything to plain ASCII, which is worth it for anything that will be moved between machines.

In a Windows .bat file every % must be doubled — %%(title)s — or the batch interpreter eats the template before yt-dlp sees it. The generator does this for you when you download a .bat.

Errors you will actually hit

ffmpeg not found

Anything that merges, converts, embeds or cuts needs ffmpeg on your PATH. Install it, then confirm with ffmpeg -version.

Sign in to confirm you are not a bot

Try --impersonate chrome first, then --cookies-from-browser. If both fail, update yt-dlp — this particular check changes often and the fix usually arrives in a release within days.

Unable to extract player response

Almost always an out-of-date yt-dlp. Update it before changing anything else: yt-dlp -U, or your package manager if you installed it that way.

Requested format is not available

Your selector matched nothing. Run -F to see what exists, and prefer a sort (-S) over a hard filter so there is always a fallback.

HTTP Error 403

The URL was signed for a different session or region. Re-run with fresh cookies, add --impersonate chrome, or try --geo-bypass.

Keeping yt-dlp current

More reported bugs are fixed by updating than by any flag. If you installed the standalone binary:

yt-dlp -U

Installed through a package manager, update it the same way you installed it — -U will refuse, and it is right to.

常见问题

"Sign in to confirm you are not a bot" 怎么解决?
先试 --impersonate chrome,再试 --cookies-from-browser chrome 用你的登录会话。都不行就更新 yt-dlp —— 这个验证经常变,修复通常几天内就会发布。
"Unable to extract player response" 是什么意思?
网站改了什么,而你的 yt-dlp 早于对应的修复。先更新,再考虑改别的;这个报错几乎从来不是靠某个 flag 解决的。
它提示 ffmpeg not found。
合并、转换、内嵌和裁剪都需要 PATH 里有 ffmpeg。装好后用 ffmpeg -version 确认。
yt-dlp 该多久更新一次?
任何东西开始失效时就更新,此外每隔几周更新一次。网站一直在变,而大多数损坏都会在项目那边很快修好。
yt-dlp 和 youtube-dl 有什么区别?
yt-dlp 是仍在维护的分支,extractor 和功能都多得多 —— SponsorBlock、下载片段、浏览器伪装、并发 fragment。它保留了 youtube-dl 的选项名,所以大多数简单命令两边都能用。