关于 bilibili-cli
bilibili-cli 是供 Agent 使用的 Bilibili 命令行工具,可查询视频、搜索内容、浏览用户资料并执行互动操作。它提供 YAML 和 JSON 结构化输出,并建议优先读取字幕来分析视频。
主要功能
- 01查询视频信息与字幕
- 02搜索视频和用户
- 03浏览热门、排行及动态
- 04查看用户资料与投稿
- 05点赞、投币和收藏
- 06导出 YAML 或 JSON
适用场景
- 01搜索指定主题的视频
- 02读取字幕并总结视频内容
- 03研究 UP 主及其近期投稿
- 04管理收藏、稍后观看和观看历史
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ public-clis/ bilibili-cli --skill bilibili-cli安装后在 Claude Code 中输入/bilibili-cli确认已加载。
包含的文件
除 SKILL.md 外,安装时一起下载的参考资料和脚本。
LICENSEREADME.mdCHANGELOG.md.gitignoreSCHEMA.mdpyproject.toml.github/ISSUE_TEMPLATE/feature_request.ymlbug_report.yml.github/workflows/publish.ymlci.ymlbili_cli/__init__.pyauth.pycli.pyclient.pypayloads.pyformatter.pyexceptions.pybili_cli/commands/__init__.pycollections.pycommon.pyaudio.pyaccount.pyinteractions.pydiscovery.pyuser_search.pyvideo.pytests/conftest.pytest_audio.pytest_cli.pytest_auth.py详细介绍
bilibili-cli 技能
用于与 Bilibili(哔哩哔哩)交互的命令行工具。可用于获取视频信息、搜索内容、浏览用户主页,以及执行点赞或三连等互动操作。
Agent 默认设置
需要机器可读的输出时:
- 优先使用
--yaml,因为它通常比格式化 JSON 更节省 token。 - 仅在下游工具严格要求 JSON 时使用
--json。 - 使用
--max、--page或--offset控制结果集的大小。 - 优先使用具体命令,而不是宽泛的命令。例如,使用
bili user-videos 946974 --max 3 --yaml,而不是获取大量时间线内容。 - 总结视频时,先获取字幕。字幕通常包含视频的核心内容,是总结时最好的主要来源。
- 仅当字幕不可用或明显不足时,才使用
--ai、评论或音频提取作为备用方案。
前置条件
# Install (requires Python 3.10+)
uv tool install bilibili-cli
# Or: pipx install bilibili-cli
# If you need audio extraction support (requires PyAV)
uv tool install "bilibili-cli[audio]"
# Or: pipx install "bilibili-cli[audio]"
# Upgrade to latest (recommended to avoid API errors)
uv tool upgrade bilibili-cli
# Or: pipx upgrade bilibili-cli
身份验证
大多数读取命令无需登录。字幕、收藏夹/关注/稍后再看/历史记录、动态和互动操作需要登录。
bili status # Check if logged in (exit 0 = yes, 1 = no)
bili login # QR code login (if not authenticated)
身份验证会自动检测本地浏览器 Cookie(Chrome/Firefox/Edge/Brave)。如果找到有效 Cookie,则无需手动登录。凭据会保存到 ~/.bilibili-cli/credential.json。
命令参考
视频
# Get video details (accepts BV ID or full URL)
bili video BV1ABcsztEcY
bili video https://www.bilibili.com/video/BV1ABcsztEcY
# Options
bili video BV1ABcsztEcY --subtitle # Show subtitles (plain text)
bili video BV1ABcsztEcY --subtitle-timeline # Show subtitles with timestamps
bili video BV1ABcsztEcY -st --subtitle-format srt # Export as SRT format
bili video BV1ABcsztEcY --ai # Show B站 AI summary
bili video BV1ABcsztEcY --comments # Show top comments
bili video BV1ABcsztEcY --related # Show related videos
bili video BV1ABcsztEcY --yaml # Token-efficient YAML output
bili video BV1ABcsztEcY --json # Structured JSON envelope
用户
# Look up user profile (by UID or username)
bili user 946974
bili user "影视飓风"
# List user's videos
bili user-videos 946974 --max 20
bili user-videos "影视飓风" --yaml
搜索
# Search users (default)
bili search "关键词"
# Search videos
bili search "关键词" --type video
# Pagination and limit
bili search "关键词" --type video --max 5
bili search "关键词" --page 2
发现
bili hot # Trending/popular videos
bili hot --page 2 --max 10 # Page 2, limit 10
bili rank # Site-wide ranking (3-day)
bili rank --day 7 --max 30 # 7-day ranking, top 30
bili feed # Dynamic timeline (requires login)
bili feed --offset 1234567890 # Next page via returned cursor
bili my-dynamics # My posted dynamics (requires login)
bili dynamic-post "hello" # Publish text dynamic (requires write credential)
bili dynamic-delete 123456789 # Delete one dynamic (requires write credential)
收藏集(需要登录)
bili favorites # List favorite folders
bili favorites <ID> --page 2 # Videos in a folder
bili following # Following list
bili watch-later # Watch later list
bili history # Watch history
音频提取
需要安装 bilibili-cli[audio] 扩展(PyAV)。使用 uv tool install "bilibili-cli[audio]" 安装。
# Download audio and split into ASR-ready WAV segments (25s each, 16kHz mono)
bili audio BV1ABcsztEcY # Split to /tmp/bilibili-cli/{title}/
bili audio BV1ABcsztEcY --segment 60 # 60s per segment
bili audio BV1ABcsztEcY --no-split # Full m4a file, no splitting
bili audio BV1ABcsztEcY -o ~/data/ # Custom output directory
互动操作(需要登录)
bili like BV1ABcsztEcY # Like a video
bili like BV1ABcsztEcY --undo # Unlike
bili coin BV1ABcsztEcY # Give 1 coin
bili coin BV1ABcsztEcY -n 2 # Give 2 coins
bili triple BV1ABcsztEcY # 一键三连 (like + coin + favorite)
bili unfollow 946974 # Unfollow by UID
账号
bili status # Quick login check
bili status --yaml # Structured auth status
bili whoami # Detailed profile info
bili whoami --yaml # Profile as YAML
bili whoami --json # Profile as JSON
bili login # QR code login
bili logout # Clear credentials
结构化输出
主要查询命令支持使用 --yaml 和 --json 输出机器可读内容。供 Agent 使用时,优先选择 YAML:
bili status --yaml # Quick structured auth check
bili video BV1ABcsztEcY --yaml # Preferred for AI agents
bili hot --max 5 --yaml # Smaller, token-efficient payload
bili user 946974 --json | jq -r '.data.user.name' # JSON when jq is needed
当标准输出不是 TTY 时,bilibili-cli 会自动默认使用 YAML。
使用 OUTPUT=yaml|json|rich|auto 可覆盖默认输出模式。
所有机器可读输出均使用 SCHEMA.md 中记录的封装格式。
调试
bili -v <command> # Enable verbose/debug logging for any command
AI Agent 常见用法
# For video summarization, fetch subtitles first
bili video BV1ABcsztEcY --subtitle
# Only use AI summary as a fallback or secondary signal
bili video BV1ABcsztEcY --ai
# Get comments for sentiment analysis
bili video BV1ABcsztEcY --comments
# Extract audio for speech-to-text (ASR)
# Segments are saved to /tmp/bilibili-cli/{title}/seg_000.wav, seg_001.wav, ...
bili audio BV1ABcsztEcY --segment 25
# Find a user's latest video BV ID with minimal payload
bili user-videos 946974 --max 1 --yaml
# Check if logged in before performing actions
bili status && bili like BV1ABcsztEcY
# Search and inspect the first few results
bili search "topic" --type video --max 3 --yaml
工作流:视频内容分析
# 1. Search for a topic
bili search "AI" --type video --max 5
# 2. Get subtitles first for summarization
bili video BV1xxx --subtitle
# 3. If subtitles are missing or incomplete, try AI summary
bili video BV1xxx --ai
# 4. If there is still not enough content, extract audio for ASR
bili audio BV1xxx --segment 25
# 5. Get comments for audience reaction
bili video BV1xxx --comments
工作流:UP主调研
# 1. Look up UP主 profile
bili user "影视飓风"
# 2. Get their recent videos
bili user-videos 946974 --max 10
# 3. Inspect a specific video
bili video BV1xxx --ai --comments
错误处理
- 命令成功时以代码 0 退出,失败时以非零代码退出
- 错误消息以 ❌ 开头
- 需要登录的命令会显示 ⚠️,并提示运行
bili login - 无效的 BV ID 会显示明确的错误消息
安全注意事项
- 不要要求用户在聊天记录中分享原始凭据或 Cookie 值。
- 优先提取本地浏览器 Cookie,而不是手动复制粘贴机密信息。
- 如果身份验证失败,请让用户通过
bili login重新登录。
评论
支持 Markdown