Skip to content

feat: add bilibili/comments, xiaohongshu/comments commands + rate-limiter plugin docs#457

Merged
jackwener merged 2 commits intojackwener:mainfrom
mikkley:feat/bilibili-xhs-comments-ratelimiter
Mar 26, 2026
Merged

feat: add bilibili/comments, xiaohongshu/comments commands + rate-limiter plugin docs#457
jackwener merged 2 commits intojackwener:mainfrom
mikkley:feat/bilibili-xhs-comments-ratelimiter

Conversation

@mikkley
Copy link
Contributor

@mikkley mikkley commented Mar 26, 2026

Summary

  • bilibili/comments <bvid> — fetches top-level replies via /x/v2/reply/main with WBI signing. Resolves bvid → aid via /x/web-interface/view, then calls the reply API with signed: true. No DOM dependency, same pattern as bilibili/search.

  • xiaohongshu/comments <note-id> — DOM extraction from the note detail page (/explore/<id>). XHS doesn't expose a public comments API, so we scroll the note container and scrape .parent-comment elements. Handles two edge cases:

    • Login-wall detection (throws AuthRequiredError)
    • Zero-like counts: XHS shows the text "赞" in the .count element when likes = 0; the extractor converts that to 0 instead of a string.
  • docs/advanced/rate-limiter-plugin.md — documents the onAfterExecute hook and shows a copy-paste rate-limiter plugin that adds a random 5–30 s sleep after every browser-platform command. Useful for long-running scraping jobs. Controlled via OPENCLI_RATE_MIN, OPENCLI_RATE_MAX, and OPENCLI_NO_RATE=1 (disable for local dev).

Test plan

  • npm test — all 294 existing tests pass; 10 new tests added (5 per command)
  • npx tsc --noEmit — no type errors
  • Manual: opencli bilibili comments BV1WtAGzYEBm --limit 5 returns ranked comment rows
  • Manual: opencli xiaohongshu comments <note-id> --limit 5 returns comment rows when logged in
  • Manual: rate-limiter local install prints [rate-limiter] xiaohongshu: sleeping Xs to stderr

🤖 Generated with Claude Code

…lugin docs

- bilibili/comments: fetch top-level replies via /x/v2/reply/main with WBI signing
  (bvid → aid resolution + signed params, no DOM dependency)
- xiaohongshu/comments: DOM extraction from note detail page with login-wall detection
  and correct handling of 0-like counts (XHS shows "赞" text instead of "0")
- docs/advanced/rate-limiter-plugin.md: documents the onAfterExecute hook pattern
  and shows a plug-and-play rate limiter that adds random sleep between platform
  commands to reduce bot-detection risk

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@Astro-Han
Copy link
Contributor

Both comments commands follow existing patterns nicely: bilibili reuses WBI signing, xiaohongshu goes with DOM extraction. A few things I noticed:

bilibili/comments error handling

The bvid resolution failure throws a bare Error instead of a CliError subclass (existing subtitle.ts uses CliError). Also, responses from /x/web-interface/view and /x/v2/reply/main don't check payload.code, so rate-limiting or auth failures would silently return an empty array instead of a clear error.

xiaohongshu/comments can't consume search output

xiaohongshu/search outputs URLs like /search_result/...?xsec_token=..., but comments only recognizes /explore/<id> and /note/<id>. Passing a search result URL to comments would fail to parse.

Output field leak

Each comment object includes loginWall: false, which leaks into --format json output and doesn't match the declared columns.

Empty result semantics

xiaohongshu throws EmptyResultError on zero comments, while bilibili returns an empty array. Might be worth aligning.

@jackwener jackwener merged commit 5731881 into jackwener:main Mar 26, 2026
@jackwener jackwener mentioned this pull request Mar 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants