Skip to content
Back to search

bilibili-cli

SkillWorks with Claude CodeGitHub

CLI skill for Bilibili (哔哩哔哩, B站) with token-efficient YAML output for AI agents to browse videos, users, search, trending, dynamics, favorites, and interactions from the terminal

Safety scan

A static text scan, not a guarantee. Select the badge to see what was scanned and every finding.

Checked today
Badge for your README
findsafeskills safety rating

Markdown

[![findsafeskills safety rating](/api/listings/public-clis--bilibili-cli/badge.svg)](/listings/public-clis--bilibili-cli)

HTML

<a href="/listings/public-clis--bilibili-cli"><img src="/api/listings/public-clis--bilibili-cli/badge.svg" alt="findsafeskills safety rating" /></a>

Install

i

Install instructions from the README

As written by the repo's author. findsafeskills has not verified these steps.

# Recommended: uv tool (fast, isolated)
uv tool install bilibili-cli

# Or: pipx
pipx install bilibili-cli

# If you need audio extraction support
uv tool install "bilibili-cli[audio]"
# or
pipx install "bilibili-cli[audio]"

Upgrade to the latest version:

uv tool upgrade bilibili-cli
# Or: pipx upgrade bilibili-cli

> **Tip:** Upgrade regularly to avoid unexpected errors from outdated API handling.

Or from source:

git clone git@github.com:jackwener/bilibili-cli.git
cd bilibili-cli
uv sync

Run tests in the project environment:

uv sync --extra dev
uv run pytest -q
uv run ruff check .
uv run python -m mypy bili_cli

If the project directory was moved and stale virtualenv wrappers remain, rerun:

uv sync --extra dev --reinstall

What was scanned

The files the safety scan read, as written by the repository's author and shown as plain text. Lines with a finding are marked.

SKILL.md · Manifest · 252 lines

