youtube-transcript-cn

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

YouTube 字幕提取技能

YouTube Subtitle Extraction Skill

从 YouTube 视频提取字幕,输出中文文字稿。
Extract subtitles from YouTube videos and output Chinese transcripts.

快速使用

Quick Start

bash
python3 scripts/get_transcript.py "https://www.youtube.com/watch?v=VIDEO_ID"
bash
python3 scripts/get_transcript.py "https://www.youtube.com/watch?v=VIDEO_ID"

工作流程

Workflow

  1. 获取视频链接:从用户消息中提取 YouTube URL
  2. 运行脚本:执行
    scripts/get_transcript.py
    提取字幕
  3. 处理输出
    • 如果字幕是中文:直接输出
    • 如果字幕是英文:翻译为中文后输出
  4. 保存结果:根据用户需求保存为 Markdown 文件
  1. Get video link: Extract YouTube URL from user messages
  2. Run script: Execute
    scripts/get_transcript.py
    to extract subtitles
  3. Process output:
    • If subtitles are in Chinese: Output directly
    • If subtitles are in English: Translate to Chinese before output
  4. Save results: Save as Markdown file per user requirements

脚本参数

Script Parameters

参数说明默认值
url
YouTube 视频链接或 ID必填
-f, --format
输出格式:
text
,
markdown
,
json
markdown
-t, --timestamps
包含时间戳
-l, --lang
首选语言(逗号分隔)
zh,en
-o, --output
输出文件路径stdout
ParameterDescriptionDefault Value
url
YouTube video link or IDRequired
-f, --format
Output format:
text
,
markdown
,
json
markdown
-t, --timestamps
Include timestampsNo
-l, --lang
Preferred languages (comma separated)
zh,en
-o, --output
Output file pathstdout

使用示例

Usage Examples

基本用法

Basic Usage

bash
python3 scripts/get_transcript.py "https://www.youtube.com/watch?v=dQw4w9WgXcQ"
bash
python3 scripts/get_transcript.py "https://www.youtube.com/watch?v=dQw4w9WgXcQ"

带时间戳输出

Output with Timestamps

bash
python3 scripts/get_transcript.py -t "https://youtu.be/VIDEO_ID"
bash
python3 scripts/get_transcript.py -t "https://youtu.be/VIDEO_ID"

保存到文件

Save to File

bash
python3 scripts/get_transcript.py -o output.md "https://www.youtube.com/watch?v=VIDEO_ID"
bash
python3 scripts/get_transcript.py -o output.md "https://www.youtube.com/watch?v=VIDEO_ID"

JSON 格式(便于后处理)

JSON Format (for easy post-processing)

bash
python3 scripts/get_transcript.py -f json "VIDEO_ID"
bash
python3 scripts/get_transcript.py -f json "VIDEO_ID"

支持的 URL 格式

Supported URL Formats

  • https://www.youtube.com/watch?v=VIDEO_ID
  • https://youtu.be/VIDEO_ID
  • https://www.youtube.com/embed/VIDEO_ID
  • 直接使用 Video ID
  • https://www.youtube.com/watch?v=VIDEO_ID
  • https://youtu.be/VIDEO_ID
  • https://www.youtube.com/embed/VIDEO_ID
  • Direct use of Video ID

语言优先级

Language Priority

脚本按以下顺序查找字幕:
  1. 简体中文 (zh-Hans)
  2. 繁体中文 (zh-Hant)
  3. 中文 (zh)
  4. 英文 (en)
  5. 自动生成字幕
The script looks for subtitles in the following order:
  1. Simplified Chinese (zh-Hans)
  2. Traditional Chinese (zh-Hant)
  3. Chinese (zh)
  4. English (en)
  5. Auto-generated subtitles

翻译处理

Translation Processing

如果获取到的是英文字幕,需要翻译为中文:
  1. 运行脚本获取英文字幕
  2. 使用 Claude 内置能力翻译为流畅的中文
  3. 保持原文结构和段落划分
If the acquired subtitles are in English, they need to be translated into Chinese:
  1. Run the script to get English subtitles
  2. Use Claude's built-in capability to translate into fluent Chinese
  3. Maintain the original structure and paragraph division

错误处理

Error Handling

错误原因解决方案
No captions available视频无字幕告知用户该视频没有可用字幕
Cannot extract video IDURL 格式错误请求用户提供正确的 YouTube 链接
网络超时网络问题重试或检查网络连接
ErrorCauseSolution
No captions availableThe video has no subtitlesInform the user that there are no available subtitles for this video
Cannot extract video IDURL format errorAsk the user to provide a correct YouTube link
Network timeoutNetwork problemRetry or check network connection

输出格式示例

Output Format Example

Markdown 格式

Markdown Format

markdown
undefined
markdown
undefined

视频标题

视频标题



文字稿

文字稿

这是视频的第一段内容...
这是视频的第二段内容...
undefined
这是视频的第一段内容...
这是视频的第二段内容...
undefined