yt-dlp
安装和升级
使用 Windows 操作系统的用户:
winget install yt-dlp
winget upgrade yt-dlp20250414 升级尝试:
yt-dlp -U
Current version: stable@2025.01.26 from yt-dlp/yt-dlp
Latest version: stable@2025.03.31 from yt-dlp/yt-dlp
Current Build Hash: 423eec9b60ab7910d97eb74cdb5daea90128850752d4aad6ccabaf8648d6387c
Updating to stable@2025.03.31 from yt-dlp/yt-dlp ...
Updated yt-dlp to stable@2025.03.31 from yt-dlp/yt-dlp查看 yt-dlp 在 Windows 系统上的安装路径:
whereis yt-dlp
C:\Users\Lenovo\AppData\Local\Microsoft\WinGet\Packages\yt-dlp.yt-dlp_Microsoft.Winget.Source_8wekyb3d8bbwe\yt-dlp.exe使用 macOS 的用户:
brew install yt-dlp基本使用
下载视频
yt-dlp ["视频链接"]下载音频
如果只想下载音频,可以使用 -x 参数:
yt-dlp -x [视频链接]如果有音频文件,会直接下载;如果没有,则下载视频,然后通过 FFmpeg 转换成音频文件,最后自动删除视频文件。
下载字幕
先查看视频有哪些字幕:
yt-dlp --list-subs [视频链接]下载特定语言的字幕(不下载视频):
yt-dlp --write-subs --sub-langs [语言代码] --skip-download [视频链接]指定下载目录
下载至家目录下的 YouTube 文件夹:
yt-dlp -o ~/YouTube/%(title)s.%(ext)s配置文件
每次下载视频时,都需要重复地输入命令以及相应的参数会比较浪费时间,所以我们根据官方文档来创建一份配置文件。
在 Windows 系统上,执照以下路径创建配置文件:
C:\Users\user_name\AppData\Roaming\yt-dlp\config在 macOS 系统上,按照以下路径创建配置文件:
~/.config/yt-dlp/configUser configuration
${XDG_CONFIG_HOME}/yt-dlp.conf${XDG_CONFIG_HOME}/yt-dlp/config(recommended on Linux/macOS)${XDG_CONFIG_HOME}/yt-dlp/config.txt${APPDATA}/yt-dlp.conf${APPDATA}/yt-dlp/config(recommended on Windows)${APPDATA}/yt-dlp/config.txt~/yt-dlp.conf~/yt-dlp.conf.txt~/.yt-dlp/config~/.yt-dlp/config.txt
使用 PowerShell 时,运行下面命令可以列出当前系统的环境变量:
Get-ChildItem env:*Notes about environment varialbes
- Environment variables are normally specified as
${VARIABLE}/$VARIABLEon UNIX and%VARIABLE%on Windows; but is always shown as${VARIABLE}in this documentation - yt-dlp also allows using UNIX-style variables on Windows for path-like options; e.g.
--output,--config-location - If unset,
${XDG_CONFIG_HOME}defaults to~/.configand${XDG_CACHE_HOME}to~/.cache - On Windows,
~points to${HOME}if present; or,${USERPROFILE}or${HOMEDRIVE}${HOMEPATH}otherwise - On Windows,
${USERPROFILE}generally points toC:\Users\<user_name>and${APPDATA}to${USERPROFILE}\AppData\Roaming
Tips for Using Configuration Files
- Use configuration files for options you use frequently
- Keep sensitive information (like passwords) in a separate, secure configuration file
- Use
--verboseto see which configuration files are being read - Consider having different configuration files for different purposes (e.g., one for audio extraction, another for video downloading)
TO DO LIST
- 继续完善视频下载的配置文件
- 研究参数
-o的使用方法 - 安装 FFmpeg 依赖,解决高清下载
I have switched to Arch Linux. 2026-06-18
The Basic Command
To download the first 8 videos from any YouTube playlist, use this command:
yt-dlp --playlist-items 1-8 "https://www.youtube.com/playlist?list=PLCO-MGSsHcdArXIfeOGoUwjH0oz8vMr8M"Other Useful Options
Here are some variations you might find helpful:
Download videos 5 through 12 (8 videos total):
bashyt-dlp --playlist-items 5-12 "https://www.youtube.com/playlist?list=PLCO-MGSsHcdArXIfeOGoUwjH0oz8vMr8M"Download specific videos (e.g., 1st, 3rd, and 5th):
bashyt-dlp --playlist-items 1,3,5 "https://www.youtube.com/playlist?list=PLCO-MGSsHcdArXIfeOGoUwjH0oz8vMr8M"Download the best quality video + audio, and save to a specific folder:
bashyt-dlp -f bestvideo+bestaudio --merge-output-format mp4 -o "~/Downloads/%(title)s.%(ext)s" --playlist-items 1-8 "https://www.youtube.com/playlist?list=PLCO-MGSsHcdArXIfeOGoUwjH0oz8vMr8M"
What Each Part Does
--playlist-items 1-8: Tells yt-dlp to only download the first 8 videos from the playlist.-f bestvideo+bestaudio: Downloads the best quality video and audio streams separately.--merge-output-format mp4: Combines them into a single MP4 file.-o "~/Downloads/%(title)s.%(ext)s": Saves the files to your Downloads folder with the video title as the filename.
A Quick Tip
If you want to see what videos will be downloaded without actually downloading them, you can preview first:
╭╴ alowree on Arch Linux at ~/OneDrive/50.marketing_communications/08.YouTube took 37s
╰─❯ yt-dlp --playlist-items 1-8 --flat-playlist "https://www.youtube.com/playlist?list=PLCO-MGSsHcdArXIfeOGoUwjH0oz8vMr8M"
[youtube:tab] Extracting URL: https://www.youtube.com/playlist?list=PLCO-MGSsHcdArXIfeOGoUwjH0oz8vMr8M
[youtube:tab] PLCO-MGSsHcdArXIfeOGoUwjH0oz8vMr8M: Downloading webpage
[youtube:tab] PLCO-MGSsHcdArXIfeOGoUwjH0oz8vMr8M: Redownloading playlist API JSON with unavailable videos
[download] Downloading playlist: Typst
[youtube:tab] Playlist Typst: Downloading 8 items of 8
[download] Downloading item 1 of 8
[download] Downloading item 2 of 8
[download] Downloading item 3 of 8
[download] Downloading item 4 of 8
[download] Downloading item 5 of 8
[download] Downloading item 6 of 8
[download] Downloading item 7 of 8
[download] Downloading item 8 of 8
[download] Finished downloading playlist: TypstThis will show you the titles and URLs of the first 8 videos.
Just run one of the commands above with your playlist URL, and it should download exactly the 8 videos you want.
