# Obsidian KB Skill 多源内容知识库维护系统,整合了 bilibili-extractor,支持 Bilibili、YouTube、知乎等平台的内容聚合,智能分类,以及长视频分段分析。 ## 功能特性 - **多源内容聚合**: 支持 Bilibili、YouTube、知乎等平台 - **增强型 Bilibili 提取**: 使用 Playwright 绕过反爬检测,支持字幕和弹幕提取 - **智能收件箱**: AI 质量评分,自动分类 - **长视频分段分析**: 30分钟+ 视频自动分段处理 - **无字幕处理**: 智能处理无字幕视频,基于元数据生成内容 - **主题组织**: 基于标签的自动主题归类 - **Git 自动同步**: 自动同步到 Obsidian 知识库 - **CLI 命令**: 完整的命令行接口 ## 快速开始 ### 安装 ```bash # 克隆项目 git clone cd obsidian-kb # 安装依赖 pip install -r requirements.txt # 配置 cp config.example.yaml config.yaml # 编辑 config.yaml,设置 API key 等 ``` ### 配置 创建 `config.yaml`: ```yaml # AI 配置 ai: provider: openai model: gpt-4 api_key: your-api-key-here # 或设置 OPENAI_API_KEY 环境变量 # 存储配置 storage: inbox_dir: inbox topics_dir: topics data_dir: data # 输出配置 output: format: markdown # 输出格式 encoding: utf-8 include_timestamp: true # 包含时间戳 include_source: true # 包含源链接 # Git 同步配置 git: enabled: true vault_path: ~/ObsidianVault # Obsidian 知识库路径 remote: origin branch: main auto_commit: true # 分段配置 chunking: enabled: true chunk_duration_seconds: 900 # 15 分钟分段 long_video_threshold: 1800 # 30 分钟以上视为长视频 # 数据源配置 sources: bilibili: enabled: true cookie: your-bilibili-cookie # 可选,用于获取字幕 # Bilibili 提取器配置 bilibili_extraction: use_playwright: true # 使用 Playwright 绕过检测 headless: true # 无头模式 cookie_file: '' # Cookie 文件路径 (可选) enable_subtitle: true # 启用字幕提取 subtitle_language: zh-CN # 字幕语言 enable_danmaku: false # 启用弹幕提取 timeout_seconds: 30 # 超时时间 max_retries: 3 # 最大重试次数 ``` ### 首次使用 1. **获取 Bilibili Cookie (可选但推荐)** 为了更好的字幕提取体验,建议设置 Bilibili Cookie: - 在浏览器中登录 Bilibili - 打开开发者工具 (F12) - 切换到 Network 标签 - 刷新页面,找到任意请求 - 复制 `Cookie` 头的值 - 将其粘贴到配置文件的 `bilibili.cookie` 字段 2. **初始化 Playwright (首次使用需要)** ```bash # 安装 Playwright 浏览器 playwright install chromium ``` 3. **测试提取器** ```bash # 测试 Bilibili 提取器 python -c "from obsidian_kb.extractors.bilibili import BilibiliExtractor; e = BilibiliExtractor(); print(e.extract_video('https://www.bilibili.com/video/BV1xx411c7mD'))" ``` ### 基本使用 ```bash # 订阅 Bilibili 收藏夹 /kb-subscribe bilibili:fav:12345678 # 查看收件箱 /kb-inbox # 处理所有内容 /kb-process --all # 处理指定内容 /kb-process BV1xx411c7mD # 跳过内容 /kb-skip BV1xx411c7mD # 查看状态 /kb-status # 搜索知识库 /kb-search python tutorial ``` ### 提取器特性 **无字幕处理:** 系统会自动处理没有字幕的视频: - 使用视频标题、描述和标签生成内容 - AI 分析视频元数据生成摘要 - 在笔记中标注"无字幕"状态 **字幕提取:** 支持多种字幕源: - CC 字幕 (官方字幕) - AI 字幕 (自动生成) - 自动选择最佳字幕源 **反爬检测:** 使用 Playwright 绕过 Bilibili 的反爬机制: - 无头模式运行 - 自动重试机制 - 可配置超时时间 ## 项目结构 ``` obsidian-kb/ ├── src/ │ ├── __init__.py │ ├── models.py # 数据模型 │ ├── config.py # 配置管理 │ ├── storage.py # 存储管理 │ ├── template_renderer.py # 模板渲染 │ ├── content_chunker.py # 内容分块 │ ├── pipeline.py # 处理管道 │ ├── cli.py # 命令行接口 │ ├── git_sync.py # Git 同步 │ └── sources/ │ ├── __init__.py │ ├── base.py # 适配器基类 │ └── bilibili.py # Bilibili 适配器 ├── templates/ │ ├── light_video.md # 轻量视频模板 │ ├── tutorial_video.md # 教程视频模板 │ ├── article.md # 文章模板 │ └── topic_index.md # 主题索引模板 ├── tests/ # 测试 ├── config.yaml # 配置文件 └── README.md ``` ## 模板系统 根据内容类型和时长自动选择模板: - **轻量视频** (`< 30分钟`): `light_video.md` - **教程视频** (`≥ 30分钟`): `tutorial_video.md` - 包含详细分段、前置知识、常见坑点 - **文章**: `article.md` ## 长视频分段策略 | 时长 | 策略 | 分段数 | |------|------|--------| | < 10分钟 | 直接处理 | 1 | | 10-30分钟 | 截断处理 | 1 | | 30-60分钟 | 两段式 | 2 | | 60分钟+ | 多段式 | 每15分钟一段 | ## 开发 ```bash # 运行测试 pytest tests/ # 运行特定测试 pytest tests/test_models.py # 覆盖率报告 pytest --cov=src tests/ ``` ## 许可证 MIT License