SuperAPI AI Directory

bilibili-subtitle

Office & productivity

View repository

Updated 10-15 17:24

About this skill

Bilibili Video Subtitles Skill

This skill is fully self-contained; all scripts are within the scripts/ directory, with no additional project dependencies required.

Dependency Installation

The script requires only one third-party library; ensure it is installed before running:

pip install requests

Optional installation (for displaying the QR code in the terminal):

pip install qrcode

Core Capabilities

Scenario What You Need to Do
User provides a link/BVID and wants subtitles or a summary Check login → Get subtitles → Generate summary
User asks "at what minute and second is a certain piece of content" Get subtitles (skip if already available) → Search SRT timestamps
User's Cookie is invalid or it is their first time using it Guide QR code login → Re-obtain subtitles

Workflow

Step 1: Parse the BVID

Extract the BVID from user input (format:BVxxxxxxxxxx)。

  • Supports plain BVID:BV1ZL411o7LZ
  • Supports full link:https://www.bilibili.com/video/BV1ZL411o7LZ
  • Short link (https://b23.tv/xxx) requires the user to first provide the full link or BVID

Step 2: Check the Subtitle Cache

Check whether subtitles_output/<BVID>/<BVID>.txt already exists:

  • Exists: Use it directly and skip Step 3. Inform the user that "local cached subtitles have been found".
  • Does not exist: Proceed to Step 3 to obtain subtitles.

Step 3: Obtain Subtitles

Run the acquisition script (path is relative to the skill directory):

python <skill-dir>/scripts/fetch_subtitle.py <BVID> --cookie cookie.txt --output-dir subtitles_output

<skill-dir> is the directory path where this SKILL.md is located. The script will automatically:

  1. Search for the Cookie by priority (specified path → current directory → script directory)
  2. Preferentially obtain AI subtitles; automatically fall back to CC subtitles when there are no AI subtitles
  3. Simultaneously output .txt、.srt、.vtt three formats

Common error handling:

Error Handling Method
Cookie does not exist/invalid Guide the user to log in (see "QR Code Login" below)
The video has no subtitles Inform the user (hard subtitles require OCR, which is beyond the skill's capabilities)
Network timeout Suggest the user check the network and retry

QR Code Login (execute only when needed)

When cookie.txt does not exist or has expired, guide the user to log in.

Choose an appropriate method based on the current environment:

Method A: AI can run terminal commands (such as Antigravity/Claude Code)

  1. Inform the user that they need to log in to Bilibili to obtain AI subtitles
  2. Run the login script:
    python <skill-dir>/scripts/cookie_login.py --output cookie.txt
    
  3. The script will print an ASCII QR code and login link in the terminal
  4. If the ASCII QR code is unclear, you can generate an image QR code for the user in the following way:
    import qrcode
    img = qrcode.make("<扫码链接URL>")
    img.save("qr_login.png")
    
  5. After the user scans the QR code and confirms in the Bilibili mobile app, the Cookie is automatically saved
  6. Continue executing Step 3

Method B: AI cannot run commands (e.g., OpenClaw/Claude.ai)

  1. Guide the user to execute it themselves in the terminal:
    pip install requests qrcode
    python <path-to-installed-skill>/scripts/cookie_login.py
    
  2. Or have the user manually obtain the Cookie:
    • Log in to Bilibili → F12 → Application → Cookies
    • Copy SESSDATA and bili_jct values
    • Write to cookie.txt, format:SESSDATA=xxx; bili_jct=xxx

Step 4: Generate summary

Read the plain text subtitles of subtitles_output/<BVID>/<BVID>.txt and generate a structured summary:

## 视频摘要:[BVID]

### 核心主题
(一句话概括视频主要讲了什么)

### 主要内容
1. [要点一]
2. [要点二]
3. [要点三]
...

### 关键结论
(视频最后强调或总结的观点)

When the subtitle text is very long:

  • Segment by content logic, do not cut evenly
  • Identify obvious "topic switches" as chapter division points
  • The summary length should be based on covering the main points

Step 5: Timestamp query

When the user asks "what time period is xxx in" or "when in the video is xxx mentioned":

  1. Confirm that the SRT file already exists (subtitles_output/<BVID>/<BVID>.srt)
  2. Run the timestamp search script:
    python <skill-dir>/scripts/search_timestamp.py \
      subtitles_output/<BVID>/<BVID>.srt "<关键词>" --context 2
    
  3. Organize the results into a friendly format:
    • "The video mentions this content around 01:23 "
    • When there are multiple matches, list all time points
    • When the keyword cannot be found, try synonyms or split-word searches

The SRT time format is HH:MM:SS,mmm, simplify to MM:SS。


Directory structure

bilibili-subtitle/             ← skill 根目录(本目录)
├── SKILL.md                   ← 本文件
└── scripts/
    ├── fetch_subtitle.py      ← 字幕获取(自包含,无外部依赖)
    ├── search_timestamp.py    ← 时间戳搜索
    └── cookie_login.py        ← 扫码登录获取 Cookie

用户工作目录下生成:
├── cookie.txt                 ← 登录 Cookie(自动生成)
└── subtitles_output/
    └── <BVID>/
        ├── <BVID>.txt         ← 纯文本字幕(用于摘要)
        ├── <BVID>.srt         ← 带时间戳字幕(用于时间定位)
        └── <BVID>.vtt         ← VTT 格式字幕

Notes

  • AI subtitles require login: When not logged in, you can only get CC subtitles manually uploaded by the UP host; AI subtitles for most videos require login.
  • Cookie validity period: Usually valid for several months, but abnormal account logout will cause it to expire.
  • Few subtitle entries: If very few subtitles are obtained (< 10 entries), it may be CC subtitles rather than complete AI subtitles; notify the user.
  • Hard subtitles: Subtitles burned into the picture (such as variety shows, movies) cannot be obtained and require OCR tool processing.