视频下载 yt-dlp
安装和升级
使用 Windows 操作系统的用户:
sh
winget install yt-dlp
winget upgrade yt-dlp20250414 升级尝试:
sh
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 系统上的安装路径:
sh
whereis yt-dlp
C:\Users\Lenovo\AppData\Local\Microsoft\WinGet\Packages\yt-dlp.yt-dlp_Microsoft.Winget.Source_8wekyb3d8bbwe\yt-dlp.exe使用 macOS 的用户:
sh
brew install yt-dlp基本使用
下载视频
sh
yt-dlp ["视频链接"]下载音频
如果只想下载音频,可以使用 -x 参数:
sh
yt-dlp -x [视频链接]如果有音频文件,会直接下载;如果没有,则下载视频,然后通过 FFmpeg 转换成音频文件,最后自动删除视频文件。
下载字幕
先查看视频有哪些字幕:
sh
yt-dlp --list-subs [视频链接]下载特定语言的字幕(不下载视频):
sh
yt-dlp --write-subs --sub-langs [语言代码] --skip-download [视频链接]指定下载目录
下载至家目录下的 YouTube 文件夹:
sh
yt-dlp -o ~/YouTube/%(title)s.%(ext)s配置文件
每次下载视频时,都需要重复地输入命令以及相应的参数会比较浪费时间,所以我们根据官方文档来创建一份配置文件。
在 Windows 系统上,执照以下路径创建配置文件:
sh
C:\Users\user_name\AppData\Roaming\yt-dlp\config在 macOS 系统上,按照以下路径创建配置文件:
sh
~/.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 时,运行下面命令可以列出当前系统的环境变量:
sh
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 依赖,解决高清下载