b2a777 0.3.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- b2a777-0.3.2/LICENSE +21 -0
- b2a777-0.3.2/PKG-INFO +226 -0
- b2a777-0.3.2/README.md +192 -0
- b2a777-0.3.2/b2a777.egg-info/PKG-INFO +226 -0
- b2a777-0.3.2/b2a777.egg-info/SOURCES.txt +30 -0
- b2a777-0.3.2/b2a777.egg-info/dependency_links.txt +1 -0
- b2a777-0.3.2/b2a777.egg-info/entry_points.txt +2 -0
- b2a777-0.3.2/b2a777.egg-info/requires.txt +9 -0
- b2a777-0.3.2/b2a777.egg-info/top_level.txt +1 -0
- b2a777-0.3.2/pyproject.toml +53 -0
- b2a777-0.3.2/setup.cfg +4 -0
- b2a777-0.3.2/src/__init__.py +0 -0
- b2a777-0.3.2/src/audio/__init__.py +3 -0
- b2a777-0.3.2/src/audio/extractor.py +116 -0
- b2a777-0.3.2/src/cli.py +237 -0
- b2a777-0.3.2/src/core/__init__.py +0 -0
- b2a777-0.3.2/src/core/api.py +129 -0
- b2a777-0.3.2/src/core/asr.py +227 -0
- b2a777-0.3.2/src/utils/__init__.py +1 -0
- b2a777-0.3.2/src/utils/config.py +28 -0
- b2a777-0.3.2/src/utils/url_parser.py +98 -0
- b2a777-0.3.2/src/utils/workspace.py +33 -0
- b2a777-0.3.2/src/visual/__init__.py +0 -0
- b2a777-0.3.2/src/visual/extractor.py +133 -0
- b2a777-0.3.2/tests/test_api.py +24 -0
- b2a777-0.3.2/tests/test_asr.py +65 -0
- b2a777-0.3.2/tests/test_audio_extractor.py +16 -0
- b2a777-0.3.2/tests/test_cli.py +6 -0
- b2a777-0.3.2/tests/test_config.py +35 -0
- b2a777-0.3.2/tests/test_extractor.py +50 -0
- b2a777-0.3.2/tests/test_url_parser.py +47 -0
- b2a777-0.3.2/tests/test_workspace.py +48 -0
b2a777-0.3.2/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 BiliVision-Agent Contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
b2a777-0.3.2/PKG-INFO
ADDED
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: b2a777
|
|
3
|
+
Version: 0.3.2
|
|
4
|
+
Summary: B2A (Bilibili to Agents) — 让 AI Agent 能「观看」B站视频
|
|
5
|
+
Author: fanzhongli
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/e8b298/B2A
|
|
8
|
+
Project-URL: Repository, https://github.com/e8b298/B2A.git
|
|
9
|
+
Project-URL: Bug-Tracker, https://github.com/e8b298/B2A/issues
|
|
10
|
+
Keywords: bilibili,agent,ai,subtitle,asr,video,multimodal
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Environment :: Console
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Topic :: Multimedia :: Video
|
|
21
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
22
|
+
Requires-Python: >=3.10
|
|
23
|
+
Description-Content-Type: text/markdown
|
|
24
|
+
License-File: LICENSE
|
|
25
|
+
Requires-Dist: httpx>=0.25.0
|
|
26
|
+
Requires-Dist: yt-dlp>=2024.0.0
|
|
27
|
+
Requires-Dist: python-dotenv>=1.0.0
|
|
28
|
+
Provides-Extra: dev
|
|
29
|
+
Requires-Dist: pytest>=8.0.0; extra == "dev"
|
|
30
|
+
Requires-Dist: pytest-asyncio>=0.23.0; extra == "dev"
|
|
31
|
+
Requires-Dist: build>=1.0.0; extra == "dev"
|
|
32
|
+
Requires-Dist: twine>=5.0.0; extra == "dev"
|
|
33
|
+
Dynamic: license-file
|
|
34
|
+
|
|
35
|
+
# B2A (Bilibili to Agents)
|
|
36
|
+
|
|
37
|
+
让 AI Agent 能「观看」B站视频的多模态内容提取工具。
|
|
38
|
+
|
|
39
|
+
## 解决什么问题
|
|
40
|
+
|
|
41
|
+
AI Agent(如 Claude Code、Cursor 等)可以访问网页,但无法真正「观看」视频。当用户想让 Agent 分析某个 B 站视频的内容时,Agent 无从下手。
|
|
42
|
+
|
|
43
|
+
B2A 提供了三条互补的信息获取轨道:
|
|
44
|
+
|
|
45
|
+
- CC 字幕 — 最快速,直接拉取视频自带的字幕文本(含时间戳)
|
|
46
|
+
- ASR 语音识别(声) — 通过豆包语音大模型将音频转为带时间戳的文字,解决 B 站大量视频无 CC 字幕的问题
|
|
47
|
+
- 视觉抽帧(形) — 下载视频并按间隔截取关键帧图片,让 Agent 能「看到」画面内容
|
|
48
|
+
|
|
49
|
+
三条轨道可任意组合,支持全视频或指定时间片段。
|
|
50
|
+
|
|
51
|
+
## 安装
|
|
52
|
+
|
|
53
|
+
### 1. 安装 ffmpeg(前置依赖)
|
|
54
|
+
|
|
55
|
+
`--visual` 抽帧和 `--asr` 切片功能依赖 ffmpeg,版本需 5.0 以上。
|
|
56
|
+
|
|
57
|
+
Windows:
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
# 方式一:winget(Windows 11 自带,推荐)
|
|
61
|
+
winget install Gyan.FFmpeg
|
|
62
|
+
|
|
63
|
+
# 方式二:scoop
|
|
64
|
+
scoop install ffmpeg
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
安装后打开新的终端窗口,验证:
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
ffmpeg -version
|
|
71
|
+
# 应显示 ffmpeg version 5.x 或更高
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
如果提示找不到命令,需要将 ffmpeg 的 bin 目录加入系统 PATH 环境变量。
|
|
75
|
+
|
|
76
|
+
macOS:
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
brew install ffmpeg
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Linux(Debian/Ubuntu):
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
sudo apt update && sudo apt install ffmpeg
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### 2. 安装 B2A
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
# 克隆仓库
|
|
92
|
+
git clone https://github.com/fanzhongli/B2A.git
|
|
93
|
+
cd B2A
|
|
94
|
+
|
|
95
|
+
# 安装
|
|
96
|
+
pip install -e .
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
安装完成后即可使用 `b2a` 命令。
|
|
100
|
+
|
|
101
|
+
## 快速上手
|
|
102
|
+
|
|
103
|
+
### 基础用法:获取视频信息 + CC 字幕
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
b2a BV1xx411c7mD
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### 语音识别(ASR)
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
# 全视频 ASR
|
|
113
|
+
b2a BV1xx411c7mD --asr
|
|
114
|
+
|
|
115
|
+
# 指定片段 ASR(3分20秒到4分50秒)
|
|
116
|
+
b2a BV1xx411c7mD --asr --start 03:20 --end 04:50
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### 视觉抽帧
|
|
120
|
+
|
|
121
|
+
```bash
|
|
122
|
+
# 全视频抽帧(每10秒一张)
|
|
123
|
+
b2a BV1xx411c7mD --visual
|
|
124
|
+
|
|
125
|
+
# 指定片段抽帧
|
|
126
|
+
b2a BV1xx411c7mD --visual --start 01:00 --end 02:30
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### 声形同时获取
|
|
130
|
+
|
|
131
|
+
```bash
|
|
132
|
+
b2a BV1xx411c7mD --asr --visual --start 03:20 --end 04:50
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### 分P视频
|
|
136
|
+
|
|
137
|
+
```bash
|
|
138
|
+
# 指定第3个分P
|
|
139
|
+
b2a BV1xx411c7mD --page 3 --asr
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
### 多种输入格式
|
|
143
|
+
|
|
144
|
+
```bash
|
|
145
|
+
# 完整链接(自动提取 BV 号、分P、时间跳转)
|
|
146
|
+
b2a "https://www.bilibili.com/video/BV1xx411c7mD?p=2&t=180"
|
|
147
|
+
|
|
148
|
+
# b23.tv 短链
|
|
149
|
+
b2a "https://b23.tv/xxxxxx"
|
|
150
|
+
|
|
151
|
+
# AV 号
|
|
152
|
+
b2a av170001
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### JSON 结构化输出(供 Agent 消费)
|
|
156
|
+
|
|
157
|
+
```bash
|
|
158
|
+
b2a BV1xx411c7mD --asr --format json
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
## ASR 配置
|
|
162
|
+
|
|
163
|
+
ASR 功能依赖豆包语音(火山引擎)API Key。不配置时,CC 字幕和视觉抽帧功能仍可正常使用。
|
|
164
|
+
|
|
165
|
+
1. 复制配置模板:
|
|
166
|
+
```bash
|
|
167
|
+
cp .env.example .env
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
2. 编辑 `.env`,填入你的 API Key:
|
|
171
|
+
```env
|
|
172
|
+
VOLC_ENV=test
|
|
173
|
+
VOLC_TEST_API_KEY=你的测试环境API_Key
|
|
174
|
+
VOLC_PROD_API_KEY=你的生产环境API_Key
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
## CLI 参数一览
|
|
178
|
+
|
|
179
|
+
```
|
|
180
|
+
b2a <url> [选项]
|
|
181
|
+
|
|
182
|
+
位置参数:
|
|
183
|
+
url B站视频URL、BV号或AV号
|
|
184
|
+
|
|
185
|
+
选项:
|
|
186
|
+
--asr 启用语音识别(提取音频轨并转文字)
|
|
187
|
+
--visual 启用视觉提取(抽取视频关键帧截图)
|
|
188
|
+
--start TIME 截取开始时间(如 01:30 或 1:03:20)
|
|
189
|
+
--end TIME 截取结束时间(如 02:40 或 1:05:00)
|
|
190
|
+
--page N 指定分P编号(从1开始)
|
|
191
|
+
--format {text,json} 输出格式(默认 text)
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
## 项目结构
|
|
195
|
+
|
|
196
|
+
```
|
|
197
|
+
B2A/
|
|
198
|
+
├── src/
|
|
199
|
+
│ ├── cli.py # CLI 入口
|
|
200
|
+
│ ├── core/
|
|
201
|
+
│ │ ├── api.py # B站 API(视频信息、字幕、分P)
|
|
202
|
+
│ │ └── asr.py # 火山引擎 ASR(含长音频自动分片)
|
|
203
|
+
│ ├── audio/
|
|
204
|
+
│ │ └── extractor.py # 音频提取(yt-dlp)
|
|
205
|
+
│ ├── visual/
|
|
206
|
+
│ │ └── extractor.py # 视觉提取(yt-dlp 下载 + ffmpeg 抽帧)
|
|
207
|
+
│ └── utils/
|
|
208
|
+
│ ├── config.py # 环境变量与鉴权
|
|
209
|
+
│ ├── url_parser.py # URL 解析(短链/BV/AV/分P/时间)
|
|
210
|
+
│ └── workspace.py # 工作区目录管理(按视频隔离)
|
|
211
|
+
├── tests/ # 测试用例(26个)
|
|
212
|
+
├── pyproject.toml # 打包配置
|
|
213
|
+
├── requirements.txt # 依赖清单
|
|
214
|
+
└── .env.example # 环境变量模板
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
## 运行测试
|
|
218
|
+
|
|
219
|
+
```bash
|
|
220
|
+
pip install -e ".[dev]"
|
|
221
|
+
pytest tests/ -v
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
## License
|
|
225
|
+
|
|
226
|
+
MIT
|
b2a777-0.3.2/README.md
ADDED
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
# B2A (Bilibili to Agents)
|
|
2
|
+
|
|
3
|
+
让 AI Agent 能「观看」B站视频的多模态内容提取工具。
|
|
4
|
+
|
|
5
|
+
## 解决什么问题
|
|
6
|
+
|
|
7
|
+
AI Agent(如 Claude Code、Cursor 等)可以访问网页,但无法真正「观看」视频。当用户想让 Agent 分析某个 B 站视频的内容时,Agent 无从下手。
|
|
8
|
+
|
|
9
|
+
B2A 提供了三条互补的信息获取轨道:
|
|
10
|
+
|
|
11
|
+
- CC 字幕 — 最快速,直接拉取视频自带的字幕文本(含时间戳)
|
|
12
|
+
- ASR 语音识别(声) — 通过豆包语音大模型将音频转为带时间戳的文字,解决 B 站大量视频无 CC 字幕的问题
|
|
13
|
+
- 视觉抽帧(形) — 下载视频并按间隔截取关键帧图片,让 Agent 能「看到」画面内容
|
|
14
|
+
|
|
15
|
+
三条轨道可任意组合,支持全视频或指定时间片段。
|
|
16
|
+
|
|
17
|
+
## 安装
|
|
18
|
+
|
|
19
|
+
### 1. 安装 ffmpeg(前置依赖)
|
|
20
|
+
|
|
21
|
+
`--visual` 抽帧和 `--asr` 切片功能依赖 ffmpeg,版本需 5.0 以上。
|
|
22
|
+
|
|
23
|
+
Windows:
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
# 方式一:winget(Windows 11 自带,推荐)
|
|
27
|
+
winget install Gyan.FFmpeg
|
|
28
|
+
|
|
29
|
+
# 方式二:scoop
|
|
30
|
+
scoop install ffmpeg
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
安装后打开新的终端窗口,验证:
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
ffmpeg -version
|
|
37
|
+
# 应显示 ffmpeg version 5.x 或更高
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
如果提示找不到命令,需要将 ffmpeg 的 bin 目录加入系统 PATH 环境变量。
|
|
41
|
+
|
|
42
|
+
macOS:
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
brew install ffmpeg
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Linux(Debian/Ubuntu):
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
sudo apt update && sudo apt install ffmpeg
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### 2. 安装 B2A
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
# 克隆仓库
|
|
58
|
+
git clone https://github.com/fanzhongli/B2A.git
|
|
59
|
+
cd B2A
|
|
60
|
+
|
|
61
|
+
# 安装
|
|
62
|
+
pip install -e .
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
安装完成后即可使用 `b2a` 命令。
|
|
66
|
+
|
|
67
|
+
## 快速上手
|
|
68
|
+
|
|
69
|
+
### 基础用法:获取视频信息 + CC 字幕
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
b2a BV1xx411c7mD
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### 语音识别(ASR)
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
# 全视频 ASR
|
|
79
|
+
b2a BV1xx411c7mD --asr
|
|
80
|
+
|
|
81
|
+
# 指定片段 ASR(3分20秒到4分50秒)
|
|
82
|
+
b2a BV1xx411c7mD --asr --start 03:20 --end 04:50
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### 视觉抽帧
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
# 全视频抽帧(每10秒一张)
|
|
89
|
+
b2a BV1xx411c7mD --visual
|
|
90
|
+
|
|
91
|
+
# 指定片段抽帧
|
|
92
|
+
b2a BV1xx411c7mD --visual --start 01:00 --end 02:30
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### 声形同时获取
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
b2a BV1xx411c7mD --asr --visual --start 03:20 --end 04:50
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### 分P视频
|
|
102
|
+
|
|
103
|
+
```bash
|
|
104
|
+
# 指定第3个分P
|
|
105
|
+
b2a BV1xx411c7mD --page 3 --asr
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### 多种输入格式
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
# 完整链接(自动提取 BV 号、分P、时间跳转)
|
|
112
|
+
b2a "https://www.bilibili.com/video/BV1xx411c7mD?p=2&t=180"
|
|
113
|
+
|
|
114
|
+
# b23.tv 短链
|
|
115
|
+
b2a "https://b23.tv/xxxxxx"
|
|
116
|
+
|
|
117
|
+
# AV 号
|
|
118
|
+
b2a av170001
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### JSON 结构化输出(供 Agent 消费)
|
|
122
|
+
|
|
123
|
+
```bash
|
|
124
|
+
b2a BV1xx411c7mD --asr --format json
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## ASR 配置
|
|
128
|
+
|
|
129
|
+
ASR 功能依赖豆包语音(火山引擎)API Key。不配置时,CC 字幕和视觉抽帧功能仍可正常使用。
|
|
130
|
+
|
|
131
|
+
1. 复制配置模板:
|
|
132
|
+
```bash
|
|
133
|
+
cp .env.example .env
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
2. 编辑 `.env`,填入你的 API Key:
|
|
137
|
+
```env
|
|
138
|
+
VOLC_ENV=test
|
|
139
|
+
VOLC_TEST_API_KEY=你的测试环境API_Key
|
|
140
|
+
VOLC_PROD_API_KEY=你的生产环境API_Key
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
## CLI 参数一览
|
|
144
|
+
|
|
145
|
+
```
|
|
146
|
+
b2a <url> [选项]
|
|
147
|
+
|
|
148
|
+
位置参数:
|
|
149
|
+
url B站视频URL、BV号或AV号
|
|
150
|
+
|
|
151
|
+
选项:
|
|
152
|
+
--asr 启用语音识别(提取音频轨并转文字)
|
|
153
|
+
--visual 启用视觉提取(抽取视频关键帧截图)
|
|
154
|
+
--start TIME 截取开始时间(如 01:30 或 1:03:20)
|
|
155
|
+
--end TIME 截取结束时间(如 02:40 或 1:05:00)
|
|
156
|
+
--page N 指定分P编号(从1开始)
|
|
157
|
+
--format {text,json} 输出格式(默认 text)
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
## 项目结构
|
|
161
|
+
|
|
162
|
+
```
|
|
163
|
+
B2A/
|
|
164
|
+
├── src/
|
|
165
|
+
│ ├── cli.py # CLI 入口
|
|
166
|
+
│ ├── core/
|
|
167
|
+
│ │ ├── api.py # B站 API(视频信息、字幕、分P)
|
|
168
|
+
│ │ └── asr.py # 火山引擎 ASR(含长音频自动分片)
|
|
169
|
+
│ ├── audio/
|
|
170
|
+
│ │ └── extractor.py # 音频提取(yt-dlp)
|
|
171
|
+
│ ├── visual/
|
|
172
|
+
│ │ └── extractor.py # 视觉提取(yt-dlp 下载 + ffmpeg 抽帧)
|
|
173
|
+
│ └── utils/
|
|
174
|
+
│ ├── config.py # 环境变量与鉴权
|
|
175
|
+
│ ├── url_parser.py # URL 解析(短链/BV/AV/分P/时间)
|
|
176
|
+
│ └── workspace.py # 工作区目录管理(按视频隔离)
|
|
177
|
+
├── tests/ # 测试用例(26个)
|
|
178
|
+
├── pyproject.toml # 打包配置
|
|
179
|
+
├── requirements.txt # 依赖清单
|
|
180
|
+
└── .env.example # 环境变量模板
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
## 运行测试
|
|
184
|
+
|
|
185
|
+
```bash
|
|
186
|
+
pip install -e ".[dev]"
|
|
187
|
+
pytest tests/ -v
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
## License
|
|
191
|
+
|
|
192
|
+
MIT
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: b2a777
|
|
3
|
+
Version: 0.3.2
|
|
4
|
+
Summary: B2A (Bilibili to Agents) — 让 AI Agent 能「观看」B站视频
|
|
5
|
+
Author: fanzhongli
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/e8b298/B2A
|
|
8
|
+
Project-URL: Repository, https://github.com/e8b298/B2A.git
|
|
9
|
+
Project-URL: Bug-Tracker, https://github.com/e8b298/B2A/issues
|
|
10
|
+
Keywords: bilibili,agent,ai,subtitle,asr,video,multimodal
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Environment :: Console
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Topic :: Multimedia :: Video
|
|
21
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
22
|
+
Requires-Python: >=3.10
|
|
23
|
+
Description-Content-Type: text/markdown
|
|
24
|
+
License-File: LICENSE
|
|
25
|
+
Requires-Dist: httpx>=0.25.0
|
|
26
|
+
Requires-Dist: yt-dlp>=2024.0.0
|
|
27
|
+
Requires-Dist: python-dotenv>=1.0.0
|
|
28
|
+
Provides-Extra: dev
|
|
29
|
+
Requires-Dist: pytest>=8.0.0; extra == "dev"
|
|
30
|
+
Requires-Dist: pytest-asyncio>=0.23.0; extra == "dev"
|
|
31
|
+
Requires-Dist: build>=1.0.0; extra == "dev"
|
|
32
|
+
Requires-Dist: twine>=5.0.0; extra == "dev"
|
|
33
|
+
Dynamic: license-file
|
|
34
|
+
|
|
35
|
+
# B2A (Bilibili to Agents)
|
|
36
|
+
|
|
37
|
+
让 AI Agent 能「观看」B站视频的多模态内容提取工具。
|
|
38
|
+
|
|
39
|
+
## 解决什么问题
|
|
40
|
+
|
|
41
|
+
AI Agent(如 Claude Code、Cursor 等)可以访问网页,但无法真正「观看」视频。当用户想让 Agent 分析某个 B 站视频的内容时,Agent 无从下手。
|
|
42
|
+
|
|
43
|
+
B2A 提供了三条互补的信息获取轨道:
|
|
44
|
+
|
|
45
|
+
- CC 字幕 — 最快速,直接拉取视频自带的字幕文本(含时间戳)
|
|
46
|
+
- ASR 语音识别(声) — 通过豆包语音大模型将音频转为带时间戳的文字,解决 B 站大量视频无 CC 字幕的问题
|
|
47
|
+
- 视觉抽帧(形) — 下载视频并按间隔截取关键帧图片,让 Agent 能「看到」画面内容
|
|
48
|
+
|
|
49
|
+
三条轨道可任意组合,支持全视频或指定时间片段。
|
|
50
|
+
|
|
51
|
+
## 安装
|
|
52
|
+
|
|
53
|
+
### 1. 安装 ffmpeg(前置依赖)
|
|
54
|
+
|
|
55
|
+
`--visual` 抽帧和 `--asr` 切片功能依赖 ffmpeg,版本需 5.0 以上。
|
|
56
|
+
|
|
57
|
+
Windows:
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
# 方式一:winget(Windows 11 自带,推荐)
|
|
61
|
+
winget install Gyan.FFmpeg
|
|
62
|
+
|
|
63
|
+
# 方式二:scoop
|
|
64
|
+
scoop install ffmpeg
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
安装后打开新的终端窗口,验证:
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
ffmpeg -version
|
|
71
|
+
# 应显示 ffmpeg version 5.x 或更高
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
如果提示找不到命令,需要将 ffmpeg 的 bin 目录加入系统 PATH 环境变量。
|
|
75
|
+
|
|
76
|
+
macOS:
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
brew install ffmpeg
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Linux(Debian/Ubuntu):
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
sudo apt update && sudo apt install ffmpeg
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### 2. 安装 B2A
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
# 克隆仓库
|
|
92
|
+
git clone https://github.com/fanzhongli/B2A.git
|
|
93
|
+
cd B2A
|
|
94
|
+
|
|
95
|
+
# 安装
|
|
96
|
+
pip install -e .
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
安装完成后即可使用 `b2a` 命令。
|
|
100
|
+
|
|
101
|
+
## 快速上手
|
|
102
|
+
|
|
103
|
+
### 基础用法:获取视频信息 + CC 字幕
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
b2a BV1xx411c7mD
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### 语音识别(ASR)
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
# 全视频 ASR
|
|
113
|
+
b2a BV1xx411c7mD --asr
|
|
114
|
+
|
|
115
|
+
# 指定片段 ASR(3分20秒到4分50秒)
|
|
116
|
+
b2a BV1xx411c7mD --asr --start 03:20 --end 04:50
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### 视觉抽帧
|
|
120
|
+
|
|
121
|
+
```bash
|
|
122
|
+
# 全视频抽帧(每10秒一张)
|
|
123
|
+
b2a BV1xx411c7mD --visual
|
|
124
|
+
|
|
125
|
+
# 指定片段抽帧
|
|
126
|
+
b2a BV1xx411c7mD --visual --start 01:00 --end 02:30
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### 声形同时获取
|
|
130
|
+
|
|
131
|
+
```bash
|
|
132
|
+
b2a BV1xx411c7mD --asr --visual --start 03:20 --end 04:50
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### 分P视频
|
|
136
|
+
|
|
137
|
+
```bash
|
|
138
|
+
# 指定第3个分P
|
|
139
|
+
b2a BV1xx411c7mD --page 3 --asr
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
### 多种输入格式
|
|
143
|
+
|
|
144
|
+
```bash
|
|
145
|
+
# 完整链接(自动提取 BV 号、分P、时间跳转)
|
|
146
|
+
b2a "https://www.bilibili.com/video/BV1xx411c7mD?p=2&t=180"
|
|
147
|
+
|
|
148
|
+
# b23.tv 短链
|
|
149
|
+
b2a "https://b23.tv/xxxxxx"
|
|
150
|
+
|
|
151
|
+
# AV 号
|
|
152
|
+
b2a av170001
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### JSON 结构化输出(供 Agent 消费)
|
|
156
|
+
|
|
157
|
+
```bash
|
|
158
|
+
b2a BV1xx411c7mD --asr --format json
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
## ASR 配置
|
|
162
|
+
|
|
163
|
+
ASR 功能依赖豆包语音(火山引擎)API Key。不配置时,CC 字幕和视觉抽帧功能仍可正常使用。
|
|
164
|
+
|
|
165
|
+
1. 复制配置模板:
|
|
166
|
+
```bash
|
|
167
|
+
cp .env.example .env
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
2. 编辑 `.env`,填入你的 API Key:
|
|
171
|
+
```env
|
|
172
|
+
VOLC_ENV=test
|
|
173
|
+
VOLC_TEST_API_KEY=你的测试环境API_Key
|
|
174
|
+
VOLC_PROD_API_KEY=你的生产环境API_Key
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
## CLI 参数一览
|
|
178
|
+
|
|
179
|
+
```
|
|
180
|
+
b2a <url> [选项]
|
|
181
|
+
|
|
182
|
+
位置参数:
|
|
183
|
+
url B站视频URL、BV号或AV号
|
|
184
|
+
|
|
185
|
+
选项:
|
|
186
|
+
--asr 启用语音识别(提取音频轨并转文字)
|
|
187
|
+
--visual 启用视觉提取(抽取视频关键帧截图)
|
|
188
|
+
--start TIME 截取开始时间(如 01:30 或 1:03:20)
|
|
189
|
+
--end TIME 截取结束时间(如 02:40 或 1:05:00)
|
|
190
|
+
--page N 指定分P编号(从1开始)
|
|
191
|
+
--format {text,json} 输出格式(默认 text)
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
## 项目结构
|
|
195
|
+
|
|
196
|
+
```
|
|
197
|
+
B2A/
|
|
198
|
+
├── src/
|
|
199
|
+
│ ├── cli.py # CLI 入口
|
|
200
|
+
│ ├── core/
|
|
201
|
+
│ │ ├── api.py # B站 API(视频信息、字幕、分P)
|
|
202
|
+
│ │ └── asr.py # 火山引擎 ASR(含长音频自动分片)
|
|
203
|
+
│ ├── audio/
|
|
204
|
+
│ │ └── extractor.py # 音频提取(yt-dlp)
|
|
205
|
+
│ ├── visual/
|
|
206
|
+
│ │ └── extractor.py # 视觉提取(yt-dlp 下载 + ffmpeg 抽帧)
|
|
207
|
+
│ └── utils/
|
|
208
|
+
│ ├── config.py # 环境变量与鉴权
|
|
209
|
+
│ ├── url_parser.py # URL 解析(短链/BV/AV/分P/时间)
|
|
210
|
+
│ └── workspace.py # 工作区目录管理(按视频隔离)
|
|
211
|
+
├── tests/ # 测试用例(26个)
|
|
212
|
+
├── pyproject.toml # 打包配置
|
|
213
|
+
├── requirements.txt # 依赖清单
|
|
214
|
+
└── .env.example # 环境变量模板
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
## 运行测试
|
|
218
|
+
|
|
219
|
+
```bash
|
|
220
|
+
pip install -e ".[dev]"
|
|
221
|
+
pytest tests/ -v
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
## License
|
|
225
|
+
|
|
226
|
+
MIT
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
b2a777.egg-info/PKG-INFO
|
|
5
|
+
b2a777.egg-info/SOURCES.txt
|
|
6
|
+
b2a777.egg-info/dependency_links.txt
|
|
7
|
+
b2a777.egg-info/entry_points.txt
|
|
8
|
+
b2a777.egg-info/requires.txt
|
|
9
|
+
b2a777.egg-info/top_level.txt
|
|
10
|
+
src/__init__.py
|
|
11
|
+
src/cli.py
|
|
12
|
+
src/audio/__init__.py
|
|
13
|
+
src/audio/extractor.py
|
|
14
|
+
src/core/__init__.py
|
|
15
|
+
src/core/api.py
|
|
16
|
+
src/core/asr.py
|
|
17
|
+
src/utils/__init__.py
|
|
18
|
+
src/utils/config.py
|
|
19
|
+
src/utils/url_parser.py
|
|
20
|
+
src/utils/workspace.py
|
|
21
|
+
src/visual/__init__.py
|
|
22
|
+
src/visual/extractor.py
|
|
23
|
+
tests/test_api.py
|
|
24
|
+
tests/test_asr.py
|
|
25
|
+
tests/test_audio_extractor.py
|
|
26
|
+
tests/test_cli.py
|
|
27
|
+
tests/test_config.py
|
|
28
|
+
tests/test_extractor.py
|
|
29
|
+
tests/test_url_parser.py
|
|
30
|
+
tests/test_workspace.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
src
|