逛GitHub的时候看到一款视频下载工具,挺好用的,记录下使用过程。
教程环境:
- win10
- pythin 3
- 谷歌浏览器
- 链接 https://www.youtube.com/watch?v=0eVpXgGuTHg 为演示链接,使用可替换为自己需要下载的视频的链接
1、资源下载
两款工具下载完成后,将yt-dlp.exe拖进FFMP的bin目录下,然后配置bin目录的环境变量。
另:已经单独整理文件备份可直接下载:
提取码: top0
2、应用使用
1、火狐浏览器使用
先新建个文件夹用于保存视频,并在文件夹中打开cmd终端:
国内火狐浏览器,没用cookie加密限制,可以直接在cmd终端中使用:
yt-dlp --cookies-from-browser firefox https://www.youtube.com/watch?v=0eVpXgGuTHg
如果链接太长报错,可以使用**-o**命令截取一定长度的字符串:
yt-dlp -o '%(title).200B.%(ext)s' 'https://www.youtube.com/watch?v=0eVpXgGuTHg'
这样视频就可以下载到打开cmd命令的文件夹了。
2、Edge、谷歌浏览器使用
Edge、谷歌浏览器是有cookie加密的,可以借助差价将浏览器保存的cookie下载下来,放进需要保存视频的文件夹中辅助使用。
插件地址 以**.txt**格式的保存。(即上图中的cookies.txt文本)
在cmd终端中使用:
yt-dlp --cookies cookies.txt https://www.youtube.com/watch?v=0eVpXgGuTHg
3、python调用
先安装依赖:yt_dlp
pip install yt_dlp
然后自定义修改程序:
from yt_dlp import YoutubeDL
URLS = ['https://www.youtube.com/watch?v=0eVpXgGuTHg',
'https://www.youtube.com/watch?v=6YyC6sc1YdM',
'https://www.bilibili.com/video/BV1RND5YYE1S/?spm_id_from=333.788.recommend_more_video.18'
]
with YoutubeDL() as ydl:
ydl.download(URLS)
文档
yt-dlp [OPTIONS] [--] URL [URL...]
-h, --help Print this help text and exit
--version Print program version and exit
-U, --update Update this program to the latest version
--no-update Do not check for updates (default)
--update-to [CHANNEL]@[TAG] Upgrade/downgrade to a specific version.
CHANNEL can be a repository as well. CHANNEL
and TAG default to "stable" and "latest"
respectively if omitted; See "UPDATE" for
details. Supported channels: stable,
nightly, master
-i, --ignore-errors Ignore download and postprocessing errors.
The download will be considered successful
even if the postprocessing fails
--no-abort-on-error Continue with next video on download errors;
e.g. to skip unavailable videos in a
playlist (default)
--abort-on-error Abort downloading of further videos if an
error occurs (Alias: --no-ignore-errors)
--dump-user-agent Display the current user-agent and exit
--list-extractors List all supported extractors and exit
--extractor-descriptions Output descriptions of all supported
extractors and exit
--use-extractors NAMES Extractor names to use separated by commas.
You can also use regexes, "all", "default"
and "end" (end URL matching); e.g. --ies
"holodex.*,end,youtube". Prefix the name
with a "-" to exclude it, e.g. --ies
default,-generic. Use --list-extractors for
a list of extractor names. (Alias: --ies)
--default-search PREFIX Use this prefix for unqualified URLs. E.g.
"gvsearch2:python" downloads two videos from
google videos for the search term "python".
Use the value "auto" to let yt-dlp guess
("auto_warning" to emit a warning when
guessing). "error" just throws an error. The
default value "fixup_error" repairs broken
URLs, but emits an error if this is not
possible instead of searching
--ignore-config Don't load any more configuration files
except those given to --config-locations.
For backward compatibility, if this option
is found inside the system configuration
file, the user configuration is not loaded.
(Alias: --no-config)
--no-config-locations Do not load any custom configuration files
(default). When given inside a configuration
file, ignore all previous --config-locations
defined in the current file
--config-locations PATH Location of the main configuration file;
either the path to the config or its
containing directory ("-" for stdin). Can be
used multiple times and inside other
configuration files
--plugin-dirs PATH Path to an additional directory to search
for plugins. This option can be used
multiple times to add multiple directories.
Note that this currently only works for
extractor plugins; postprocessor plugins can
only be loaded from the default plugin
directories
--flat-playlist Do not extract the videos of a playlist,
only list them
--no-flat-playlist Fully extract the videos of a playlist
(default)
--live-from-start Download livestreams from the start.
Currently only supported for YouTube
(Experimental)
--no-live-from-start Download livestreams from the current time
(default)
--wait-for-video MIN[-MAX] Wait for scheduled streams to become
available. Pass the minimum number of
seconds (or range) to wait between retries
--no-wait-for-video Do not wait for scheduled streams (default)
--mark-watched Mark videos watched (even with --simulate)
--no-mark-watched Do not mark videos watched (default)
--color [STREAM:]POLICY Whether to emit color codes in output,
optionally prefixed by the STREAM (stdout or
stderr) to apply the setting to. Can be one
of "always", "auto" (default), "never", or
"no_color" (use non color terminal
sequences). Use "auto-tty" or "no_color-tty"
to decide based on terminal support only.
Can be used multiple times
--compat-options OPTS Options that can help keep compatibility
with youtube-dl or youtube-dlc
configurations by reverting some of the
changes made in yt-dlp. See "Differences in
default behavior" for details
--alias ALIASES OPTIONS Create aliases for an option string. Unless
an alias starts with a dash "-", it is
prefixed with "--". Arguments are parsed
according to the Python string formatting
mini-language. E.g. --alias get-audio,-X
"-S=aext:{0},abr -x --audio-format {0}"
creates options "--get-audio" and "-X" that
takes an argument (ARG0) and expands to
"-S=aext:ARG0,abr -x --audio-format ARG0".
All defined aliases are listed in the --help
output. Alias options can trigger more
aliases; so be careful to avoid defining
recursive options. As a safety measure, each
alias may be triggered a maximum of 100
times. This option can be used multiple times