youtube-transcribe-skill
npx machina-cli add skill feiskyer/claude-code-settings/youtube-transcribe-skill --openclawYouTube 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
youtube.com/watch?v=oryoutu.be/formats). -
Get Video Information: Use WebFetch or firecrawl to fetch the page and extract the video title for subsequent file naming.
Step 2: CLI Quick Extraction (Priority Attempt)
Use command-line tools to quickly extract subtitles.
-
Check Tool Availability: Execute
which yt-dlp.- If
yt-dlpis found, proceed to subtitle download. - If
yt-dlpis NOT found, skip immediately to Step 3.
- If
-
Execute Subtitle Download (Only if
yt-dlpis found):- Tip: Always add
--cookies-from-browserto avoid sign-in restrictions. Default tochrome. - Retry Logic: If
yt-dlpfails 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.
# 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
chrome-devtools-mcptools (specificallymcp__plugin_claude-code-settings_chrome__new_page) are available. - CRITICAL CHECK: If
chrome-devtools-mcpis NOT available ANDyt-dlpwas NOT found in Step 2:- STOP execution.
- Notify the User: "Unable to proceed. Please either install
yt-dlp(for fast CLI extraction) OR configurechrome-devtools-mcp(for browser automation)."
- Check if
-
Initialize Browser Session (If tools are available):
Call
mcp__plugin_claude-code-settings_chrome__new_pageto open the video URL.
3.2 Analyze Page State
Call mcp__plugin_claude-code-settings_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
mcp__plugin_claude-code-settings_chrome__clickto click that button.
3.4 Open Transcript Panel
- Call
mcp__plugin_claude-code-settings_chrome__take_snapshotto get the updated UI snapshot. - Search for a button labeled "Show transcript", "显示转录稿", or "内容转文字".
- Call
mcp__plugin_claude-code-settings_chrome__clickto click that button.
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__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.
3.6 Save and Cleanup
- Use the Write tool to save the extracted text as a local file (e.g.,
<Video Title>.txt). - Call
mcp__plugin_claude-code-settings_chrome__close_pageto release resources.
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.
Source
git clone https://github.com/feiskyer/claude-code-settings/blob/main/skills/youtube-transcribe-skill/SKILL.mdView on GitHub Overview
Extract subtitles/transcripts from a YouTube video URL and save them as a local file. It first attempts a fast CLI route with yt-dlp using cookies-from-browser to bypass sign-in, then falls back to browser automation if needed. The workflow supports multiple languages such as zh-Hans, zh-Hant, and en.
How This Skill Works
The skill validates the YouTube URL and retrieves the video title for naming. It then tries to download subtitles with yt-dlp if available, using --cookies-from-browser and --sub-lang options; if the CLI path fails or is unavailable, it uses chrome-devtools-mcp based browser automation to open the video, reveal the transcript panel, and extract text from the DOM.
When to Use It
- You want a quick local copy of subtitles for a YouTube video via a CLI workflow.
- yt-dlp is installed and accessible and you need auto-sub or standard subtitles.
- The video has sign-in/cookie restrictions and requires browser cookies to fetch subtitles.
- You need subtitles in zh-Hans, zh-Hant, and en for multilingual study.
- CLI download fails or is blocked and you need a browser-automation fallback to extract transcripts.
Quick Start
- Step 1: Verify the YouTube URL format and fetch the video title for naming.
- Step 2: If yt-dlp is available, run the subtitle download with --cookies-from-browser (default chrome) and --write-auto-sub --write-sub --sub-lang zh-Hans,zh-Hant,en.
- Step 3: If CLI fails or is unavailable, switch to browser automation to open the video, reveal the transcript panel, and extract text via DOM.
Best Practices
- Verify the input URL is a valid YouTube URL (youtube.com/watch?v= or youtu.be).
- Prefer the CLI path first with yt-dlp if available for speed.
- Always pass --cookies-from-browser (default chrome) and include --write-auto-sub, --write-sub, and --sub-lang zh-Hans,zh-Hant,en.
- Check the exit code after the CLI step and retry with the correct browser if cookies cause issues.
- If the CLI path is unavailable or fails, ensure chrome-devtools-mcp tools exist before falling back to browser automation.
Example Use Cases
- Download Chinese subtitles for a cooking tutorial for offline study.
- Archive transcripts from a news video for research analysis.
- Create bilingual subtitles (Chinese and English) for a language-learning video.
- Export subtitles for an NLP dataset from an educational video.
- Save lecture transcripts for quick offline revision notes.