bilibili-watch-mcp

v0.2.2
io.github.Liber1917/bilibili-watch-mcp Checked 4 days ago Published 4 days ago

Turns Bilibili videos into agent-readable materials: subtitles, danmaku, keyframe sheets, frames.

An MCP server that turns Bilibili videos into agent-readable materials: subtitle text, danmaku (bullet comments), sprite keyframe contact sheets, and optional hi-res frames. Built for tool-using agents (Claude Code, Cline, etc.) that need to *understand* a video, not download it. video accepts a BV id or a full URL. AI-generated subtitles require the account cookie (see BILI_SESSDATA below); CC subtitles and everything else work login-free. mid is the number in a creator's space URL (https://space.bilibili.com/), not the display name.

Summary extracted from the README.

bilibili-watch-mcp

An MCP server that turns Bilibili videos into agent-readable materials: subtitle text, danmaku (bullet comments), sprite keyframe contact sheets, and optional hi-res frames. Built for tool-using agents (Claude Code, Cline, etc.) that need to understand a video, not download it.

Bilibili 视频 → agent 可读材料 的 MCP server:字幕全文、弹幕、进度条关键帧拼图、可选高清抽帧。给 Claude Code 这类工具型 agent 提供"看懂视频"的能力。

Why this exists

  • Most Bilibili MCP servers only expose search/metadata. The ones that expose subtitles depend on bilibili-api-python, which was taken down by a legal notice in 2026 and is unmaintained. This project's fetching is built on yt-dlp (actively maintained, quick to follow Bilibili's anti-bot changes) plus two signature-free endpoints for danmaku and sprite sheets — no dead dependencies.
  • The sprite contact sheet trick: one request returns Bilibili's own progress-bar preview thumbnails covering the whole video — no login, no video download. Good for coarse "where am I in this video" localization. Hi-res frames (854px) make on-screen code / slide text readable.

Tools

Tool What it does
search_videos(keyword, limit) Login-free site search. Returns BV id, title, uploader, duration, plays.
watch_video(video, with_frames, max_frames, subtitle_max_chars) Fetch one video: metadata + subtitle text inline + danmaku + sprite sheets. with_frames=True additionally downloads a low-quality stream and extracts uniform frames + scene-cut frames (854px), then deletes the video.
list_creator_videos(mid, limit, max_pages) List everything one creator uploaded: BV id, title, plays, duration, newest first. Saves the full list as creator_<mid>.json. Needs the debug-enabled browser.

video accepts a BV id or a full URL. AI-generated subtitles require the account cookie (see BILI_SESSDATA below); CC subtitles and everything else work login-free. mid is the number in a creator's space URL (https://space.bilibili.com/<mid>), not the display name.

Why list_creator_videos reads the page instead of calling an API: direct calls to the upload-list endpoint are blocked (403 / 412), so the tool opens the creator's space in the debug browser and pages through it the way a person would, about 5 seconds per page. It stops as soon as Bilibili asks for verification or paging stalls, and says so in the report.

Install

pip install bilibili-watch-mcp        # or: uvx bilibili-watch-mcp

Runtime dependencies (requests, yt-dlp, imageio-ffmpeg, mcp) are pulled in automatically. No ffmpeg installation needed — imageio-ffmpeg ships a static binary.

Configure your client

Claude Code:

claude mcp add bilibili-watch -- bilibili-watch-mcp

Or .mcp.json / claude_desktop_config.json:

{
  "mcpServers": {
    "bilibili-watch": {
      "command": "bilibili-watch-mcp",
      "env": {
        "BILI_SESSDATA": "",
        "BILI_WATCH_OUT": "./bili_watch_out"
      }
    }
  }
}

Authentication (AI subtitles, better search & creator lists)

