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
# Bilibili (auto-detect language)
python scripts/extract_subtitles.py "https://www.bilibili.com/video/BV1xx411c7mD"
# YouTube, save to Downloads
python scripts/extract_subtitles.py "https://youtu.be/dQw4w9WgXcQ" --output-dir "downloads"
# Force English
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 chromefails when Chrome is running (database locked).--cookies-from-browser edgefails 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.