fix(kb-bilibili): 分离API和下载请求,禁用下载自动解压
This commit is contained in:
@@ -31,7 +31,6 @@ class BilibiliContent:
|
|||||||
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
|
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
|
||||||
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8',
|
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8',
|
||||||
'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8',
|
'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8',
|
||||||
'Accept-Encoding': 'gzip, deflate, br',
|
|
||||||
'Connection': 'keep-alive',
|
'Connection': 'keep-alive',
|
||||||
'Upgrade-Insecure-Requests': '1',
|
'Upgrade-Insecure-Requests': '1',
|
||||||
'Sec-Fetch-Dest': 'document',
|
'Sec-Fetch-Dest': 'document',
|
||||||
@@ -58,10 +57,11 @@ class BilibiliContent:
|
|||||||
result = {"success": False, "bvid": bvid, "message": "", "filepath": None, "metadata": {}}
|
result = {"success": False, "bvid": bvid, "message": "", "filepath": None, "metadata": {}}
|
||||||
|
|
||||||
try:
|
try:
|
||||||
async with aiohttp.ClientSession(headers=self._get_headers()) as session:
|
# API 请求使用自动解压
|
||||||
|
async with aiohttp.ClientSession(headers=self._get_headers()) as api_session:
|
||||||
# 获取视频信息
|
# 获取视频信息
|
||||||
print(f"获取视频信息: {bvid}")
|
print(f"获取视频信息: {bvid}")
|
||||||
async with session.get("https://api.bilibili.com/x/web-interface/view", params={'bvid': bvid}) as resp:
|
async with api_session.get("https://api.bilibili.com/x/web-interface/view", params={'bvid': bvid}) as resp:
|
||||||
data = await resp.json()
|
data = await resp.json()
|
||||||
|
|
||||||
if data.get('code') != 0:
|
if data.get('code') != 0:
|
||||||
@@ -77,7 +77,7 @@ class BilibiliContent:
|
|||||||
|
|
||||||
# 获取播放地址
|
# 获取播放地址
|
||||||
print(f"获取视频流...")
|
print(f"获取视频流...")
|
||||||
async with session.get("https://api.bilibili.com/x/player/playurl",
|
async with api_session.get("https://api.bilibili.com/x/player/playurl",
|
||||||
params={'bvid': bvid, 'cid': cid, 'qn': quality}) as resp:
|
params={'bvid': bvid, 'cid': cid, 'qn': quality}) as resp:
|
||||||
play_data = await resp.json()
|
play_data = await resp.json()
|
||||||
|
|
||||||
@@ -97,7 +97,9 @@ class BilibiliContent:
|
|||||||
safe_title = "".join(c for c in title if c.isalnum() or c in (' ', '-', '_')).strip()[:30]
|
safe_title = "".join(c for c in title if c.isalnum() or c in (' ', '-', '_')).strip()[:30]
|
||||||
output_path = self.output_dir / f"{safe_title}_{bvid}.flv"
|
output_path = self.output_dir / f"{safe_title}_{bvid}.flv"
|
||||||
|
|
||||||
async with session.get(video_url) as resp:
|
# 视频下载使用禁用自动解压的 session
|
||||||
|
async with aiohttp.ClientSession(headers=self._get_headers(), auto_decompress=False) as download_session:
|
||||||
|
async with download_session.get(video_url) as resp:
|
||||||
with open(output_path, 'wb') as f:
|
with open(output_path, 'wb') as f:
|
||||||
async for chunk in resp.content.iter_chunked(81920):
|
async for chunk in resp.content.iter_chunked(81920):
|
||||||
f.write(chunk)
|
f.write(chunk)
|
||||||
|
|||||||
@@ -70,7 +70,32 @@ generate_summary(...) # 生成汇报
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 待办
|
### 2026-02-12: B站视频下载失败 - 403 Forbidden
|
||||||
|
|
||||||
- [ ] 测试 Prompt-based 模式是否正常工作
|
**问题:** 使用 kb-bilibili-content 下载视频时返回 403 Forbidden 错误。
|
||||||
- [ ] 验证主代理能否正确执行 SKILL.md 中的步骤
|
|
||||||
|
**原因:**
|
||||||
|
1. 视频可能需要B站会员权限
|
||||||
|
2. 或者需要登录cookie才能下载
|
||||||
|
3. 当前未配置 `BILIBILI_COOKIE` 环境变量
|
||||||
|
|
||||||
|
**复现场景:**
|
||||||
|
- 链接:https://www.bilibili.com/video/BV1Z9nXzUEhv
|
||||||
|
- 下载命令:`python3 bilibili_content.py --id "BV1Z9nXzUEhv" --type video`
|
||||||
|
- 结果:返回403错误页面,文件只有548字节
|
||||||
|
|
||||||
|
**影响:** 无法进行后续的OCR处理和深度分析
|
||||||
|
|
||||||
|
**建议解决方案:**
|
||||||
|
1. 配置 `BILIBILI_COOKIE` 环境变量
|
||||||
|
2. 或提供cookies文件路径
|
||||||
|
3. 或跳过OCR步骤,使用元数据+简介进行深度分析
|
||||||
|
|
||||||
|
**当前进度:**
|
||||||
|
- ✅ 步骤1:环境变量检查完成
|
||||||
|
- ✅ 步骤2:链接解析成功(bilibili_BV1Z9nXzUEhv)
|
||||||
|
- ✅ 步骤3:元数据提取成功(标题:新加坡分区漫游指南...)
|
||||||
|
- ❌ 步骤4:视频下载失败(403)
|
||||||
|
- ⏸️ 步骤5:OCR处理(阻塞)
|
||||||
|
- ⏸️ 步骤6:深度分析(阻塞)
|
||||||
|
- ⏸️ 步骤7:归档(阻塞)
|
||||||
|
|||||||
Reference in New Issue
Block a user