home / skills / feiskyer / claude-code-settings / youtube-transcribe-skill

youtube-transcribe-skill skill

/skills/youtube-transcribe-skill

This skill extracts YouTube transcripts from a video URL and saves them as a timestamped text file for easy reference.

npx playbooks add skill feiskyer/claude-code-settings --skill youtube-transcribe-skill

Review the files below or copy the command above to add this skill to your agents.

Files (1)
SKILL.md
4.9 KB
---
name: youtube-transcribe-skill
description: 'Extract subtitles/transcripts from YouTube videos. Triggers: "youtube transcript", "extract subtitles", "video captions", "视频字幕", "字幕提取", "YouTube转文字", "提取字幕".'
allowed-tools: Read, Write, Glob, Grep, Task, Bash(cat:*), Bash(ls:*), Bash(tree:*), Bash(yt-dlp:*), Bash(which:*), mcp__plugin_claude-code-settings_chrome__*
---

# 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**: 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.

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 "<Video Title>.%(ext)s" "[VIDEO_URL]"
   ```

3. **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.

1. **Check Tool Availability**:

   - Check if `chrome-devtools-mcp` tools (specifically `mcp__plugin_claude-code-settings_chrome__new_page`) are available.
   - **CRITICAL CHECK**: If `chrome-devtools-mcp` is **NOT** available AND `yt-dlp` was **NOT** found in Step 2:
     - **STOP** execution.
     - **Notify the User**: "Unable to proceed. Please either install `yt-dlp` (for fast CLI extraction) OR configure `chrome-devtools-mcp` (for browser automation)."

2. **Initialize Browser Session** (If tools are available):

   Call `mcp__plugin_claude-code-settings_chrome__new_page` to 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._

1. Search the snapshot for a button labeled **"...more"**, **"...更多"**, or **"Show more"** (usually located in the description block below the video title).
2. Call `mcp__plugin_claude-code-settings_chrome__click` to click that button.

### 3.4 Open Transcript Panel

1. Call `mcp__plugin_claude-code-settings_chrome__take_snapshot` to get the updated UI snapshot.
2. Search for a button labeled **"Show transcript"**, **"显示转录稿"**, or **"内容转文字"**.
3. Call `mcp__plugin_claude-code-settings_chrome__click` to 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:

```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

1. Use the Write tool to save the extracted text as a local file (e.g., `<Video Title>.txt`).
2. Call `mcp__plugin_claude-code-settings_chrome__close_page` to 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.

Overview

This skill extracts subtitles/transcripts from a YouTube video URL and saves them as a local text file. It prefers a fast CLI path using yt-dlp and falls back to browser automation when the CLI is unavailable. The output is a timestamped transcript file named after the video title.

How this skill works

First, it validates the YouTube URL and fetches the video title for file naming. It tries a CLI extraction with yt-dlp (using browser cookies to avoid sign-in issues). If yt-dlp is missing or fails, it uses browser automation (chrome-devtools-mcp) to open the page, reveal the transcript UI, read the transcript DOM, and save lines as "Timestamp Subtitle Text". Finally, it writes the result to the current working directory and reports file path, language, and line count.

When to use it

  • You need a quick local copy of subtitles for a YouTube video.
  • The video has auto-generated or uploaded captions you want timestamped.
  • You cannot or prefer not to stream video while extracting text.
  • YT-DLP is available for fast extraction, or chrome-devtools-mcp is configured for fallback.
  • You want a simple .txt file named after the video's title for further processing.

Best practices

  • Prefer yt-dlp with --cookies-from-browser to avoid sign-in and region blocks; specify the correct browser if default fails.
  • Validate the URL format (youtube.com/watch?v= or youtu.be/) before running extraction.
  • If CLI fails with browser errors, retry after providing the actual browser name (e.g., firefox, safari, edge).
  • When using browser automation, ensure chrome-devtools-mcp tools are configured and available before starting.
  • Sanitize the resulting filename to remove filesystem-unfriendly characters and confirm the working directory has write permission.

Example use cases

  • Download English and Chinese captions from a tutorial video for offline review and translation.
  • Generate a timestamped transcript file for podcast-style YouTube episodes to create show notes.
  • Automate subtitle extraction in a processing pipeline where text will be indexed or summarized.
  • Fallback to browser automation when yt-dlp is not installed on an environment-limited machine.
  • Quickly retrieve auto-generated subtitles for accessibility checks or quality assurance.

FAQ

What if yt-dlp is not installed?

The skill will attempt browser automation via chrome-devtools-mcp. If those tools are also unavailable it will stop and instruct you to install yt-dlp or configure chrome-devtools-mcp.

What transcript languages are extracted?

By default it requests common languages (for example zh-Hans, zh-Hant, en). Available languages depend on the video; the tool tries auto-generated and uploaded captions.

Where is the file saved and how is it named?

The file is saved in the current working directory using the video title as the filename, e.g., "<Video Title>.txt", with each line formatted as "Timestamp Subtitle Text".