youtube-transcript

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

YouTube Transcript

YouTube 字幕提取

Extract transcripts from YouTube videos using the youtube-transcript-api.
使用youtube-transcript-api从YouTube视频中提取字幕文本。

Usage

使用方法

Run the script with a YouTube URL or video ID:
bash
uv run scripts/get_transcript.py "VIDEO_URL_OR_ID"
With timestamps:
bash
uv run scripts/get_transcript.py "VIDEO_URL_OR_ID" --timestamps
通过YouTube链接或视频ID运行脚本:
bash
uv run scripts/get_transcript.py "VIDEO_URL_OR_ID"
带时间戳的情况:
bash
uv run scripts/get_transcript.py "VIDEO_URL_OR_ID" --timestamps

Defaults

默认设置

  • Without timestamps (default): Plain text, one line per caption segment
  • With timestamps:
    [MM:SS] text
    format (or
    [HH:MM:SS]
    for longer videos)
  • 不带时间戳(默认):纯文本格式,每个字幕段占一行
  • 带时间戳
    [MM:SS] 文本
    格式(长视频则为
    [HH:MM:SS]
    格式)

Supported URL Formats

支持的链接格式

  • https://www.youtube.com/watch?v=VIDEO_ID
  • https://youtu.be/VIDEO_ID
  • https://youtube.com/embed/VIDEO_ID
  • Raw video ID (11 characters)
  • https://www.youtube.com/watch?v=VIDEO_ID
  • https://youtu.be/VIDEO_ID
  • https://youtube.com/embed/VIDEO_ID
  • 原始视频ID(11个字符)

Output

输出

  • CRITICAL: YOU MUST NEVER MODIFY THE RETURNED TRANSCRIPT
  • If the transcript is without timestamps, you SHOULD clean it up so that it is arranged by complete paragraphs and the lines don't cut in the middle of sentences.
  • If you were asked to save the transcript to a specific file, save it to the requested file.
  • If no output file was specified, use the YouTube video ID with a
    -transcript.txt
    suffix.
  • 重要提示:绝对不得修改返回的字幕文本
  • 如果是不带时间戳的字幕,你应该对其进行整理,使其按完整段落排列,且句子不会被中途截断。
  • 如果用户要求将字幕保存到指定文件,请保存到该请求的文件中。
  • 如果未指定输出文件,请使用YouTube视频ID加上
    -transcript.txt
    后缀作为文件名。

Notes

注意事项

  • Fetches auto-generated or manually added captions (whichever is available)
  • Requires the video to have captions enabled
  • Falls back to auto-generated captions if manual ones aren't available
  • 获取自动生成或手动添加的字幕(以可用的为准)
  • 要求视频已启用字幕功能
  • 如果没有手动添加的字幕,将 fallback 到自动生成的字幕