Extract subtitles/transcripts from a YouTube video URL and save them as a local file.
Input YouTube URL: $ARGUMENTS
youtube.com/watch?v= or youtu.be/ formats).Use command-line tools to quickly extract subtitles.
Execute which yt-dlp.
yt-dlp is found, proceed to subtitle download.yt-dlp is NOT found, skip immediately to Step 3.yt-dlp is found):--cookies-from-browser to avoid sign-in restrictions. Default to chrome.yt-dlp fails with a browser error (e.g., "Could not open Chrome"), ask the user to specify their available browser (e.g., firefox, safari, edge) and retry.```bash
# Get the title first (try chrome first)
yt-dlp --cookies-from-browser=chrome --get-title "[VIDEO_URL]"
# Download subtitles
yt-dlp --cookies-from-browser=chrome --write-auto-sub --write-sub --sub-lang zh-Hans,zh-Hant,en --skip-download --output "
```
When the CLI method fails or yt-dlp is missing, use browser UI automation to extract subtitles.
chrome-devtools-mcp tools (specifically mcp__plugin_claude-code-settings_chrome__new_page) are available.chrome-devtools-mcp is NOT available AND yt-dlp was NOT found in Step 2:yt-dlp (for fast CLI extraction) OR configure chrome-devtools-mcp (for browser automation)." Call mcp__plugin_claude-code-settings_chrome__new_page to open the video URL.
Call mcp__plugin_claude-code-settings_chrome__take_snapshot to read the page accessibility tree.
_Reason: The "Show transcript" button is usually hidden within the collapsed description area._
mcp__plugin_claude-code-settings_chrome__click to click that button.mcp__plugin_claude-code-settings_chrome__take_snapshot to get the updated UI snapshot.mcp__plugin_claude-code-settings_chrome__click to click that button._Reason: Directly reading the accessibility tree for long lists is slow and consumes many tokens; DOM injection is more efficient._
Call mcp__plugin_claude-code-settings_chrome__evaluate_script to execute the following JavaScript:
() => {
// Select all transcript segment containers
const segments = document.querySelectorAll("ytd-transcript-segment-renderer");
if (!segments.length) return "BUFFERING"; // Retry if empty
// Iterate and format as "timestamp text"
return Array.from(segments)
.map((seg) => {
const time = seg.querySelector(".segment-timestamp")?.innerText.trim();
const text = seg.querySelector(".segment-text")?.innerText.trim();
return `${time} ${text}`;
})
.join("\n");
};
If it returns "BUFFERING", wait a few seconds and retry.
).mcp__plugin_claude-code-settings_chrome__close_page to release resources.Timestamp Subtitle Text.共 1 个版本