feat: integrate bilibili-extractor into obsidian-kb

- Add extractors layer with BilibiliExtractor (Playwright stealth mode)
- Add outputs layer with ObsidianWriter and GitSync
- Implement subtitle/no-subtitle graceful degradation
- Update config with output and bilibili extraction settings
- Complete integration pipeline: extract → process → output → sync
- Add comprehensive tests (100% pass rate)
- Update documentation (SKILL.md, README.md, requirements.txt)
This commit is contained in:
OpenClaw Agent
2026-02-07 13:07:43 +08:00
parent ceeeb0f84c
commit 08f7c9f26c
29 changed files with 5824 additions and 45 deletions
+99 -8
View File
@@ -23,6 +23,13 @@ from shortlink_resolver import (
PlaywrightResolver
)
# 导入主流程
try:
from main_pipeline import MainPipeline
MAIN_PIPELINE_AVAILABLE = True
except ImportError:
MAIN_PIPELINE_AVAILABLE = False
# Pattern definitions for auto-detection
PATTERNS = {
'bilibili_full': re.compile(r'https?://(?:www\.)?bilibili\.com/video/(BV\w+)'),
@@ -276,6 +283,45 @@ def process_link(url: str, platform: str, auto_process: bool = False) -> Tuple[b
return False, f"处理失败: {e}"
def process_video_full(source_id: str, enable_git_sync: bool = False) -> Tuple[bool, str]:
"""
使用主流程完整处理视频(新接口)
完整流程: 提取 → 处理 → 输出 → 同步
Args:
source_id: 视频ID(支持BV号、URL)
enable_git_sync: 是否启用Git同步
Returns:
(success, message) tuple
"""
if not MAIN_PIPELINE_AVAILABLE:
return False, "主流程模块未可用,请检查依赖"
try:
# 导入配置
from src.config import get_config
# 获取配置
config = get_config()
# 创建主流程
pipeline = MainPipeline(config=config, enable_git_sync=enable_git_sync)
# 处理视频
result = pipeline.process_video(source_id)
# 返回结果
if result['success']:
return True, result['message']
else:
return False, result.get('error', 'Unknown error')
except Exception as e:
return False, f"处理失败: {e}"
def handle_message(text: str) -> Optional[str]:
"""
Main entry point: handle incoming message and return response.
@@ -317,19 +363,64 @@ def handle_message(text: str) -> Optional[str]:
def main():
"""CLI for testing the handler."""
if len(sys.argv) < 2:
print("Usage: python3 handler.py 'text to test'")
print("Usage: python3 handler.py <command> [options]")
print("\nCommands:")
print(" detect 'text' - 检测文本中的内容链接")
print(" process <BV/URL> - 使用主流程处理视频")
print(" process <BV/URL> --git - 处理视频并同步到Git")
print("\nExamples:")
print(' python3 handler.py "https://www.bilibili.com/video/BV1xx411c7mD"')
print(' python3 handler.py "Check this video: https://b23.tv/xxxxx"')
print(' python3 handler.py detect "https://www.bilibili.com/video/BV1xx411c7mD"')
print(' python3 handler.py process BV1xx411c7mD')
print(' python3 handler.py process BV1xx411c7mD --git')
sys.exit(1)
text = sys.argv[1]
response = handle_message(text)
command = sys.argv[1].lower()
if command == 'detect':
# 检测链接
if len(sys.argv) < 3:
print("Error: Please provide text to detect")
sys.exit(1)
text = ' '.join(sys.argv[2:])
response = handle_message(text)
if response:
print(response)
else:
print("No content links detected")
elif command == 'process':
# 使用主流程处理视频
if len(sys.argv) < 3:
print("Error: Please provide BV number or URL")
sys.exit(1)
source_id = sys.argv[2]
enable_git = '--git' in sys.argv
print(f"Processing video: {source_id}")
if enable_git:
print("Git sync: enabled")
else:
print("Git sync: disabled")
print()
success, message = process_video_full(source_id, enable_git_sync=enable_git)
if success:
print(message)
sys.exit(0)
else:
print(f"\n❌ Failed: {message}")
sys.exit(1)
if response:
print(response)
else:
print("No content links detected")
# 兼容旧格式:直接传入文本进行检测
text = sys.argv[1]
response = handle_message(text)
if response:
print(response)
else:
print("No content links detected")
if __name__ == '__main__':