Codex-settings youtube-transcribe-skill
Extract subtitles/transcripts from a YouTube video URL and save as a local file. Use when you need to extract subtitles from a YouTube video.
git clone https://github.com/feiskyer/codex-settings
T=$(mktemp -d) && git clone --depth=1 https://github.com/feiskyer/codex-settings "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/youtube-transcribe-skill" ~/.claude/skills/feiskyer-codex-settings-youtube-transcribe-skill && rm -rf "$T"
skills/youtube-transcribe-skill/SKILL.mdYouTube Transcript Extraction
Extract subtitles/transcripts from a YouTube video URL and save them as a local file.
Input YouTube URL: $ARGUMENTS
Step 1: Verify URL and Get Video Information
-
Verify URL Format: Confirm the input is a valid YouTube URL (supports
oryoutube.com/watch?v=
formats).youtu.be/ -
Get Video Information:
- If
is available, preferyt-dlp
.yt-dlp --get-title "[VIDEO_URL]" - If using browser automation, extract the title from the page (via snapshot or
) for file naming.document.title
- If
Step 2: CLI Quick Extraction (Priority Attempt)
Use command-line tools to quickly extract subtitles.
-
Check Tool Availability: Execute
.which yt-dlp- If
is found, proceed to subtitle download.yt-dlp - If
is NOT found, skip immediately to Step 3.yt-dlp
- If
-
Execute Subtitle Download (Only if
is found):yt-dlp- Tip: Always add
to avoid sign-in restrictions. Default to--cookies-from-browser
.chrome - Retry Logic: If
fails with a browser error (e.g., "Could not open Chrome"), ask the user to specify their available browser (e.g.,yt-dlp
,firefox
,safari
) and retry.edge
# 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 "<Video Title>.%(ext)s" "[VIDEO_URL]" - Tip: Always add
-
Verify Results:
- Check the command exit code.
- Exit code 0 (Success): Subtitles have been saved locally, task complete.
- Exit code non-0 (Failure):
- If error is related to browser/cookies, ask user for correct browser and retry Step 2.
- If other errors (e.g., video unavailable), proceed to Step 3.
Step 3: Browser Automation (Fallback)
When the CLI method fails or
yt-dlp is missing, use browser UI automation to extract subtitles.
-
Check Tool Availability:
- Check if
tools (specificallychrome-devtools-mcp
) are available.mcp__chrome__new_page - CRITICAL CHECK: If
is NOT available ANDchrome-devtools-mcp
was NOT found in Step 2:yt-dlp- STOP execution.
- Notify the User: "Unable to proceed. Please either install
(for fast CLI extraction) OR configureyt-dlp
(for browser automation)."chrome-devtools-mcp
- Check if
-
Initialize Browser Session (If tools are available):
Call
to open the video URL.mcp__chrome__new_page
3.2 Analyze Page State
Call
mcp__chrome__take_snapshot to read the page accessibility tree.
3.3 Expand Video Description
Reason: The "Show transcript" button is usually hidden within the collapsed description area.
- Search the snapshot for a button labeled "...more", "...更多", or "Show more" (usually located in the description block below the video title).
- Call
to click that button.mcp__chrome__click
3.4 Open Transcript Panel
- Call
to get the updated UI snapshot.mcp__chrome__take_snapshot - Search for a button labeled "Show transcript", "显示转录稿", or "内容转文字".
- Call
to click that button.mcp__chrome__click
3.5 Extract Content via DOM
Reason: Directly reading the accessibility tree for long lists is slow and consumes many tokens; DOM injection is more efficient.
Call
mcp__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.
3.6 Save and Cleanup
- Use the Write tool to save the extracted text as a local file (e.g.,
).<Video Title>.txt - Call
to release resources.mcp__chrome__close_page
Output Requirements
- Save the subtitle file to the current working directory.
- Filename format:
<Video Title>.txt - File content format: Each line should be
.Timestamp Subtitle Text - Report upon completion: File path, subtitle language, total number of lines.