--- name: youtube-transcribe-skill description: '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.' --- # YouTube 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 1. **Verify URL Format**: Confirm the input is a valid YouTube URL (supports `youtube.com/watch?v=` or `youtu.be/` formats). 2. **Get Video Information**: - If `yt-dlp` is available, prefer `yt-dlp --get-title "[VIDEO_URL]"`. - If using browser automation, extract the title from the page (via snapshot or `document.title`) for file naming. ## Step 2: CLI Quick Extraction (Priority Attempt) Use command-line tools to quickly extract subtitles. 1. **Check Tool Availability**: Execute `which yt-dlp`. - If `yt-dlp` is **found**, proceed to subtitle download. - If `yt-dlp` is **NOT found**, skip immediately to **Step 3**. 2. **Execute Subtitle Download** (Only if `yt-dlp` is found): - **Tip**: Always add `--cookies-from-browser` to avoid sign-in restrictions. Default to `chrome`. - **Retry Logic**: If `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 "