自动同步: 2026-03-14 02:10

This commit is contained in:
2026-03-14 02:10:08 +08:00
parent 8da5f11591
commit 3b83bbb929
52 changed files with 4378 additions and 1930 deletions
+118 -50
View File
@@ -1,86 +1,154 @@
---
name: kb-zhihu-content
description: 知乎内容下载 - 下载视频、提取文章内容
---
# KB Zhihu Content Skill
**kb-zhihu-content** - Download Zhihu videos and extract content.
**kb-zhihu-content** - 下载知乎视频、提取文章内容。
## Features
## 什么时候使用
- Video download using **yt-dlp**
- Subtitle extraction (returns no subtitle, triggers Whisper)
- **Read article content from MediaCrawler data** (NEW!)
- Supports `ZHIHU_COOKIE` environment variable
- kb-workflow 步骤 3a:下载知乎视频
- kb-workflow 步骤 3b:提取知乎专栏文章内容
## Environment Variables
## 功能
| Variable | Required | Description |
|----------|----------|-------------|
| `ZHIHU_COOKIE` | No | 知乎登录 Cookie (for member-only videos) |
- 视频下载(使用 yt-dlp)
- 从 MediaCrawler 数据读取文章内容
- 支持 `ZHIHU_COOKIE` 环境变量
## Commands
## 环境变量
| 变量名 | 必需 | 说明 |
|--------|------|------|
| `ZHIHU_COOKIE` | 否 | 知乎登录 Cookie |
## 命令
```bash
# Download video
python zhihu_content.py --id "12345678" --type video --output "/path/to/downloads/"
# 下载视频
python3 zhihu_content.py --id "12345678" --type video --output "/path/to/downloads/"
# Extract subtitle (returns no subtitle, triggers Whisper)
python zhihu_content.py --id "12345678" --type subtitle --output "/path/to/subtitles/"
# 从 MediaCrawler 读取文章内容 (⚡ NEW!)
python zhihu_content.py --type article-from-media --input "~/work/MediaCrawler/data/zhihu/json/detail_contents_2026-02-27.json" --output "~/work/knowledge-base/data/zhihu/"
```
## MediaCrawler 数据读取
**新功能**:从 MediaCrawler 爬取的数据中提取知乎文章内容
### 使用方法
```bash
# 从 MediaCrawler JSON 文件读取文章内容
python zhihu_content.py --type article-from-media \
# 从 MediaCrawler 读取文章内容
python3 zhihu_content.py --type article-from-media \
--input "~/work/MediaCrawler/data/zhihu/json/detail_contents_2026-02-27.json" \
--output "~/work/knowledge-base/data/zhihu/"
# 查找最新的爬取数据
python zhihu_content.py --type article-from-media \
# 自动查找最新 MediaCrawler 数据
python3 zhihu_content.py --type article-from-media \
--output "~/work/knowledge-base/data/zhihu/"
```
### 参数说明
## 输出格式 Schema
| 参数 | 说明 |
|------|------|
| `--type article-from-media` | 从 MediaCrawler 数据读取 |
| `--input` | MediaCrawler 输出文件路径(可选,不指定则自动查找最新) |
| `--output` | 输出目录 |
### 必需字段
### 输出格式
| 字段 | 类型 | 说明 |
|------|------|------|
| `success` | boolean | 是否成功 |
| `type` | string | 操作类型(video/article) |
### 视频下载特有字段
| 字段 | 类型 | 说明 |
|------|------|------|
| `filepath` | string | 视频文件路径 |
| `filename` | string | 视频文件名 |
### 文章提取特有字段
| 字段 | 类型 | 说明 |
|------|------|------|
| `filepath` | string | 文章文件路径 |
| `filename` | string | 文章文件名 |
| `content_length` | number | 内容长度 |
## 成功示例
### 视频下载
```json
{
"success": true,
"type": "video",
"filename": "zhihu_12345678.mp4",
"filepath": "content/downloads/zhihu_12345678.mp4",
"message": "下载完成"
}
```
### 文章内容提取
```json
{
"success": true,
"type": "article",
"filename": "zhihu_article_如何高效的爬取微信公众号.md",
"filepath": "/home/xxx/work/knowledge-base/data/zhihu/zhihu_article_如何高效的爬取微信公众号.md",
"filepath": "~/work/knowledge-base/data/zhihu/zhihu_article_如何高效的爬取微信公众号.md",
"content_length": 4563,
"message": "文章内容已导出"
}
```
## 原有功能
## 错误示例
### Video Download
### 视频下载失败
Video download uses **yt-dlp**:
1. Parses `ZHIHU_COOKIE` environment variable (optional)
2. Creates temporary Netscape-format cookie file
3. Runs `yt-dlp -f best -o <output> <url>`
4. Cleans up temporary file
```json
{
"success": false,
"type": "video",
"error": "视频不存在或无法访问",
"suggestion": "请检查视频 ID 是否正确"
}
```
**Note**: 知乎视频通常没有官方字幕,将自动触发 Whisper 语音识别
### MediaCrawler 数据未找到
## Installation
```json
{
"success": false,
"type": "article-from-media",
"error": "未找到 MediaCrawler 数据文件",
"suggestion": "请先运行 MediaCrawler 爬取文章"
}
```
### 网络错误
```json
{
"success": false,
"error": "网络请求失败: Connection timeout"
}
```
## 安装
```bash
# Already included in kb-skills repo
# Ensure yt-dlp is installed
cp -r kb-zhihu-content/ ~/.openclaw/skills/
pip install yt-dlp aiohttp
```
## 在 kb-workflow 中的使用
```bash
# 步骤 3a:下载知乎视频
python3 ~/.openclaw/skills/kb-zhihu-content/zhihu_content.py \
--id "12345678" --type video \
--output "content/downloads/"
# 注意:知乎视频没有官方字幕,下载后需要进入 Whisper 步骤
# 步骤 3b:提取专栏文章(如果有 MediaCrawler 数据)
python3 ~/.openclaw/skills/kb-zhihu-content/zhihu_content.py \
--type article-from-media \
--output "content/"
```
## 注意事项
- **知乎视频没有官方字幕**:下载后必须进入 Whisper 步骤
- MediaCrawler 需要单独安装和运行
- 部分视频可能需要登录才能下载