| name | video-subtitle-extractor |
| description | Extract and save subtitles from video URLs as plain .txt files. Supports Bilibili (B站) and YouTube. Use when the user provides a Bilibili or YouTube video link and asks to extract, download, or save subtitles/captions. Triggers on phrases like "提取字幕", "下载字幕", "extract subtitles", "get subtitles", or when a bilibili.com / youtube.com / youtu.be URL is provided with a subtitle-related request. |
Video Subtitle Extractor
Extract subtitles from Bilibili or YouTube videos and save as plain .txt files.
Requires: yt-dlp installed (pip install yt-dlp)
Workflow
- Run the extraction script with the video URL
- Show the user the saved file path and a preview of the content
Script
Run from this skill's directory (paths below are relative to the skill root):
python scripts/extract_subtitles.py <URL> [--output-dir <dir>] [--lang <code>]
Arguments:
<URL> — Bilibili or YouTube video URL (required)
--output-dir / -o — Where to save the .txt file (default: current directory)
--lang / -l — Subtitle language code (optional)
--cookies / -c — Path to cookies.txt file (required for login-gated videos)
Default language priority:
- Bilibili:
zh-Hans → ai-zh → zh → zh-CN
- YouTube:
zh-Hans → zh → zh-CN → en
Common examples
python scripts/extract_subtitles.py "https://www.bilibili.com/video/BV1xx411c7mD"
python scripts/extract_subtitles.py "https://youtu.be/dQw4w9WgXcQ" --output-dir "downloads"
python scripts/extract_subtitles.py "https://www.youtube.com/watch?v=abc" --lang en
Authentication (cookies)
YouTube and some Bilibili videos require login. Export cookies from your browser using the
Get cookies.txt LOCALLY
extension, then pass the file:
python scripts/extract_subtitles.py "<URL>" --cookies "path/to/cookies.txt"
Store the cookies file in the video-subtitle-extractor/cookies/ directory (e.g. video-subtitle-extractor/cookies/www.youtube.com_cookies.txt) and it will be automatically detected by the script.
Note: --cookies-from-browser chrome fails when Chrome is running (database locked).
--cookies-from-browser edge fails on Windows due to DPAPI encryption. Use a cookies.txt file instead.
Troubleshooting
No subtitles found — List available languages first:
yt-dlp --list-subs "<URL>"
Then re-run with --lang <code> from the list.
HTTP 429 (Too Many Requests) — YouTube rate-limiting. Wait a moment and retry.
Bilibili "subtitles only available when logged in" — Export Bilibili cookies and pass with --cookies.