自动同步: 2026-03-14 02:10
This commit is contained in:
@@ -1,91 +1,214 @@
|
||||
---
|
||||
name: kb-bilibili-content
|
||||
description: B站内容下载 - 下载视频、字幕、专栏文章
|
||||
---
|
||||
|
||||
# KB Bilibili Content Skill
|
||||
|
||||
**kb-bilibili-content** - Download Bilibili videos and extract content.
|
||||
**kb-bilibili-content** - 下载 B站视频、字幕、专栏文章。
|
||||
|
||||
## Features
|
||||
## 什么时候使用
|
||||
|
||||
- Video download using **yt-dlp** (recommended)
|
||||
- Subtitle extraction
|
||||
- Article content extraction
|
||||
- Multiple quality options (360P/480P/720P/1080P)
|
||||
- Supports `BILIBILI_COOKIE` environment variable
|
||||
- kb-workflow 步骤 3a:下载视频或字幕
|
||||
- kb-workflow 步骤 3b:提取专栏文章内容
|
||||
|
||||
## Environment Variables
|
||||
## 功能
|
||||
|
||||
| Variable | Required | Description |
|
||||
|----------|----------|-------------|
|
||||
| `BILIBILI_COOKIE` | No | B站登录 Cookie (for member-only videos) |
|
||||
- 视频下载(使用 yt-dlp)
|
||||
- 字幕提取(官方字幕)
|
||||
- 专栏文章内容提取
|
||||
- 多种画质选项(360P/480P/720P/1080P)
|
||||
- 支持 `BILIBILI_COOKIE` 环境变量(会员视频)
|
||||
|
||||
## Commands
|
||||
## 环境变量
|
||||
|
||||
| 变量名 | 必需 | 说明 |
|
||||
|--------|------|------|
|
||||
| `BILIBILI_COOKIE` | 否 | B站登录 Cookie(会员视频需要) |
|
||||
|
||||
**获取 Cookie:**
|
||||
1. 登录 bilibili.com
|
||||
2. F12 → Network → 刷新页面
|
||||
3. 从请求头复制 Cookie
|
||||
|
||||
```bash
|
||||
# Download video (720P default)
|
||||
python bilibili_content.py --id "BV1xx411c7mD" --type video --output "/path/to/downloads/"
|
||||
|
||||
# Download video (1080P)
|
||||
python bilibili_content.py --id "BV1xx411c7mD" --type video --quality 80 --output "/path/to/downloads/"
|
||||
|
||||
# Download video (480P)
|
||||
python bilibili_content.py --id "BV1xx411c7mD" --type video --quality 32 --output "/path/to/downloads/"
|
||||
|
||||
# Extract subtitle
|
||||
python bilibili_content.py --id "BV1xx411c7mD" --type subtitle --output "/path/to/subtitles/"
|
||||
|
||||
# Get article content
|
||||
python bilibili_content.py --id "cv43780186" --type article --output "/path/to/article.md"
|
||||
export BILIBILI_COOKIE="SESSDATA=xxx; bili_jct=xxx; DedeUserID=xxx"
|
||||
```
|
||||
|
||||
## Output
|
||||
## 命令
|
||||
|
||||
```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": "video_title.mp4",
|
||||
"filepath": "/path/to/downloads/video_title.mp4",
|
||||
"message": "下载完成: video_title.mp4"
|
||||
"filename": "bilibili_BV1xx411c7mD.mp4",
|
||||
"filepath": "content/downloads/bilibili_BV1xx411c7mD.mp4",
|
||||
"quality": "720P",
|
||||
"message": "下载完成"
|
||||
}
|
||||
```
|
||||
|
||||
## Cookie Setup
|
||||
### 专栏文章提取
|
||||
|
||||
### Get Cookie from Browser
|
||||
1. Login to bilibili.com
|
||||
2. Press F12 → Network → Refresh page
|
||||
3. Copy Cookie from request headers
|
||||
|
||||
### Set Environment Variable
|
||||
```bash
|
||||
# Add to ~/.bashrc for persistence
|
||||
export BILIBILI_COOKIE="SESSDATA=xxx; bili_jct=xxx; DedeUserID=xxx; DedeUserID__ckMd5=xxx"
|
||||
|
||||
# Or set temporarily
|
||||
export BILIBILI_COOKIE="your_cookie_here"
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"type": "article",
|
||||
"filename": "bilibili_cv43780186.txt",
|
||||
"filepath": "content/bilibili_cv43780186.txt",
|
||||
"content_length": 5234,
|
||||
"message": "文章内容提取成功"
|
||||
}
|
||||
```
|
||||
|
||||
## Installation
|
||||
## 错误示例
|
||||
|
||||
```bash
|
||||
cp -r kb-bilibili-content/ ~/skills/
|
||||
pip install aiohttp playwright
|
||||
playwright install chromium
|
||||
### 403 禁止访问
|
||||
|
||||
```json
|
||||
{
|
||||
"success": false,
|
||||
"type": "video",
|
||||
"error": "403 Forbidden",
|
||||
"error_code": "FORBIDDEN",
|
||||
"suggestion": "可能需要会员权限,请配置 BILIBILI_COOKIE 环境变量"
|
||||
}
|
||||
```
|
||||
|
||||
## How It Works
|
||||
### 视频不存在
|
||||
|
||||
Video download uses **yt-dlp** with Netscape-format cookie file:
|
||||
1. Parses `BILIBILI_COOKIE` environment variable
|
||||
2. Creates temporary Netscape-format cookie file
|
||||
3. Runs `yt-dlp --cookies <file> -f <format> -o <output>`
|
||||
4. Cleans up temporary file
|
||||
```json
|
||||
{
|
||||
"success": false,
|
||||
"type": "video",
|
||||
"error": "视频不存在或已被删除",
|
||||
"error_code": "NOT_FOUND"
|
||||
}
|
||||
```
|
||||
|
||||
## Quality Options
|
||||
### 网络超时
|
||||
|
||||
| Quality | ID | Resolution | Notes |
|
||||
|---------|-----|------------|-------|
|
||||
| 16 | 360P | 640x360 | Fastest |
|
||||
| 32 | 480P | 852x480 | Default for low bandwidth |
|
||||
| 64 | 720P | 1280x720 | **Recommended** |
|
||||
| 80 | 1080P | 1920x1080 | Best quality |
|
||||
```json
|
||||
{
|
||||
"success": false,
|
||||
"type": "video",
|
||||
"error": "下载超时",
|
||||
"error_code": "TIMEOUT",
|
||||
"suggestion": "请检查网络连接后重试"
|
||||
}
|
||||
```
|
||||
|
||||
Default quality: **64 (720P)**
|
||||
## 画质选项
|
||||
|
||||
| 画质 | 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
|
||||
- **下载时间**:视频可能较大,需要耐心等待
|
||||
|
||||
Reference in New Issue
Block a user