B2A (Bilibili to Agents) — 让 AI Agent 能「观看」B站视频
Project description
B2A (Bilibili to Agents)
让 AI Agent 能「观看」B站视频的多模态内容提取工具。
解决什么问题
AI Agent(如 Claude Code、Cursor 等)可以访问网页,但无法真正「观看」视频。当用户想让 Agent 分析某个 B 站视频的内容时,Agent 无从下手。
B2A 提供了三条互补的信息获取轨道:
- CC 字幕 — 最快速,直接拉取视频自带的字幕文本(含时间戳)
- ASR 语音识别(声) — 通过豆包语音大模型将音频转为带时间戳的文字,解决 B 站大量视频无 CC 字幕的问题
- 视觉抽帧(形) — 下载视频并按间隔截取关键帧图片,让 Agent 能「看到」画面内容
三条轨道可任意组合,支持全视频或指定时间片段。
安装
1. 安装 ffmpeg(前置依赖)
--visual 抽帧和 --asr 切片功能依赖 ffmpeg,版本需 5.0 以上。
Windows:
# 方式一:winget(Windows 11 自带,推荐)
winget install Gyan.FFmpeg
# 方式二:scoop
scoop install ffmpeg
安装后打开新的终端窗口,验证:
ffmpeg -version
# 应显示 ffmpeg version 5.x 或更高
如果提示找不到命令,需要将 ffmpeg 的 bin 目录加入系统 PATH 环境变量。
macOS:
brew install ffmpeg
Linux(Debian/Ubuntu):
sudo apt update && sudo apt install ffmpeg
2. 安装 B2A
# 克隆仓库
git clone https://github.com/fanzhongli/B2A.git
cd B2A
# 安装
pip install -e .
安装完成后即可使用 b2a 命令。
快速上手
基础用法:获取视频信息 + CC 字幕
b2a BV1xx411c7mD
语音识别(ASR)
# 全视频 ASR
b2a BV1xx411c7mD --asr
# 指定片段 ASR(3分20秒到4分50秒)
b2a BV1xx411c7mD --asr --start 03:20 --end 04:50
视觉抽帧
# 全视频抽帧(每10秒一张)
b2a BV1xx411c7mD --visual
# 指定片段抽帧
b2a BV1xx411c7mD --visual --start 01:00 --end 02:30
声形同时获取
b2a BV1xx411c7mD --asr --visual --start 03:20 --end 04:50
分P视频
# 指定第3个分P
b2a BV1xx411c7mD --page 3 --asr
多种输入格式
# 完整链接(自动提取 BV 号、分P、时间跳转)
b2a "https://www.bilibili.com/video/BV1xx411c7mD?p=2&t=180"
# b23.tv 短链
b2a "https://b23.tv/xxxxxx"
# AV 号
b2a av170001
JSON 结构化输出(供 Agent 消费)
b2a BV1xx411c7mD --asr --format json
ASR 配置
ASR 功能依赖豆包语音(火山引擎)API Key。不配置时,CC 字幕和视觉抽帧功能仍可正常使用。
- 复制配置模板:
cp .env.example .env
- 编辑
.env,填入你的 API Key:
VOLC_ENV=test
VOLC_TEST_API_KEY=你的测试环境API_Key
VOLC_PROD_API_KEY=你的生产环境API_Key
CLI 参数一览
b2a <url> [选项]
位置参数:
url B站视频URL、BV号或AV号
选项:
--asr 启用语音识别(提取音频轨并转文字)
--visual 启用视觉提取(抽取视频关键帧截图)
--start TIME 截取开始时间(如 01:30 或 1:03:20)
--end TIME 截取结束时间(如 02:40 或 1:05:00)
--page N 指定分P编号(从1开始)
--format {text,json} 输出格式(默认 text)
项目结构
B2A/
├── src/
│ ├── cli.py # CLI 入口
│ ├── core/
│ │ ├── api.py # B站 API(视频信息、字幕、分P)
│ │ └── asr.py # 火山引擎 ASR(含长音频自动分片)
│ ├── audio/
│ │ └── extractor.py # 音频提取(yt-dlp)
│ ├── visual/
│ │ └── extractor.py # 视觉提取(yt-dlp 下载 + ffmpeg 抽帧)
│ └── utils/
│ ├── config.py # 环境变量与鉴权
│ ├── url_parser.py # URL 解析(短链/BV/AV/分P/时间)
│ └── workspace.py # 工作区目录管理(按视频隔离)
├── tests/ # 测试用例(26个)
├── pyproject.toml # 打包配置
├── requirements.txt # 依赖清单
└── .env.example # 环境变量模板
运行测试
pip install -e ".[dev]"
pytest tests/ -v
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file b2a777-0.3.2.tar.gz.
File metadata
- Download URL: b2a777-0.3.2.tar.gz
- Upload date:
- Size: 18.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0b0d98db67da027e388451ef71647cc2f3b68653d97872f6bb289bd216fc8be4
|
|
| MD5 |
b7cdad3bad35b2feec647a1b99ef3e38
|
|
| BLAKE2b-256 |
ccce76c3d73c0b544ba19cf93fb41869cd3e9d08f99688ef2d51de6a1ae7a9de
|
Provenance
The following attestation bundles were made for b2a777-0.3.2.tar.gz:
Publisher:
publish.yml on e8b298/B2A
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
b2a777-0.3.2.tar.gz -
Subject digest:
0b0d98db67da027e388451ef71647cc2f3b68653d97872f6bb289bd216fc8be4 - Sigstore transparency entry: 1012965181
- Sigstore integration time:
-
Permalink:
e8b298/B2A@154684ac7487058bc347b18fc1b49d8a4e71e497 -
Branch / Tag:
refs/tags/v0.3.2 - Owner: https://github.com/e8b298
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@154684ac7487058bc347b18fc1b49d8a4e71e497 -
Trigger Event:
push
-
Statement type:
File details
Details for the file b2a777-0.3.2-py3-none-any.whl.
File metadata
- Download URL: b2a777-0.3.2-py3-none-any.whl
- Upload date:
- Size: 19.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d4b862274e937d0ac5a437b6a3c3b8e5258fe122dc8362bfb2530d94e0bc12c5
|
|
| MD5 |
bb9e6f4c372367b80287bf7d6f87d8c9
|
|
| BLAKE2b-256 |
f5d67bcd8bd186f58caeb4b6ad4093a0b70f06a7bf315d86269bb5ebb33b0f3f
|
Provenance
The following attestation bundles were made for b2a777-0.3.2-py3-none-any.whl:
Publisher:
publish.yml on e8b298/B2A
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
b2a777-0.3.2-py3-none-any.whl -
Subject digest:
d4b862274e937d0ac5a437b6a3c3b8e5258fe122dc8362bfb2530d94e0bc12c5 - Sigstore transparency entry: 1012965253
- Sigstore integration time:
-
Permalink:
e8b298/B2A@154684ac7487058bc347b18fc1b49d8a4e71e497 -
Branch / Tag:
refs/tags/v0.3.2 - Owner: https://github.com/e8b298
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@154684ac7487058bc347b18fc1b49d8a4e71e497 -
Trigger Event:
push
-
Statement type: