bilibili-source
Fetch comprehensive, login-free data for any Bilibili (B站) video — title, UP name and follower count, publish date, partition, tags, per-part cids, live stats (view, like, coin, favorite, share, reply, danmaku), and full danmaku (bullet-comment) text. Use this skill whenever working with a Bilibili video and needing real, citable numbers or metadata — ingesting a Bilibili source into a knowledge base, analyzing why a video performed, verifying a creator's claimed metrics, building a case study, or any time a Bilibili view/like/favorite count is about to be written into a document — fetch it, never hand-type or estimate it. Accepts BVID, av numbers, b23.tv short links, or full URLs. Subtitles and favorites-folder (收藏夹) enumeration are also covered but require the user's Bilibili login.
1How It Works & Mechanism
The core design encapsulates 'a single view/detail API call + jq formatting' into a unified JSON: input is first normalized into bvid/aid query parameters, then fetched from api.bilibili.com and mapped into title/up/tags/stat/pages.
json=$(bili_curl "https://api.bilibili.com/x/web-interface/view/detail?$q")
Network resilience encapsulation: Requests strip local proxy env vars (Bilibili is a mainland Chinese service, where local forward proxies break requests), include browser UA + Referer to avoid occasional HTTP 412 errors, and implement failure retry backoff.
curl -fsSL --max-time 20 --retry 3 --retry-delay 1 --retry-all-errors -H "User-Agent: $UA" -H "Referer: https://www.bilibili.com"
The danmaku script reuses fetch to resolve the part's cid, then requests dm/list.so, performs raw-DEFLATE decompression, and extracts text from each <d> element.
xml=$(bili_curl "https://api.bilibili.com/x/v1/dm/list.so?oid=$cid" | python3 -c "import sys,zlib; sys.stdout.buffer.write(zlib.decompress(sys.stdin.buffer.read(), -15))")
Subtitle tracks enforce logged-in sessions: The script uses yt-dlp to read the user's browser cookies to pull subtitle tracks like ai-zh; the skill explicitly states 'There is no login-free path — do not try to bypass it' and requires asking the user beforehand.
yt-dlp --skip-download --write-subs --sub-langs "ai-zh,zh-Hans,zh-CN,zh" --user-agent "$UA" --add-header "Referer:https://www.bilibili.com" --cookies-from-browser "$browser"
Data honesty discipline built into the workflow: Metrics must include a fetched_at timestamp, and missing data must be marked as 'Unretrieved/Unverified' rather than estimated, preventing knowledge bases from being contaminated by manual entries.
**Live metrics → always cite `fetched_at`.** … A bare "12,000 views" with no timestamp is meaningless and silently goes stale.
Health checks against third-party API drift: bili-selftest.sh uses a fixed public fixture to assert each capability and login-gate invariant one by one, presenting drifts as PASS/FAIL lines.
It asserts SHAPE (fields exist, right types) and documented INVARIANTS — never exact values, since engagement numbers drift by design.
2Core Capabilities
3External Dependencies
| Kind | Dependency / Endpoint |
|---|---|
| cli | curl |
| cli | jq |
| cli | python3 |
| cli | yt-dlp |
| network | api.bilibili.com |
| network | b23.tv(短链展开,单跳 302) |
4Recommended Governance & Evidence
- 本地凭据 / 浏览器配置: Reads user login cookies/sessions/keyrings: bili-subs.sh via yt-dlp --cookies-from-browser "$browser" (chrome/firefox/safa
- scripts/: Executes local scripts or commands: bilibili-source/scripts/bili-fetch.sh
- 网络端点: Declares external network access: https://api.bilibili.com/x/web-interface/view/detail (fetch)
- 本地工作目录: File I/O and artifact output: bili-subs.sh writes subtitle files to the current directory: <id>.<lang>.<ext> (json3/srt)
5Second-Pass Verification
- [ok] fetch/danmaku 免登录(无凭证接触) — grep 复核三脚本无 Cookie/Authorization/SESSDATA 使用;bili_curl 只带 UA+Referer。
- [ok] bili-subs.sh 读浏览器 cookie 且有 ask-first — --cookies-from-browser 实参存在;脚本头『Because it reads the user's logged-in session, ASK THE USER before running it.』存在。
- [ok] 网络外发仅限 Bilibili 系域名 — 逐脚本重读:view/detail、dm/list.so、player/wbi/v2、fav/folder/created/list-all 均在 api.bilibili.com;短链 b23.tv;yt-dlp 目标为 bilibili.com 视频 URL。
- [ok] raw-deflate 弹幕解压机制成立 — list.so 返回经 python3 zlib.decompress(..., -15)(window bits -15),与脚本注释『headerless raw DEFLATE』一致。
- [ok] WBI 签名只在 reference(space/wbi/*)不在这批脚本里 — 脚本中 wbi 仅出现在 x/player/wbi/v2 端点名(登录门检测),无签名实现;reference 目录 TOC 标注 WBI 仅 space/wbi/* 需要。
- [ok] 功能声明 vs 实际能力相符 — 『fetch real, verifiable data…never hand-type or estimate』由 fetched_at+NO FABRICATION+脚本落地;未发现夸大或无法定位的承诺。
- [ok] 注入面(输入归一化) — BV 正则锚定 10 字符长度防过捕;aid 分支取纯数字;两者进入 query 而非 shell 求值。
- [ok] 元数据(license/stars/commit) — 仓库级 MIT、stars=1385、pushed_at=2026-09-09T12:33:29Z;本地 HEAD==pin d5c4678cb5d4fd6acc9c922690df035dbd33d247。
6Verdict & Scenarios
0274158c3549e867…