Two ways to provide the Bilibili session cookie (SESSDATA), tried in order:

  1. Automatic — via a debug-enabled browser (recommended). Since Chrome 136, the default profile cannot be opened with a debugging port, so use a dedicated profile. Start Chrome once, log in to Bilibili in that window; the session persists in the profile:

    chrome.exe --user-data-dir="%USERPROFILE%\bili-watch-auth" --remote-debugging-port=9222 https://www.bilibili.com
    

    The server auto-detects 127.0.0.1:9222 and pulls SESSDATA over CDP on demand. Cookie values live in memory only — never written to disk, never echoed. If the debug browser is closed, tools fall back to login-free mode (danmaku/sprites/≤1080p still work; AI subtitles don't).

    list_creator_videos needs this browser window to be open; without it the tool returns an error telling you to start it. Use a different port with BILI_CDP_PORT.

  2. Manual — environment variable. Set BILI_SESSDATA to the cookie value from your browser's DevTools.

Note: yt-dlp cannot fetch Bilibili's AI-generated subtitles even when authenticated, so this server additionally pulls them from the player API directly (requires login state) and converts them to .srt.

Environment variables:

Var Meaning
BILI_SESSDATA Optional. Your Bilibili session cookie value (browser DevTools → Cookies). Unlocks AI-generated subtitles. Give it only if you accept the account implications.
BILI_WATCH_OUT Output directory for fetched materials. Default ./bili_watch_out.
BILI_CDP_PORT Optional. Debug port of the dedicated browser. Default 9222.

How an agent should use the output

watch_video returns a text report with:

  1. subtitle text inline — compact form: one line per minute with a [mm:ss] timestamp, about a quarter of the raw srt size. For lecture/slide videos this alone is usually 90% of the content. Read it first.
  2. sprite contact sheet paths — one or a few JPGs, each a 10x10 grid of thumbnails evenly covering the whole video. Cell k ≈ k × duration / total cells. Use for coarse time localization.
  3. frames paths (if with_frames) — uniform_*.jpg with a timestamp table, and scene_*.jpg at detected scene cuts. 854px wide; on-screen text (slides, code) is readable. Read these with your file/image tool.

Typical flows:

  • Everything by one creator → list_creator_videos(mid) → watch_video(bvid) for the ones that matter.
  • Lecture / tutorial → search_videos → watch_video(bvid) → read subtitle text.
  • Hands-on coding demo → watch_video(bvid, with_frames=true) → locate the segment on sprite sheets → read nearby frames/*.jpg.
  • Personal, low-volume use only. This project talks to Bilibili as a guest client; abusive request rates will get your IP rate-limited (-352 / HTTP 412) and may put your account at risk if you attach BILI_SESSDATA.
  • list_creator_videos pages through a creator's space at human speed (about 5 seconds per page) and stops when verification is demanded. Keep it that way; do not shorten the pause or retry around a block.
  • Not affiliated with or endorsed by Bilibili. You are responsible for complying with their terms of service and local law. Bilibili has been actively sending legal notices to third-party API projects since 2026 — this project deliberately keeps its footprint minimal (yt-dlp + two signature-free endpoints) but cannot promise that never changes.

中文说明(简要)

给 agent 用的 B站视频理解 MCP。search_videos 免登录搜视频,watch_video 一键取字幕全文(直接返回文本)+ 弹幕 + 进度条关键帧拼图(粗定位画面)+ 可选高清抽帧(854px,PPT/代码可读,实操演示类用 with_frames=True),list_creator_videos 列出一位 UP 主的全部投稿(按发布时间从新到旧,完整清单存成 JSON;需要那个带调试端口的浏览器开着,每翻一页停 5 秒,遇验证即停)。取料底座是 yt-dlp(活跃维护、跟进B站风控),弹幕和拼图走两个免签名接口,不依赖任何已关停的第三方 SDK。

登录态(AI字幕/提高搜索成功率)推荐自动方式:开一个带调试端口的专用 Chrome 窗口并登录一次(chrome.exe --user-data-dir="%USERPROFILE%\bili-watch-auth" --remote-debugging-port=9222 https://www.bilibili.com),server 会自动经 CDP 取 SESSDATA(只在内存、不落盘);调试窗口关掉则自动降级为免登录模式。也可手动设 BILI_SESSDATA 环境变量。注意 yt-dlp 拿不到 B站 AI 字幕,本工具会登录态直连播放器接口补拉并转成 srt。仅供个人低频使用,请尊重平台条款。

License

MIT. See LICENSE.