What does Bili Watch do?
Overview
Enable WorkBuddy to read Bilibili videos via two paths:
- Text path: Capture subtitles (ai-zh)/danmaku, then have the AI read and summarize (
bili_watch.py) — it can "hear" the dialogue but misses the visuals. - Frame path: Download the video + ffmpeg keyframe extraction + AI reads each frame (
bili_frames.py) — actually sees the visuals (camera moves/UI/actions/textures), the only reliable way for companion viewing, visual-heavy content (PVZ memes, MC recordings, game compilations).
Boundary: This skill only does one-way "video→text" transcription. It does not involve automated recommendations, coins, comments, or private messages (those high-risk tools are in the open-source project bilibili_learning_bot, unrelated to this skill and not recommended by default).
Key Constraints (from real probing)
- Subtitle requires login: Bilibili subtitles (including AI subtitles) now require login. Without cookies, you get
Subtitles are only available when logged in. The language code for AI subtitles is usuallyai-zh(notzh-CN);--list-subsshowsai-zh srt/zh-CN.json3for real subtitle tracks. - Browser choice (critical):
- Prefer Firefox:
--cookies-from-browser firefoxreliably gets the login state for AI subtitles (Firefox cookies have no system-level encryption, yt-dlp reads them directly). Tested:--list-subssuccessfully listsai-zh, subtitles are captured. - Edge/Chrome have App-Bound Encryption (DPAPI):
--cookies-from-browser edgefails withFailed to decrypt with DPAPI, yt-dlp cannot read cookies, subtitle branch falls back to danmaku. - Exported cookie file is unreliable: Exporting Netscape format
.txtwith Cookie-Editor and feeding via--cookiestoapi.bilibili.com— tested: thenavendpoint returnsisLogin=false(SESSDATA expired/rotated on the server, exported cookie is stale), causingplayer/wbi/v2to return no subtitles, forcing danmaku fallback. Do not rely on exported cookie files; use Firefox real-time login state instead.
- Prefer Firefox:
- Danmaku does not require login:
yt-dlp --write-subs --sub-langs danmaku --skip-downloadcan directly capture danmaku XML as a fallback when no subtitles exist (content is fragmented and danmaku may be mixed with unrelated topics, only for rough context, not as actual subtitles). - Anti-scraping: Direct connection to bilibili.com with default UA gets blocked with 412; fetching homepage BV numbers or calling APIs requires browser UA + Referer/Origin (e.g.,
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 Chrome/120.0 Safari/537.36, Refererhttps://www.bilibili.com). - Environment dependencies: Sandbox/new machines often lack
yt-dlp; first runpython -m pip install -q yt-dlp. Frame extraction needs ffmpeg:pip install imageio-ffmpeg(includes static binary, no system ffmpeg needed). Whisper is usually missing (ASR audio transcription branch is disabled by default; user confirmed not needed).
Workflow
- Confirm the target is a Bilibili video (link or BV number).
- Prioritize subtitles: Run
scripts/bili_watch.py <BVID> --cookies-from-browser firefox(the script uses yt-dlp internally to fetch and parse subtitles). Must run on the user's local Windows machine (Firefox logged into Bilibili) to get subtitles. - First check tracks with
--list-subs:python -m yt_dlp --cookies-from-browser firefox --list-subs <URL>. If you seeai-zh, capture it; if onlydanmaku, login state isn't passing or the video has no subtitles. - If no subtitles/not logged in, the script automatically falls back to the danmaku branch, outputting danmaku transcription (fragmented context, may not match the video topic). Inside a sandbox without login, only this branch is possible.
- Once text is obtained, the AI reads and summarizes / answers questions.
- Visual-heavy videos (no subtitles or information is in the visuals: memes, recordings, game compilations):
python scripts/bili_frames.py <BVID>downloads and extracts frames; AI uses Read to inspect each frame (max 4 per batch — concurrency beyond that causes "model doesn't support images" errors). Never use title/tags/patterns to hallucinate "seeing" visuals; if unclear, re-extract with--width 1920for higher resolution. - Do not save to disk by default: Only prints preview to terminal; no file written. For long-term archiving, add
--saveto generate<BVID>.transcript.txt(user explicitly requested no default saving of danmaku files).
Bundled Script
scripts/bili_watch.py — Converts Bilibili videos to text (subtitles + danmaku).
- Usage:
python bili_watch.py <BVID or link/keyword> [--browser firefox] [--cookies file] [--save] [--search] --browser: Which browser's Bilibili login state to read (default firefox; edge/chrome fail due to DPAPI encryption, set as non-default).--cookies: Netscape format cookie file (now has an API direct connection branch: callsplayer/wbi/v2to get AI subtitle direct link). Note: Exported cookie files often report not logged in due to stale SESSDATA; prefer--cookies-from-browser firefox.--save: Save to disk as<BVID>.transcript.txt(not saved by default, only terminal preview). File includes metadata + subtitles + danmaku + comments.--comments: Additionally fetch public comments (viax/v2/reply/wbi/main, no login required, reuses the script'swbi_signsignature);--comment-pagessets page limit (default 10, ~20 per page);--comment-mode2=by popularity/3=by time. Sub-replies indented with↳prefix. With--save, comments are appended to the file.--search: Treat the target as a keyword to search for videos, listing candidate BVs.--search-limitquantity (default 20);--search-ordertotalrank/click/pubdate/dm/stow. Fixed 2026-08-25: First goes through the wbi signed APIx/web-interface/wbi/search/all/v2(automatically uses browser login state or--cookies). If the API is rate-limited and returns an empty shell (numResults>0but empty result), automatically falls back to scraping thehttps://search.bilibili.com/allweb page SSR card data (parsingbili-video-card__wrapblocks for title/BV/UP/length). Provide full context for search keywords (e.g., "NX tree command Minecraft"), as over-splitting tokens can hit unrelated content.--min-danmaku: Danmaku merge threshold (default 2). Repeated danmaku with count >= threshold are merged into a single line with(xN). All danmaku are preserved, no destructive deletion (danmaku is now a 100% output item, no longer just a fallback).--no-danmaku: Only fetch subtitles, no danmaku.- Output structure (upgraded): ① Metadata at top (title/UP/length/plays/category/tags/publish/description, for AI background context); ② Subtitles first with timestamps
[mm:ss]; ③ Danmaku 100% preserved with timestamps + dedup merging; ④ Comments (optional). Subtitles and danmaku are decoupled: if subtitles exist, danmaku is still included; if no subtitles, danmaku is output independently. - Parsing logic: json3/vtt/srt subtitles extract from
from/timecode with[timestamp]; danmaku XML extracts from<d p="timestamp,...">with[timestamp]; comments extractdata.replies[].content.message(includingrepliessub-replies). - Videos without subtitles: Bilibili-side videos that only have danmaku track (e.g., BV1eVgA64EpH, BV1cj8c6jE7f),
--list-subsonly showsdanmaku; danmaku is output 100% independently, no longer misreported as a "fallback". - Status differentiation (false report fixed): The script now uses
--list-substo check the real track first, no longer mistaking "no subtitles" as "not logged in." Three branches: ① Login state read and video genuinely has no subtitle track → message "This video does not have a subtitle track (no subtitles)"; ② Subtitle track exists but cookies not read successfully (not logged in/DPAPI encrypted/browser not installed) → message to switch to Firefox or provide--cookies; ③ No cookie and track status unconfirmed → message to skip subtitles (danmaku still fetched). The old unified message "possibly not logged in or this video has no subtitles" is deprecated.
scripts/bili_frames.py — Downloads Bilibili videos + ffmpeg frame extraction for AI image reading (new in v1.2.0).
- Usage:
python bili_frames.py <BVID> [--interval 3] [--width 1280] [--outdir directory]; or--video <local.mp4>to skip download and extract directly from a local file. - Dependencies:
pip install yt-dlp imageio-ffmpeg(imageio-ffmpeg includes a static ffmpeg binary, no system-wide installation needed). - Automatic format selection (critical pitfall):
-f "bv*[height<=1080]+ba/b[height<=1080]" --format-sort "vbr:asc"— forces selection of the lowest-bitrate normal-quality stream within 1080p, avoiding the "1080P High Bitrate/60fps" tier that requires a membership (free accounts get a format unavailable error). Format IDs vary per video (30080/100050/80…), never hardcode format IDs. On failure, automatically degrades to 720p and retries. - Image reading specification: AI uses Read to inspect each frame, max 4 per batch; never hallucinate visuals (past failure: guessing "healing montage" from title while the actual video was a chat-style meme); if unclear, enlarge with
--width 1920and re-extract.
Notes
- Collaboration: The user runs the script on their own Windows machine to get text, then pastes the result to WorkBuddy; or if WorkBuddy has local access, it can invoke the script directly. The sandbox environment has no browser login state, so the subtitle branch cannot be demonstrated, but the danmaku branch can be verified here directly.
- Distinction from bilibili_learning_bot: That is a full account automation tool (recommendations/coins/comments/private messages), high risk of account suspension and API costs; this skill only does content transcription, low risk.