Skip to main content

A CLI for Bilibili — browse videos, users, favorites from the terminal

Project description

bilibili-cli

CI PyPI version Python versions License

A CLI for Bilibili — browse videos, users, favorites from the terminal 📺

English | 中文

More Projects

  • xhs-cli — Xiaohongshu CLI tooling
  • twitter-cli — Twitter/X CLI tooling
  • discord-cli — Discord CLI for local-first chat sync and search
  • tg-cli — Telegram CLI for local-first sync, search, and export

Features

  • 🎬 Video — details, subtitles, AI summary, comments, related videos
  • 🎵 Audio — extract audio and split into ASR-ready WAV segments
  • 👤 User — profile, video list, following list
  • 🔍 Search — search users or videos by keyword
  • 🔥 Trending — hot videos and site-wide ranking
  • 📰 Feed — dynamic timeline from your follows
  • 📂 Favorites — browse favorite folders, watch-later, and watch history
  • 👍 Interactions — like, coin, triple (一键三连)
  • 🔐 Smart auth — auto-extracts cookies from Chrome/Firefox, or QR code login
  • 📊 Structured output — major query commands support --yaml and --json

Installation

# 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]"

Or from source:

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

Run tests in the project environment:

uv run pytest -q
uv run ruff check .
uv run mypy bili_cli

Usage

# Login & account
bili status                    # Check login status
bili login                     # QR code login
bili whoami                    # Detailed profile (level, coins, followers)

# Videos
bili video BV1ABcsztEcY                 # Video details
bili video BV1ABcsztEcY --subtitle      # With subtitles (plain text)
bili video BV1ABcsztEcY --subtitle-timeline        # With timeline
bili video BV1ABcsztEcY -st --subtitle-format srt  # Export as SRT
bili video BV1ABcsztEcY --ai            # AI summary
bili video BV1ABcsztEcY --comments      # Top comments
bili video BV1ABcsztEcY --related       # Related videos
bili video BV1ABcsztEcY --yaml          # Agent-friendly YAML
bili video BV1ABcsztEcY --json          # Raw JSON

# Users
bili user 946974                        # UP profile
bili user "影视飓风"                     # Search by name
bili user-videos 946974 --max 20        # Video list

# Discovery
bili hot                                # Trending videos (page 1)
bili hot --page 2 --max 10              # Page 2, top 10
bili rank                               # Site-wide ranking (3-day)
bili rank --day 7 --max 30              # 7-day ranking, top 30
bili search "关键词"                     # Search users
bili search "关键词" --type video --max 5 # Search videos (top 5)
bili search "关键词" --page 2            # Next page
bili feed                               # Dynamic timeline
bili feed --offset 1234567890           # Next page via returned cursor
bili my-dynamics                         # My posted dynamics
bili dynamic-post "抽个奖,明天开奖"       # Publish text dynamic
bili dynamic-delete 123456789012345678   # Delete one dynamic

# Collections
bili favorites                          # Favorite folders
bili favorites <ID> --page 2            # Videos in a folder
bili following                          # Following list
bili watch-later                        # Watch later
bili history                            # Watch history

# Audio extraction
bili audio BV1ABcsztEcY                 # Download + split into 25s WAV segments
bili audio BV1ABcsztEcY --segment 60    # 60s per segment
bili audio BV1ABcsztEcY --no-split      # Full m4a, no splitting
bili audio BV1ABcsztEcY -o ~/data/      # Custom output directory

# Interactions
bili like BV1ABcsztEcY                  # Like
bili coin BV1ABcsztEcY                  # Give coin
bili triple BV1ABcsztEcY                # 一键三连 🎉
bili unfollow 946974                    # Unfollow by UID

Authentication

bilibili-cli uses a 3-tier authentication strategy:

  1. Saved credential — loads from ~/.bilibili-cli/credential.json
  2. Browser cookies — auto-extracts from Chrome, Firefox, Edge, or Brave
  3. QR code loginbili login displays a QR code in the terminal

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. bili status exits with code 0 only when authenticated; otherwise it exits with 1.

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).

Audio extraction requires the optional audio dependency group (av).

Use as AI Agent Skill

bilibili-cli ships with a SKILL.md that teaches AI agents how to use it.

Agent Output Recommendation

If an AI agent needs machine-readable output, prefer --yaml first:

  • --yaml is usually more token-efficient than pretty-printed JSON
  • It is still easy to parse for agents and scripts
  • Keep --json for jq, strict JSON-only tooling, or exact downstream schemas