View this file on GitHub (read at the repository's current version: the scan did not record which commit it read)

  1. ---
  2. name: bilibili-cli
  3. description: CLI skill for Bilibili (哔哩哔哩, B站) with token-efficient YAML output for AI agents to browse videos, users, search, trending, dynamics, favorites, and interactions from the terminal
  4. author: jackwener
  5. version: "0.6.2"
  6. tags:
  7. - bilibili
  8. - 哔哩哔哩
  9. - b站
  10. - video
  11. - social-media
  12. - cli
  13. ---
  14. # bilibili-cli Skill
  15. A CLI tool for interacting with Bilibili (哔哩哔哩). Use it to fetch video info, search content, browse user profiles, and perform interactions like liking or triple-clicking.
  16. ## Agent Defaults
  17. When you need machine-readable output:
  18. 1. Prefer `--yaml` first because it is usually more token-efficient than pretty JSON.
  19. 2. Use `--json` only when downstream tooling strictly requires JSON.
  20. 3. Keep result sets small with `--max`, `--page`, or `--offset`.
  21. 4. Prefer specific commands over broad ones. Example: use `bili user-videos 946974 --max 3 --yaml` instead of fetching large timelines.
  22. 5. When summarizing a video, fetch subtitles first. Subtitles usually contain the video's core content and are the best primary source for summaries.
  23. 6. Only fall back to `--ai`, comments, or audio extraction when subtitles are unavailable or clearly insufficient.
  24. ## Prerequisites
  25. ```bash
  26. # Install (requires Python 3.10+)
  27. uv tool install bilibili-cli
  28. # Or: pipx install bilibili-cli
  29. # If you need audio extraction support (requires PyAV)
  30. uv tool install "bilibili-cli[audio]"
  31. # Or: pipx install "bilibili-cli[audio]"
  32. # Upgrade to latest (recommended to avoid API errors)
  33. uv tool upgrade bilibili-cli
  34. # Or: pipx upgrade bilibili-cli
  35. ```
  36. ## Authentication
  37. Most read commands work without login. Subtitles, favorites/following/watch-later/history, feed, and interactions require login.
  38. ```bash
  39. bili status # Check if logged in (exit 0 = yes, 1 = no)
  40. bili login # QR code login (if not authenticated)
  41. ```
  42. Authentication auto-detects local browser cookies (Chrome/Firefox/Edge/Brave). If cookies are found and valid, no manual login needed. Credentials are saved to `~/.bilibili-cli/credential.json`.
  43. ## Command Reference
  44. ### Video
  45. ```bash
  46. # Get video details (accepts BV ID or full URL)
  47. bili video BV1ABcsztEcY
  48. bili video https://www.bilibili.com/video/BV1ABcsztEcY
  49. # Options
  50. bili video BV1ABcsztEcY --subtitle # Show subtitles (plain text)
  51. bili video BV1ABcsztEcY --subtitle-timeline # Show subtitles with timestamps
  52. bili video BV1ABcsztEcY -st --subtitle-format srt # Export as SRT format
  53. bili video BV1ABcsztEcY --ai # Show B站 AI summary
  54. bili video BV1ABcsztEcY --comments # Show top comments
  55. bili video BV1ABcsztEcY --related # Show related videos
  56. bili video BV1ABcsztEcY --yaml # Token-efficient YAML output
  57. bili video BV1ABcsztEcY --json # Structured JSON envelope
  58. ```
  59. ### User
  60. ```bash
  61. # Look up user profile (by UID or username)
  62. bili user 946974
  63. bili user "影视飓风"
  64. # List user's videos
  65. bili user-videos 946974 --max 20
  66. bili user-videos "影视飓风" --yaml
  67. ```
  68. ### Search
  69. ```bash
  70. # Search users (default)
  71. bili search "关键词"
  72. # Search videos
  73. bili search "关键词" --type video
  74. # Pagination and limit
  75. bili search "关键词" --type video --max 5
  76. bili search "关键词" --page 2
  77. ```
  78. ### Discovery
  79. ```bash
  80. bili hot # Trending/popular videos
  81. bili hot --page 2 --max 10 # Page 2, limit 10
  82. bili rank # Site-wide ranking (3-day)
  83. bili rank --day 7 --max 30 # 7-day ranking, top 30
  84. bili feed # Dynamic timeline (requires login)
  85. bili feed --offset 1234567890 # Next page via returned cursor
  86. bili my-dynamics # My posted dynamics (requires login)
  87. bili dynamic-post "hello" # Publish text dynamic (requires write credential)
  88. bili dynamic-delete 123456789 # Delete one dynamic (requires write credential)
  89. ```
  90. ### Collections (require login)
  91. ```bash
  92. bili favorites # List favorite folders
  93. bili favorites <ID> --page 2 # Videos in a folder
  94. bili following # Following list
  95. bili watch-later # Watch later list
  96. bili history # Watch history
  97. ```
  98. ### Audio Extraction
  99. Requires `bilibili-cli[audio]` extra (PyAV). Install with `uv tool install "bilibili-cli[audio]"`.
  100. ```bash
  101. # Download audio and split into ASR-ready WAV segments (25s each, 16kHz mono)
  102. bili audio BV1ABcsztEcY # Split to /tmp/bilibili-cli/{title}/
  103. bili audio BV1ABcsztEcY --segment 60 # 60s per segment
  104. bili audio BV1ABcsztEcY --no-split # Full m4a file, no splitting
  105. bili audio BV1ABcsztEcY -o ~/data/ # Custom output directory
  106. ```
  107. ### Interactions (require login)
  108. ```bash
  109. bili like BV1ABcsztEcY # Like a video
  110. bili like BV1ABcsztEcY --undo # Unlike
  111. bili coin BV1ABcsztEcY # Give 1 coin
  112. bili coin BV1ABcsztEcY -n 2 # Give 2 coins
  113. bili triple BV1ABcsztEcY # 一键三连 (like + coin + favorite)
  114. bili unfollow 946974 # Unfollow by UID
  115. ```
  116. ### Account
  117. ```bash
  118. bili status # Quick login check
  119. bili status --yaml # Structured auth status
  120. bili whoami # Detailed profile info
  121. bili whoami --yaml # Profile as YAML
  122. bili whoami --json # Profile as JSON
  123. bili login # QR code login
  124. bili logout # Clear credentials
  125. ```
  126. ## Structured Output
  127. Major query commands support both `--yaml` and `--json` for machine-readable output. Prefer YAML for agent use:
  128. ```bash
  129. bili status --yaml # Quick structured auth check
  130. bili video BV1ABcsztEcY --yaml # Preferred for AI agents
  131. bili hot --max 5 --yaml # Smaller, token-efficient payload
  132. bili user 946974 --json | jq -r '.data.user.name' # JSON when jq is needed
  133. ```
  134. When stdout is not a TTY, `bilibili-cli` defaults to YAML automatically.
  135. Use `OUTPUT=yaml|json|rich|auto` to override the default output mode.
  136. All machine-readable output uses the envelope documented in [SCHEMA.md](./SCHEMA.md).
  137. ## Debugging
  138. ```bash
  139. bili -v <command> # Enable verbose/debug logging for any command
  140. ```
  141. ## Common Patterns for AI Agents
  142. ```bash
  143. # For video summarization, fetch subtitles first
  144. bili video BV1ABcsztEcY --subtitle
  145. # Only use AI summary as a fallback or secondary signal
  146. bili video BV1ABcsztEcY --ai
  147. # Get comments for sentiment analysis
  148. bili video BV1ABcsztEcY --comments
  149. # Extract audio for speech-to-text (ASR)
  150. # Segments are saved to /tmp/bilibili-cli/{title}/seg_000.wav, seg_001.wav, ...
  151. bili audio BV1ABcsztEcY --segment 25
  152. # Find a user's latest video BV ID with minimal payload
  153. bili user-videos 946974 --max 1 --yaml
  154. # Check if logged in before performing actions
  155. bili status && bili like BV1ABcsztEcY
  156. # Search and inspect the first few results
  157. bili search "topic" --type video --max 3 --yaml
  158. ```
  159. ### Workflow: Video Content Analysis
  160. ```bash
  161. # 1. Search for a topic
  162. bili search "AI" --type video --max 5
  163. # 2. Get subtitles first for summarization
  164. bili video BV1xxx --subtitle
  165. # 3. If subtitles are missing or incomplete, try AI summary
  166. bili video BV1xxx --ai
  167. # 4. If there is still not enough content, extract audio for ASR
  168. bili audio BV1xxx --segment 25
  169. # 5. Get comments for audience reaction
  170. bili video BV1xxx --comments
  171. ```
  172. ### Workflow: UP主 Research
  173. ```bash
  174. # 1. Look up UP主 profile
  175. bili user "影视飓风"
  176. # 2. Get their recent videos
  177. bili user-videos 946974 --max 10
  178. # 3. Inspect a specific video
  179. bili video BV1xxx --ai --comments
  180. ```
  181. ## Error Handling
  182. - Commands exit with code 0 on success, non-zero on failure
  183. - Error messages are prefixed with ❌
  184. - Login-required commands show ⚠️ with instruction to run `bili login`
  185. - Invalid BV IDs show a clear error message
  186. ## Safety Notes
  187. - Do not ask users to share raw credential/cookie values in chat logs.
  188. - Prefer local browser cookie extraction over manual secret copy/paste.
  189. - If auth fails, ask the user to re-login via `bili login`.
README.md · README · 455 lines

View this file on GitHub (read at the repository's current version: the scan did not record which commit it read)

  1. # bilibili-cli
  2. [![CI](https://github.com/jackwener/bilibili-cli/actions/workflows/ci.yml/badge.svg)](https://github.com/jackwener/bilibili-cli/actions/workflows/ci.yml)
  3. [![PyPI version](https://img.shields.io/pypi/v/bilibili_cli.svg)](https://pypi.org/project/bilibili-cli/)
  4. [![Python versions](https://img.shields.io/pypi/pyversions/bilibili_cli.svg)](https://pypi.org/project/bilibili-cli/)
  5. [![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](./LICENSE)
  6. A CLI for Bilibili — browse videos, users, favorites from the terminal 📺
  7. [English](#features) | [中文](#功能特性)
  8. ## More Projects
  9. - [xiaohongshu-cli](https://github.com/jackwener/xiaohongshu-cli) — Xiaohongshu (小红书) CLI for notes and account workflows
  10. - [twitter-cli](https://github.com/jackwener/twitter-cli) — Twitter/X CLI tooling
  11. - [discord-cli](https://github.com/jackwener/discord-cli) — Discord CLI for local-first chat sync and search
  12. - [tg-cli](https://github.com/jackwener/tg-cli) — Telegram CLI for local-first sync, search, and export
  13. ## Features
  14. - 🎬 **Video** — details, subtitles, AI summary, comments, related videos
  15. - 🎵 **Audio** — extract audio and split into ASR-ready WAV segments
  16. - 👤 **User** — profile, video list, following list
  17. - 🔍 **Search** — search users or videos by keyword
  18. - 🔥 **Trending** — hot videos and site-wide ranking
  19. - 📰 **Feed** — dynamic timeline from your follows
  20. - 📂 **Favorites** — browse favorite folders, watch-later, and watch history
  21. - 👍 **Interactions** — like, coin, triple (一键三连)
  22. - 🔐 **Smart auth** — auto-extracts cookies from Chrome/Firefox, or QR code login
  23. - 📊 **Structured output** — major query commands support `--yaml` and `--json`
  24. - 🤖 **Agent-friendly defaults** — non-TTY stdout defaults to YAML; override with `OUTPUT=yaml|json|rich|auto`
  25. - 📦 **Stable envelope** — see [SCHEMA.md](./SCHEMA.md) for `ok/schema_version/data/error`
  26. - 🧱 **Normalized payloads** — command-layer output is normalized instead of leaking raw upstream SDK responses
  27. ## Installation
  28. ```bash
  29. # Recommended: uv tool (fast, isolated)
  30. uv tool install bilibili-cli
  31. # Or: pipx
  32. pipx install bilibili-cli
  33. # If you need audio extraction support
  34. uv tool install "bilibili-cli[audio]"
  35. # or
  36. pipx install "bilibili-cli[audio]"
  37. ```
  38. Upgrade to the latest version:
  39. ```bash
  40. uv tool upgrade bilibili-cli
  41. # Or: pipx upgrade bilibili-cli
  42. ```
  43. > **Tip:** Upgrade regularly to avoid unexpected errors from outdated API handling.
  44. Or from source:
  45. ```bash
  46. git clone git@github.com:jackwener/bilibili-cli.git
  47. cd bilibili-cli
  48. uv sync
  49. ```
  50. Run tests in the project environment:
  51. ```bash
  52. uv sync --extra dev
  53. uv run pytest -q
  54. uv run ruff check .
  55. uv run python -m mypy bili_cli
  56. ```
  57. If the project directory was moved and stale virtualenv wrappers remain, rerun:
  58. ```bash
  59. uv sync --extra dev --reinstall
  60. ```
  61. ## Usage
  62. ```bash
  63. # Login & account
  64. bili status # Check login status
  65. bili status --yaml # Structured auth status
  66. bili login # QR code login
  67. bili whoami # Detailed profile (level, coins, followers)
  68. bili whoami --yaml # Structured profile
  69. # Videos
  70. bili video BV1ABcsztEcY # Video details
  71. bili video BV1ABcsztEcY --subtitle # With subtitles (plain text)
  72. bili video BV1ABcsztEcY --subtitle-timeline # With timeline
  73. bili video BV1ABcsztEcY -st --subtitle-format srt # Export as SRT
  74. bili video BV1ABcsztEcY --ai # AI summary
  75. bili video BV1ABcsztEcY --comments # Top comments
  76. bili video BV1ABcsztEcY --related # Related videos
  77. bili video BV1ABcsztEcY --yaml # Agent-friendly YAML
  78. bili video BV1ABcsztEcY --json # Normalized JSON envelope
  79. bili video BV1ABcsztEcY --subtitle-timeline --comments --json # Extras in one payload
  80. # Users
  81. bili user 946974 # UP profile
  82. bili user "影视飓风" # Search by name
  83. bili user-videos 946974 --max 20 # Video list
  84. # Discovery
  85. bili hot # Trending videos (page 1)
  86. bili hot --page 2 --max 10 # Page 2, top 10
  87. bili rank # Site-wide ranking (3-day)
  88. bili rank --day 7 --max 30 # 7-day ranking, top 30
  89. bili search "关键词" # Search users
  90. bili search "关键词" --type video --max 5 # Search videos (top 5)
  91. bili search "关键词" --page 2 # Next page
  92. bili feed # Dynamic timeline
  93. bili feed --offset 1234567890 # Next page via returned cursor
  94. bili my-dynamics # My posted dynamics
  95. bili dynamic-post "抽个奖,明天开奖" # Publish text dynamic
  96. bili dynamic-delete 123456789012345678 # Delete one dynamic
  97. # Collections
  98. bili favorites # Favorite folders
  99. bili favorites <ID> --page 2 # Videos in a folder
  100. bili following # Following list
  101. bili watch-later # Watch later
  102. bili history # Watch history
  103. # Audio extraction
  104. bili audio BV1ABcsztEcY # Download + split into 25s WAV segments
  105. bili audio BV1ABcsztEcY --segment 60 # 60s per segment
  106. bili audio BV1ABcsztEcY --no-split # Full m4a, no splitting
  107. bili audio BV1ABcsztEcY -o ~/data/ # Custom output directory
  108. # Interactions
  109. bili like BV1ABcsztEcY # Like
  110. bili coin BV1ABcsztEcY # Give coin
  111. bili triple BV1ABcsztEcY # 一键三连 🎉
  112. bili unfollow 946974 # Unfollow by UID
  113. bili like BV1ABcsztEcY --json # Structured write result
  114. bili coin BV1ABcsztEcY --yaml # Structured write result
  115. ```
  116. ## Authentication
  117. bilibili-cli uses a 3-tier authentication strategy:
  118. 1. **Saved credential** — loads from `~/.bilibili-cli/credential.json`
  119. 2. **Browser cookies** — auto-extracts from Chrome, Firefox, Edge, or Brave
  120. 3. **QR code login** — `bili login` displays a QR code in the terminal
  121. Credentials are validated on use for authenticated commands. Expired cookies are automatically cleared, while transient network validation failures keep local credentials for best-effort fallback.
  122. `bili status` exits with code `0` only when authenticated; otherwise it exits with `1`.
  123. Most commands work without login. Subtitles, favorites/following/watch-later/history, feed, my-dynamics, and interactions require authentication. Write actions (like/coin/triple/unfollow/dynamic-post/dynamic-delete) require write-capable credential (`bili_jct`).
  124. Audio extraction requires the optional `audio` dependency group (`av`).
  125. ## Structured Output
  126. All `--json` / `--yaml` output uses the shared envelope from [SCHEMA.md](./SCHEMA.md).
  127. Major commands now emit normalized payloads instead of raw upstream SDK blobs:
  128. - `bili video` → `data.video`, `data.subtitle`, `data.ai_summary`, `data.comments`, `data.related`, `data.warnings`
  129. - `bili hot` / `bili rank` → `data.items`
  130. - `bili search` → normalized user/video lists
  131. - `bili like` / `bili coin` / `bili triple` / `bili unfollow` → normalized write-action results
  132. Structured errors now use more specific codes such as `not_authenticated`, `permission_denied`, `invalid_input`, `network_error`, `upstream_error`, and `not_found`.
  133. ## Use as AI Agent Skill
  134. bilibili-cli ships with a [`SKILL.md`](./SKILL.md) that teaches AI agents how to use it.
  135. ### Agent Output Recommendation
  136. If an AI agent needs machine-readable output, prefer `--yaml` first:
  137. - `--yaml` is usually more token-efficient than pretty-printed JSON
  138. - It is still easy to parse for agents and scripts
  139. - Keep `--json` for `jq`, strict JSON-only tooling, or exact downstream schemas
  140. - Non-TTY stdout defaults to YAML automatically
  141. - Use `OUTPUT=yaml|json|rich|auto` to override the default mode
  142. Examples:
  143. ```bash
  144. bili status --yaml
  145. bili video BV1ABcsztEcY --yaml
  146. bili hot --max 5 --yaml
  147. bili user-videos 946974 --max 3 --yaml
  148. ```
  149. For agent usage, also prefer narrower queries (`--max`, `--page`, `--offset`) to avoid wasting context on oversized payloads.
  150. When an AI agent is asked to summarize a video, it should fetch subtitles first. Subtitles usually contain the core content of the video and are the best primary source for summarization. Only fall back to AI summary, comments, or audio extraction when subtitles are unavailable or insufficient.
  151. ### [Skills CLI](https://github.com/vercel-labs/skills) (Recommended)
  152. ```bash
  153. npx skills add jackwener/bilibili-cli
  154. ```
  155. | Flag | Description |
  156. | --- | --- |
  157. | `-g` | Install globally (user-level, shared across projects) |
  158. | `-a claude-code` | Target a specific agent |
  159. | `-y` | Non-interactive mode |
  160. ### Manual Install
  161. ```bash
  162. mkdir -p .agents/skills
  163. git clone git@github.com:jackwener/bilibili-cli.git .agents/skills/bilibili-cli
  164. ```
  165. Once added, AI agents that support the `.agents/skills/` convention will automatically discover and use bilibili-cli commands.
  166. ### ~~OpenClaw / ClawHub~~ (Deprecated)
  167. > ⚠️ ClawHub install method is deprecated and no longer supported. Use [Skills CLI](#skills-cli-recommended) or Manual Install above.
  168. ## Troubleshooting
  169. - `需要登录` / `not_authenticated` — Run `bili login` to scan QR code, or ensure you're logged in to bilibili.com in Chrome/Firefox/Edge/Brave.
  170. - `HTTP 412` / `RateLimitError` — Bilibili anti-scraping triggered. Wait a moment and retry, or reduce `--max`.
  171. - `无法提取 BV 号` / `InvalidBvidError` — Check the BV ID or URL format. Must be `BV` followed by 10 alphanumeric characters.
  172. - `NetworkError` — Check your network connection. If behind a proxy, ensure it supports the target domain.
  173. - `当前登录凭证不支持写操作` — Your saved cookies lack `bili_jct`. Run `bili login` to re-authorize with full write permission.
  174. Structured error codes: `not_authenticated`, `permission_denied`, `invalid_input`, `network_error`, `upstream_error`, `not_found`, `rate_limited`, `internal_error`.
  175. ---
  176. ## 推荐项目
  177. - [xiaohongshu-cli](https://github.com/jackwener/xiaohongshu-cli) — 小红书笔记与账号工作流 CLI
  178. - [twitter-cli](https://github.com/jackwener/twitter-cli) — Twitter/X CLI 工具
  179. - [discord-cli](https://github.com/jackwener/discord-cli) — Discord 本地优先同步、检索与导出 CLI
  180. - [tg-cli](https://github.com/jackwener/tg-cli) — Telegram 本地优先同步、检索与导出 CLI
  181. ## 功能特性
  182. - 🎬 **视频** — 详情、字幕、AI 总结、评论、相关推荐
  183. - 🎵 **音频** — 提取视频音频,切分为语音识别 (ASR) 可用的 WAV 片段
  184. - 👤 **用户** — UP 主资料、视频列表、关注列表
  185. - 🔍 **搜索** — 按关键词搜索用户或视频
  186. - 🔥 **发现** — 热门视频、全站排行榜
  187. - 📰 **动态** — 关注的人的动态时间线
  188. - 📂 **收藏** — 收藏夹浏览、稍后再看、观看历史
  189. - 👍 **互动** — 点赞、投币、一键三连
  190. - 🔐 **智能认证** — 自动提取浏览器 Cookie,或扫码登录
  191. - 📊 **结构化输出** — 主要查询命令支持 `--yaml` 和 `--json`
  192. - 🤖 **更适合 Agent** — stdout 不是 TTY 时默认输出 YAML,也可以用 `OUTPUT=yaml|json|rich|auto` 覆盖
  193. - 🧱 **规范化 payload** — 结构化输出在命令层做了收口,不再直接暴露原始上游 SDK 返回
  194. ## 安装
  195. ```bash
  196. # 推荐:uv tool(快速、隔离环境)
  197. uv tool install bilibili-cli
  198. # 或者:pipx
  199. pipx install bilibili-cli
  200. # 如果需要音频提取功能
  201. uv tool install "bilibili-cli[audio]"
  202. # 或
  203. pipx install "bilibili-cli[audio]"
  204. ```
  205. 升级到最新版本:
  206. ```bash
  207. uv tool upgrade bilibili-cli
  208. # 或:pipx upgrade bilibili-cli
  209. ```
  210. > **提示:** 建议定期升级,避免因版本过旧导致的 API 调用异常。
  211. 或从源码安装:
  212. ```bash
  213. git clone git@github.com:jackwener/bilibili-cli.git
  214. cd bilibili-cli
  215. uv sync
  216. ```
  217. 开发环境验证:
  218. ```bash
  219. uv sync --extra dev
  220. uv run pytest -q
  221. uv run ruff check .
  222. uv run python -m mypy bili_cli
  223. ```
  224. 如果项目目录发生过移动,导致旧的 virtualenv wrapper 失效,可重新执行:
  225. ```bash
  226. uv sync --extra dev --reinstall
  227. ```
  228. ## 使用示例
  229. ```bash
  230. # 登录与账号
  231. bili status # 检查登录状态
  232. bili status --yaml # 结构化认证状态
  233. bili login # 扫码登录
  234. bili whoami # 查看个人信息(等级、硬币、粉丝数)
  235. bili whoami --yaml # 结构化个人信息
  236. # 视频
  237. bili video BV1ABcsztEcY # 视频详情
  238. bili video BV1ABcsztEcY --subtitle # 显示字幕(纯文本)
  239. bili video BV1ABcsztEcY --subtitle-timeline # 显示带时间线的字幕
  240. bili video BV1ABcsztEcY -st --subtitle-format srt # 导出为 SRT
  241. bili video BV1ABcsztEcY --ai # AI 总结
  242. bili video BV1ABcsztEcY --comments # 热门评论
  243. bili video BV1ABcsztEcY --related # 相关推荐
  244. bili video BV1ABcsztEcY --yaml # 适合 AI Agent 的 YAML
  245. bili video BV1ABcsztEcY --json # 规范化 JSON envelope
  246. bili video BV1ABcsztEcY --subtitle-timeline --comments --json # 额外内容也会进入 payload
  247. # 用户
  248. bili user 946974 # UP 主资料
  249. bili user "影视飓风" # 按用户名搜索
  250. bili user-videos 946974 --max 20 # 视频列表
  251. # 发现
  252. bili hot # 热门视频(第1页)
  253. bili hot --page 2 --max 10 # 第2页,前10条
  254. bili rank # 全站排行榜(3日)
  255. bili rank --day 7 --max 30 # 7日榜,前30条
  256. bili search "关键词" # 搜索用户
  257. bili search "关键词" --type video --max 5 # 搜索视频(前5条)
  258. bili search "关键词" --page 2 # 第2页结果
  259. bili feed # 动态时间线
  260. bili feed --offset 1234567890 # 使用上一页游标翻页
  261. bili my-dynamics # 我发布的动态
  262. bili dynamic-post "抽个奖,明天开奖" # 发布文字动态
  263. bili dynamic-delete 123456789012345678 # 删除单条动态
  264. # 收藏
  265. bili favorites # 收藏夹列表
  266. bili following # 关注列表
  267. bili watch-later # 稍后再看
  268. bili history # 观看历史
  269. # 音频提取
  270. bili audio BV1ABcsztEcY # 下载并切分为 25 秒 WAV 片段
  271. bili audio BV1ABcsztEcY --segment 60 # 每段 60 秒
  272. bili audio BV1ABcsztEcY --no-split # 完整 m4a,不切分
  273. bili audio BV1ABcsztEcY -o ~/data/ # 自定义输出目录
  274. # 互动
  275. bili like BV1ABcsztEcY # 点赞
  276. bili coin BV1ABcsztEcY # 投币
  277. bili triple BV1ABcsztEcY # 一键三连 🎉
  278. bili unfollow 946974 # 取消关注(按 UID)
  279. bili like BV1ABcsztEcY --json # 结构化写操作结果
  280. bili coin BV1ABcsztEcY --yaml # 结构化写操作结果
  281. ```
  282. ## 认证策略
  283. bilibili-cli 采用三级认证策略:
  284. 1. **已保存凭证** — 从 `~/.bilibili-cli/credential.json` 加载
  285. 2. **浏览器 Cookie** — 自动从 Chrome、Firefox、Edge、Brave 提取
  286. 3. **扫码登录** — `bili login` 在终端显示二维码
  287. 需要认证的命令会自动校验凭证。过期 Cookie 会自动清除;如果只是临时网络异常,不会误清本地凭证(会以 best-effort 继续尝试)。
  288. 大部分命令无需登录。字幕、收藏夹、动态和互动操作需要登录。写操作(like/coin/triple/unfollow/dynamic-post/dynamic-delete)需要可写凭证(包含 `bili_jct`)。
  289. ## 结构化输出
  290. 所有 `--json` / `--yaml` 输出都使用 [SCHEMA.md](./SCHEMA.md) 里的 envelope。
  291. 主要命令现在会返回命令层规范化后的 payload,例如:
  292. - `bili video` → `data.video`、`data.subtitle`、`data.ai_summary`、`data.comments`、`data.related`、`data.warnings`
  293. - `bili hot` / `bili rank` → `data.items`
  294. - `bili search` → 规范化后的用户或视频列表
  295. - `bili like` / `bili coin` / `bili triple` / `bili unfollow` → 标准化写操作结果
  296. 结构化错误码也区分成了 `not_authenticated`、`permission_denied`、`invalid_input`、`network_error`、`upstream_error`、`not_found` 等类型,便于脚本或 agent 做恢复和分支处理。
  297. ## AI Agent 使用建议
  298. 如果 AI Agent 需要机器可读输出,默认优先 `--yaml`:
  299. - `--yaml` 通常比格式化 JSON 更省 token
  300. - 对 agent 来说仍然容易解析
  301. - 只有在要配合 `jq` 或下游必须是 JSON 时,再使用 `--json`
  302. - stdout 不是 TTY 时会默认自动输出 YAML
  303. - 也可以用 `OUTPUT=yaml|json|rich|auto` 强制覆盖默认输出模式
  304. 示例:
  305. ```bash
  306. bili status --yaml
  307. bili video BV1ABcsztEcY --yaml
  308. bili hot --max 5 --yaml
  309. bili user-videos 946974 --max 3 --yaml
  310. ```
  311. 另外,agent 应尽量配合 `--max`、`--page`、`--offset` 缩小结果集,避免把不必要的数据带进上下文。
  312. 如果 agent 要帮用户总结视频,应该优先拉字幕。字幕通常就是视频核心内容的第一手来源,最适合做 summary;只有在没有字幕或字幕明显不足时,再退回到 AI summary、评论或音频提取。
  313. 音频提取功能需要安装可选依赖组 `audio`(即 `av`)。
  314. ## 作为 AI Agent Skill 使用
  315. bilibili-cli 自带 [`SKILL.md`](./SKILL.md),让 AI Agent 能自动学习并使用本工具。
  316. ### [Skills CLI](https://github.com/vercel-labs/skills)(推荐)
  317. ```bash
  318. npx skills add jackwener/bilibili-cli
  319. ```
  320. | 参数 | 说明 |
  321. | --- | --- |
  322. | `-g` | 全局安装(用户级别,跨项目共享) |
  323. | `-a claude-code` | 指定目标 Agent |
  324. | `-y` | 非交互模式 |
  325. ### 手动安装
  326. ```bash
  327. mkdir -p .agents/skills
  328. git clone git@github.com:jackwener/bilibili-cli.git .agents/skills/bilibili-cli
  329. ```
  330. 添加后,支持 `.agents/skills/` 的 AI Agent 会自动发现并使用 bilibili-cli 命令。
  331. ### ~~OpenClaw / ClawHub~~(已过时)
  332. > ⚠️ ClawHub 安装方式已过时,不再支持。请使用上方的 Skills CLI 或手动安装。
  333. ## 常见问题
  334. - `需要登录` — 执行 `bili login` 扫码登录,或确保已在 Chrome/Firefox/Edge/Brave 登录 bilibili.com
  335. - `HTTP 412` / `RateLimitError` — B 站反爬触发,稍等后重试,或减小 `--max`
  336. - `无法提取 BV 号` — 检查 BV 号或 URL 格式,必须是 `BV` + 10 位字母数字
  337. - `NetworkError` — 检查网络连接
  338. - `当前登录凭证不支持写操作` — 保存的 Cookie 缺少 `bili_jct`,执行 `bili login` 重新授权
  339. ## License
  340. Apache-2.0

Ratings and comments

Sign in to rate this skill.

Sign in

Free to use. If it’s helped, pass it on.