Skip to content

视频下载 yt-dlp

安装和升级

使用 Windows 操作系统的用户:

sh
winget install yt-dlp
winget upgrade yt-dlp

20250414 升级尝试:

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

基本使用

下载视频

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

User 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

Notes about environment varialbes

  • Environment variables are normally specified as ${VARIABLE}/$VARIABLE on 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 ~/.config and ${XDG_CACHE_HOME} to ~/.cache
  • On Windows, ~ points to ${HOME} if present; or, ${USERPROFILE} or ${HOMEDRIVE}${HOMEPATH} otherwise
  • On Windows, ${USERPROFILE} generally points to C:\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 --verbose to 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` 的使用方法-o 的使用方法
  • 安装 FFmpeg 依赖,解决高清下载
最近更新