Examples:

bili video BV1ABcsztEcY --yaml
bili hot --max 5 --yaml
bili user-videos 946974 --max 3 --yaml

For agent usage, also prefer narrower queries (--max, --page, --offset) to avoid wasting context on oversized payloads.

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.

Claude Code / Antigravity

# Clone into your project's skills directory
mkdir -p .agents/skills
git clone git@github.com:jackwener/bilibili-cli.git .agents/skills/bilibili-cli

# Or just copy the SKILL.md
curl -o .agents/skills/bilibili-cli/SKILL.md \
  https://raw.githubusercontent.com/jackwener/bilibili-cli/main/SKILL.md

Once added, AI agents that support the .agents/skills/ convention will automatically discover and use bilibili-cli commands.

OpenClaw / ClawHub

Officially supports OpenClaw and ClawHub. Install via ClawHub:

clawhub install bilibili-cli

All bilibili-cli commands are available in OpenClaw after installation.


推荐项目

  • xhs-cli — 小红书 CLI 工具
  • twitter-cli — Twitter/X CLI 工具
  • discord-cli — Discord 本地优先同步、检索与导出 CLI
  • tg-cli — Telegram 本地优先同步、检索与导出 CLI

功能特性

  • 🎬 视频 — 详情、字幕、AI 总结、评论、相关推荐
  • 🎵 音频 — 提取视频音频,切分为语音识别 (ASR) 可用的 WAV 片段
  • 👤 用户 — UP 主资料、视频列表、关注列表
  • 🔍 搜索 — 按关键词搜索用户或视频
  • 🔥 发现 — 热门视频、全站排行榜
  • 📰 动态 — 关注的人的动态时间线
  • 📂 收藏 — 收藏夹浏览、稍后再看、观看历史
  • 👍 互动 — 点赞、投币、一键三连
  • 🔐 智能认证 — 自动提取浏览器 Cookie,或扫码登录
  • 📊 结构化输出 — 主要查询命令支持 --yaml--json

安装

# 推荐:uv tool(快速、隔离环境)
uv tool install bilibili-cli

# 或者:pipx
pipx install bilibili-cli

# 如果需要音频提取功能
uv tool install "bilibili-cli[audio]"
# 或
pipx install "bilibili-cli[audio]"

或从源码安装:

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

使用示例

# 登录与账号
bili status                    # 检查登录状态
bili login                     # 扫码登录
bili whoami                    # 查看个人信息(等级、硬币、粉丝数)

# 视频
bili video BV1ABcsztEcY                 # 视频详情
bili video BV1ABcsztEcY --subtitle      # 显示字幕(纯文本)
bili video BV1ABcsztEcY --subtitle-timeline        # 显示带时间线的字幕
bili video BV1ABcsztEcY -st --subtitle-format srt  # 导出为 SRT
bili video BV1ABcsztEcY --ai            # AI 总结
bili video BV1ABcsztEcY --comments      # 热门评论
bili video BV1ABcsztEcY --related       # 相关推荐
bili video BV1ABcsztEcY --yaml          # 适合 AI Agent 的 YAML
bili video BV1ABcsztEcY --json          # 原始 JSON

# 用户
bili user 946974                        # UP 主资料
bili user "影视飓风"                     # 按用户名搜索
bili user-videos 946974 --max 20        # 视频列表

# 发现
bili hot                                # 热门视频(第1页)
bili hot --page 2 --max 10              # 第2页,前10条
bili rank                               # 全站排行榜(3日)
bili rank --day 7 --max 30              # 7日榜,前30条
bili search "关键词"                     # 搜索用户
bili search "关键词" --type video --max 5 # 搜索视频(前5条)
bili search "关键词" --page 2            # 第2页结果
bili feed                               # 动态时间线
bili feed --offset 1234567890           # 使用上一页游标翻页
bili my-dynamics                         # 我发布的动态
bili dynamic-post "抽个奖,明天开奖"       # 发布文字动态
bili dynamic-delete 123456789012345678   # 删除单条动态

# 收藏
bili favorites                          # 收藏夹列表
bili following                          # 关注列表
bili watch-later                        # 稍后再看
bili history                            # 观看历史

