youtube-downloader
Download YouTube videos and HLS streams (m3u8) from platforms like Mux, Vimeo, etc. using yt-dlp and ffmpeg. Use this skill when users request downloading videos, extracting audio, handling protected streams with authentication headers, or troubleshooting download issues like nsig extraction failures, 403 errors, or cookie extraction problems.
1How It Works & Mechanism
Core implementation relies on yt-dlp/ffmpeg CLI wrappers: SKILL.md guides the agent to use yt-dlp for downloading and ffmpeg for HLS processing/transcoding, bundled with a Python wrapper script download_video.py to programmatically automate the download process.
Enable reliable video and audio downloads from YouTube and HLS streaming platforms (Mux, Vimeo, etc.) using yt-dlp and ffmpeg.
Automated orchestration of PO Token providers (crucial for high quality): Automatically runs pip install to add plugins into yt-dlp's Python environment. It prioritizes launching the brainicism/bgutil-ytdlp-pot-provider Docker container (-p 4416:4416) with health checks pinging 127.0.0.1:4416; if Docker is missing or fails, it falls back to pip install yt-dlp-getpot-wpc to run the browser-based WPC approach.
run_cmd = ["docker", "run", "-d", "--name", name] ... "-p", "4416:4416", *env_args, "--init", "brainicism/bgutil-ytdlp-pot-provider"
Cookie authentication pipeline: Upon authorization, passes the browser cookie session to yt-dlp (--cookies-from-browser chrome/firefox or a --cookies file), forcing the youtube player client to web_safari when cookies are present.
cmd.extend(["--cookies-from-browser", cookies_from_browser]) ... elif cookies_file: cmd.extend(["--cookies", cookies_file])
UX orchestration designed for non-technical users: Fully delegated to the agent—first fetches metadata via --info (falling back to YouTube oEmbed on failure) to verify video identity, downloads according to defaults or selections, and finally reports the file path, size, and resolution, requiring zero terminal commands from the user throughout.
Assume the user is non-technical. Do not ask them to run commands. Execute everything yourself and report progress in plain language.
Error-driven retry chain: Maps common yt-dlp failures (403 / nsig / 'Only images are available' / SSL EOF) to strategies—falling back to non-m3u8 progressive formats on 403; restarting the container or switching to WPC on PO token failure; switching to the web_safari client on cookie+403 errors.
return "http error 403" in text or "403: forbidden" in text or "fragment 1 not found" in text
Proxy-aware design (tailored for Mainland China network environments): Reads ambient proxies ALL_PROXY/HTTPS_PROXY/HTTP_PROXY and passes them to yt-dlp, pip, and Docker containers, rewriting localhost proxies to host.docker.internal; pip uses a hardcoded Tsinghua mirror pypi.tuna.tsinghua.edu.cn.
PYPI_MIRROR = "https://pypi.tuna.tsinghua.edu.cn/simple"
2Core Capabilities
3External Dependencies
| Kind | Dependency / Endpoint |
|---|---|
| cli | yt-dlp |
| cli | ffmpeg / ffprobe |
| cli | docker |
| cli | python / pip(yt-dlp 解释器) |
| network | youtube.com(下载取流 + oEmbed 元数据) |
| network | 清华 PyPI 镜像(硬编码装插件源) |
| network | Docker Hub 镜像 brainicism/bgutil-ytdlp-pot-provider(第三方 PO token 服务,拉取即执行) |
| network | 本机 PO provider 探活端点 |
| network | 用户提供任意视频/HLS URL(m3u8 可指向任意第三方 CDN,如 Mux/Vimeo) |
| package | bgutil-ytdlp-pot-provider(pip 插件) |
| package | yt-dlp-getpot-wpc(pip 浏览器版 token 提供者,会启动真实浏览器) |
4Recommended Governance & Evidence
- 本地凭据 / 浏览器配置: Reading user login cookies/sessions/keyrings: Browser cookies: --cookies-from-browser chrome/firefox → yt-dlp reads browser cookie stores (script
- scripts/: Executing local scripts or commands: External CLIs: yt-dlp (downloading/metadata/format listing), ffprobe/ffmpeg, docker run/start/rm/info, pip inst
- scripts/ 或 SKILL.md: Declares dynamic installation of external language package dependencies
- 网络端点: Declares external network access: youtube.com: yt-dlp metadata/stream fetching; oEmbed fallback via urlopen https://www.youtube.com/oembed (
- 本地工作目录: File I/O and artifact output: Download output: recursive mkdir for output_dir + writing video/audio/subtitle files per -o templates (templates support absolute paths and yt-dlp %()s syntax, user configurable
5Second-Pass Verification
- [ok] yt-dlp 调用真实存在(下载/-F/-o/-f/--dump-json) — 脚本 cmd = ["yt-dlp"] 起步(738 行),全部参数列表化
- [ok] ffmpeg/ffprobe 调用 — SKILL.md 多处 ffmpeg 命令 + 脚本 get_video_resolution 中 which ffprobe 实测存在
- [ok] cookie 读取路径(--cookies-from-browser / --cookies) — 773-776 行真实拼接;注意解密主体是 yt-dlp 而非脚本,脚本无 cookie 解析代码
- [ok] cookie 日志脱敏 filter_cookie_lines — 仅过滤含 'extracting cookies' 或 'extracted'+'cookies' 的行,非完整脱敏(其他含 cookie 内容行仍会输出)——实现与声称基本一致,范围略窄
- [ok] oEmbed 兜底网络端点 — 660-663 行 urlopen youtube.com/oembed,URL 经 quote 编码,无注入面
- [ok] PO token:docker bgutil 容器 + 4416 ping 探活 — 437-446/553-563 行 docker run brainicism 镜像,255-257 行 ping;容器内实现本 repo 无法审计 → 供应链项如实标注
- [ok] WPC 浏览器回退自动拉起 Chrome — 脚本只传 --extractor-args youtubepot-wpc:browser_path=…(249-252 行)+ find_chrome_path;真实浏览器启动由第三方插件 yt-dlp-getpot-wpc 完成,脚本侧证据到传参为止
- [ok] pip 自动安装插件(清华镜像) — 350、377 行安装命令真实存在,PYPI_MIRROR 38 行硬编码
6Verdict & Scenarios
6c6c403e7e905b4e…