bbc-skill — Bilibili Comment Collector
Download all comments (top-level + nested + pinned) for a Bilibili video and
produce data that Claude Code can analyze downstream.
Update check
Throttle to one check per 24 hours per installation; never mutate the skill directory without explicit user consent.
-
If
<this-skill-dir>/.last_update
exists and is less than 24 hours old, skip this step entirely.
-
Otherwise, fetch the latest tag from upstream:
bash
git -C <this-skill-dir> ls-remote --tags origin 'v*' 2>/dev/null \
| awk '{print $2}' | sed 's|refs/tags/||' \
| sort -V | tail -1
-
Compare with this skill's
from the frontmatter. If the upstream tag is strictly newer (semver), tell the user one line and ask:
"A newer version of this skill is available: vX.Y.Z → vA.B.C. Want me to
?"
If they say yes, run
git -C <this-skill-dir> pull --ff-only
. Refresh
either way so the prompt doesn't repeat for 24 hours.
-
If upstream is the same or older, refresh
silently and continue.
-
On any failure (offline, not a git checkout — e.g. ClawHub-installed copy, read-only path, no permission), swallow the error silently and continue with the user's task. Do not mention the failure.
When to use
Trigger this skill when the user:
- Asks to get / fetch / download / export / collect / analyze comments of a
specific Bilibili video (BV 号, URL, or video page).
- Asks to analyze audience feedback / sentiment / keywords / top comments /
IP distribution of their own Bilibili videos.
- Provides a Bilibili URL like
https://www.bilibili.com/video/BVxxxxxxxxxx/
.
- Mentions their UP主 UID and wants batch analysis across their videos.
Do not use for: posting / deleting comments, downloading videos, barrage
(弹幕), live stream data, or private messages.
Prerequisites
-
Python 3.9+ (stdlib only — zero pip install).
-
Bilibili cookie. The user must be logged in to bilibili.com. The
recommended path:
- Install the Chrome/Edge extension
Get cookies.txt LOCALLY
(open-source, fully local, no upload).
- On a logged-in bilibili.com tab, click Export → save
www.bilibili.com_cookies.txt
.
- Pass via or set .
Alternatives:
- env var with just the SESSDATA value.
- Browser auto-detection (Firefox / Chrome / Edge on macOS) via
. Works best for Firefox; Chrome/Edge needs a logged-in
profile with cookies flushed to disk.
Auth delegation (Principle 7): the skill never runs OAuth flows. The human
is expected to log in via browser; the agent only consumes the resulting
cookie.
Quick start
Before any fetch, verify the cookie works:
bash
python3 -m bbc cookie-check
Success envelope (stdout):
json
{"ok":true,"data":{"mid":441831884,"uname":"探索未至之境","vip":false}}
Fetch all comments for a single video:
bash
python3 -m bbc fetch BV1NjA7zjEAU
Or pass a URL:
bash
python3 -m bbc fetch "https://www.bilibili.com/video/BV1NjA7zjEAU/"
Output (default
./bilibili-comments/<BV>/
):
- — one comment per line, flattened
- — video metadata + statistics + top-N
- — archived API responses
- — resume state
Commands
| Command | Purpose |
|---|
| Fetch all comments for one video |
| Batch fetch all videos of a UP主 |
| Rebuild from existing |
| Validate cookie; print logged-in user |
| Return JSON schema for commands (for agent discovery) |
Call
or
for full parameter details — do
not guess flag names.
Agent contract
Stdout vs stderr
- stdout: stable JSON envelope or
. JSON is the default when stdout is not a TTY.
Pass for human-readable tables.
- stderr: human log lines + NDJSON progress events for long tasks.
Exit codes
| Code | Meaning |
|---|
| 0 | Success |
| 1 | Runtime / API error |
| 2 | Auth error (cookie invalid / missing) |
| 3 | Validation error (bad BV number, bad flag) |
| 4 | Network error (timeout / retries exhausted) |
Error envelope
json
{
"ok": false,
"error": {
"code": "auth_expired",
"message": "SESSDATA 已过期,请重新登录 B 站",
"retryable": true,
"retry_after_auth": true
}
}
Error codes:
,
,
,
,
,
,
. See
for the full
contract.
Dry-run
Every fetch command supports
to preview the planned request
without making network calls:
bash
python3 -m bbc fetch BV1NjA7zjEAU --dry-run
Idempotency
Re-running the same
command on the same output directory resumes from
(skips already-fetched pages). Pass
to refetch.
Analysis workflow (for the agent)
- Read first (< 10 KB) to establish global context: video
metadata, total counts, time distribution, top-N.
- For thematic analysis, or / on —
each line is a flat JSON object, never load the whole file unless small.
- Typical analyses:
- Sentiment distribution → scan by batch
- Top fans → group by , count entries, aggregate
- UP 主互动 → filter
- Audience geography → histogram
- Feedback timeline → bucket by day/week
The
schema is documented in
references/agent-contract.md
.
Run the skill against any video to produce a real sample locally.
Safety tier
All commands are
read-only (tier:
). No mutation, no deletion, no
message sending. Dry-run available for all fetch commands.
References
references/api-endpoints.md
— Bilibili API fields used
references/cookie-extraction.md
— per-browser cookie decryption
references/agent-contract.md
— full envelope + schema contract
Limitations
- returned by the API includes pinned comments. Completeness
check:
top_level + nested + pinned == declared_all_count
.
- Very old comments (>2 years) may return thin data if the user was deleted.
- Anti-bot: aggressive values or repeated runs may trigger HTTP 412.
The client sleeps 1s between requests and backs off on 412.