# 音频提取
bili audio BV1ABcsztEcY                 # 下载并切分为 25 秒 WAV 片段
bili audio BV1ABcsztEcY --segment 60    # 每段 60 秒
bili audio BV1ABcsztEcY --no-split      # 完整 m4a,不切分
bili audio BV1ABcsztEcY -o ~/data/      # 自定义输出目录

# 互动
bili like BV1ABcsztEcY                  # 点赞
bili coin BV1ABcsztEcY                  # 投币
bili triple BV1ABcsztEcY                # 一键三连 🎉
bili unfollow 946974                    # 取消关注(按 UID)

认证策略

bilibili-cli 采用三级认证策略:

  1. 已保存凭证 — 从 ~/.bilibili-cli/credential.json 加载
  2. 浏览器 Cookie — 自动从 Chrome、Firefox、Edge、Brave 提取
  3. 扫码登录bili login 在终端显示二维码

需要认证的命令会自动校验凭证。过期 Cookie 会自动清除;如果只是临时网络异常,不会误清本地凭证(会以 best-effort 继续尝试)。

大部分命令无需登录。字幕、收藏夹、动态和互动操作需要登录。写操作(like/coin/triple/unfollow/dynamic-post/dynamic-delete)需要可写凭证(包含 bili_jct)。

AI Agent 使用建议

如果 AI Agent 需要机器可读输出,默认优先 --yaml

  • --yaml 通常比格式化 JSON 更省 token
  • 对 agent 来说仍然容易解析
  • 只有在要配合 jq 或下游必须是 JSON 时,再使用 --json

示例:

bili video BV1ABcsztEcY --yaml
bili hot --max 5 --yaml
bili user-videos 946974 --max 3 --yaml

另外,agent 应尽量配合 --max--page--offset 缩小结果集,避免把不必要的数据带进上下文。

如果 agent 要帮用户总结视频,应该优先拉字幕。字幕通常就是视频核心内容的第一手来源,最适合做 summary;只有在没有字幕或字幕明显不足时,再退回到 AI summary、评论或音频提取。

音频提取功能需要安装可选依赖组 audio(即 av)。

作为 AI Agent Skill 使用

bilibili-cli 自带 SKILL.md,让 AI Agent 能自动学习并使用本工具。

Claude Code / Antigravity

# 克隆到项目的 skills 目录
mkdir -p .agents/skills
git clone git@github.com:jackwener/bilibili-cli.git .agents/skills/bilibili-cli

# 或者只复制 SKILL.md
curl -o .agents/skills/bilibili-cli/SKILL.md \
  https://raw.githubusercontent.com/jackwener/bilibili-cli/main/SKILL.md

添加后,支持 .agents/skills/ 的 AI Agent 会自动发现并使用 bilibili-cli 命令。

OpenClaw / ClawHub

官方支持 OpenClawClawHub 生态。通过 ClawHub 安装:

clawhub install bilibili-cli

安装后即可在 OpenClaw 中直接使用所有 bilibili-cli 命令。

License

Apache-2.0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bilibili_cli-0.5.0.tar.gz (178.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

bilibili_cli-0.5.0-py3-none-any.whl (40.0 kB view details)

Uploaded Python 3

File details

Details for the file bilibili_cli-0.5.0.tar.gz.

File metadata

  • Download URL: bilibili_cli-0.5.0.tar.gz
  • Upload date:
  • Size: 178.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for bilibili_cli-0.5.0.tar.gz
Algorithm Hash digest
SHA256 e2ab118448b328e7f7eb514b3215e3c7ca432ef41b237a572ef413fd3a05e78b
MD5 1672eb93b7732266780d6a88b8fb2598
BLAKE2b-256 bd1814866f67f3e470184b96a554e945f8517ebe1c6605b624e2e19177a56249

See more details on using hashes here.

Provenance

The following attestation bundles were made for bilibili_cli-0.5.0.tar.gz:

Publisher: publish.yml on jackwener/bilibili-cli

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bilibili_cli-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: bilibili_cli-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 40.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for bilibili_cli-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ef5cc093d1d50810c0ff366a886e154cffd0d9371dafa5802625993bbca99dee
MD5 672cad427c9b0c5cc6e085d1d0b5538f
BLAKE2b-256 7fdaf53aa21c29ce4a44d390f740ba77e1bb8c1cf3f68c3d0c28d2b37459b78e

See more details on using hashes here.

Provenance

The following attestation bundles were made for bilibili_cli-0.5.0-py3-none-any.whl:

Publisher: publish.yml on jackwener/bilibili-cli

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page