This repository has been archived on 2026-08-07. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
openclaw/skills/kb-bilibili-content/SKILL.md
T

215 lines
4.7 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
name: kb-bilibili-content
description: B站内容下载 - 下载视频、字幕、专栏文章
---
# KB Bilibili Content Skill
**kb-bilibili-content** - 下载 B站视频、字幕、专栏文章。
## 什么时候使用
- kb-workflow 步骤 3a:下载视频或字幕
- kb-workflow 步骤 3b:提取专栏文章内容
## 功能
- 视频下载(使用 yt-dlp)
- 字幕提取(官方字幕)
- 专栏文章内容提取
- 多种画质选项(360P/480P/720P/1080P)
- 支持 `BILIBILI_COOKIE` 环境变量(会员视频)
## 环境变量
| 变量名 | 必需 | 说明 |
|--------|------|------|
| `BILIBILI_COOKIE` | 否 | B站登录 Cookie(会员视频需要) |
**获取 Cookie:**
1. 登录 bilibili.com
2. F12 → Network → 刷新页面
3. 从请求头复制 Cookie
```bash
export BILIBILI_COOKIE="SESSDATA=xxx; bili_jct=xxx; DedeUserID=xxx"
```
## 命令
```bash
# 下载字幕(推荐首先尝试)
python3 bilibili_content.py --id "BV1xx411c7mD" --type subtitle-download --output "/path/to/output/"
# 下载视频(720P,推荐)
python3 bilibili_content.py --id "BV1xx411c7mD" --type video --output "/path/to/output/"
# 下载视频(1080P)
python3 bilibili_content.py --id "BV1xx411c7mD" --type video --quality 80 --output "/path/to/output/"
# 提取专栏文章
python3 bilibili_content.py --id "cv43780186" --type article --output "/path/to/output/"
```
## 输出格式 Schema
### 必需字段
| 字段 | 类型 | 说明 |
|------|------|------|
| `success` | boolean | 是否成功 |
| `type` | string | 操作类型(subtitle/video/article) |
### 字幕下载特有字段
| 字段 | 类型 | 说明 |
|------|------|------|
| `has_subtitle` | boolean | 是否有官方字幕 |
| `subtitle_file` | string | 字幕文件路径(有字幕时) |
### 视频下载特有字段
| 字段 | 类型 | 说明 |
|------|------|------|
| `filepath` | string | 视频文件路径 |
| `filename` | string | 视频文件名 |
| `quality` | string | 画质 |
### 文章提取特有字段
| 字段 | 类型 | 说明 |
|------|------|------|
| `filepath` | string | 文章文件路径 |
| `content_length` | number | 内容长度 |
## 成功示例
### 字幕下载 - 有官方字幕
```json
{
"success": true,
"type": "subtitle-download",
"has_subtitle": true,
"subtitle_file": "content/downloads/bilibili_BV1xx411c7mD.srt",
"message": "官方字幕下载成功"
}
```
### 字幕下载 - 无官方字幕
```json
{
"success": true,
"type": "subtitle-download",
"has_subtitle": false,
"message": "无官方字幕,需要下载视频进行语音识别"
}
```
### 视频下载
```json
{
"success": true,
"type": "video",
"filename": "bilibili_BV1xx411c7mD.mp4",
"filepath": "content/downloads/bilibili_BV1xx411c7mD.mp4",
"quality": "720P",
"message": "下载完成"
}
```
### 专栏文章提取
```json
{
"success": true,
"type": "article",
"filename": "bilibili_cv43780186.txt",
"filepath": "content/bilibili_cv43780186.txt",
"content_length": 5234,
"message": "文章内容提取成功"
}
```
## 错误示例
### 403 禁止访问
```json
{
"success": false,
"type": "video",
"error": "403 Forbidden",
"error_code": "FORBIDDEN",
"suggestion": "可能需要会员权限,请配置 BILIBILI_COOKIE 环境变量"
}
```
### 视频不存在
```json
{
"success": false,
"type": "video",
"error": "视频不存在或已被删除",
"error_code": "NOT_FOUND"
}
```
### 网络超时
```json
{
"success": false,
"type": "video",
"error": "下载超时",
"error_code": "TIMEOUT",
"suggestion": "请检查网络连接后重试"
}
```
## 画质选项
| 画质 | ID | 分辨率 | 说明 |
|------|-----|--------|------|
| 360P | 16 | 640x360 | 最快 |
| 480P | 32 | 852x480 | 低带宽 |
| 720P | 64 | 1280x720 | **推荐** |
| 1080P | 80 | 1920x1080 | 最高画质 |
**默认画质:** 64 (720P)
## 安装
```bash
cp -r kb-bilibili-content/ ~/.openclaw/skills/
pip install aiohttp yt-dlp
```
## 在 kb-workflow 中的使用
```bash
# 步骤 3a:首先尝试字幕
python3 ~/.openclaw/skills/kb-bilibili-content/bilibili_content.py \
--id "BV1xx411c7mD" --type subtitle-download \
--output "content/downloads/"
# 判断结果:
# - has_subtitle=true → 跳过 Whisper,直接进入深度分析
# - has_subtitle=false → 下载视频,进入 Whisper 步骤
# 如果无字幕,下载视频
python3 ~/.openclaw/skills/kb-bilibili-content/bilibili_content.py \
--id "BV1xx411c7mD" --type video \
--output "content/downloads/"
```
## 注意事项
- **无官方字幕是正常的**:很多视频没有自动生成的字幕,这不是错误
- **403 错误**:通常需要配置 Cookie
- **会员视频**:必须配置 BILIBILI_COOKIE
- **下载时间**:视频可能较大,需要耐心等待