Update obsidian-kb skill and add find-skills
- obsidian-kb: Add OCR processors (easyocr, tesseract) - obsidian-kb: Fix subtitle detection with test files - obsidian-kb: Add cookie verification script - Add find-skills skill for discovering capabilities - Add video processing scripts - Update clawhub lock file
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
测试B站字幕提取 - 测试多个视频
|
||||
"""
|
||||
import asyncio
|
||||
import json
|
||||
from playwright.async_api import async_playwright
|
||||
|
||||
async def test_video(bvid):
|
||||
"""测试单个视频"""
|
||||
url = f"https://www.bilibili.com/video/{bvid}"
|
||||
|
||||
async with async_playwright() as playwright:
|
||||
browser = await playwright.chromium.launch(headless=True)
|
||||
context = await browser.new_context()
|
||||
page = await context.new_page()
|
||||
|
||||
# 使用 API 获取视频信息
|
||||
api_url = "https://api.bilibili.com/x/web-interface/view"
|
||||
response = await page.request.get(api_url, params={'bvid': bvid})
|
||||
data = await response.json()
|
||||
|
||||
if data.get('code') == 0:
|
||||
video_data = data.get('data', {})
|
||||
title = video_data.get('title', '')
|
||||
cid = video_data.get('cid', '')
|
||||
print(f"\n视频: {title}")
|
||||
print(f"BV号: {bvid}")
|
||||
print(f"cid: {cid}")
|
||||
|
||||
# 获取字幕
|
||||
if cid:
|
||||
player_url = "https://api.bilibili.com/x/player/v2"
|
||||
player_response = await page.request.get(player_url, params={'bvid': bvid, 'cid': cid})
|
||||
player_data = await player_response.json()
|
||||
|
||||
if player_data.get('code') == 0:
|
||||
subtitle_info = player_data.get('data', {}).get('subtitle', {})
|
||||
subtitles_list = subtitle_info.get('subtitles', [])
|
||||
|
||||
if subtitles_list:
|
||||
print(f"✅ 找到 {len(subtitles_list)} 个字幕")
|
||||
for i, sub in enumerate(subtitles_list[:3]):
|
||||
print(f" [{i+1}] {sub.get('lan_doc')} - {sub.get('subtitle_url')}")
|
||||
|
||||
# 获取第一个字幕内容
|
||||
subtitle_url = subtitles_list[0].get('subtitle_url', '')
|
||||
if subtitle_url:
|
||||
full_url = f"https:{subtitle_url}"
|
||||
sub_response = await page.request.get(full_url)
|
||||
if sub_response.ok:
|
||||
sub_data = await sub_response.json()
|
||||
body = sub_data.get('body', [])
|
||||
print(f"\n字幕示例 (前3条):")
|
||||
for i, item in enumerate(body[:3]):
|
||||
from_time = item.get('from', 0)
|
||||
to_time = item.get('to', 0)
|
||||
content = item.get('content', '')
|
||||
print(f" [{i+1}] [{from_time:.1f} - {to_time:.1f}] {content}")
|
||||
else:
|
||||
print(f"❌ 获取字幕内容失败: {sub_response.status}")
|
||||
else:
|
||||
print("❌ 该视频没有字幕")
|
||||
else:
|
||||
print(f"❌ 获取视频信息失败: {data.get('message')}")
|
||||
|
||||
await browser.close()
|
||||
|
||||
async def main():
|
||||
"""测试多个视频"""
|
||||
# 测试视频列表(包含不同类型的视频)
|
||||
test_videos = [
|
||||
"BV1XX4y1C7tF", # 教程类视频,可能有字幕
|
||||
"BV1GJ411x7h7", # TED演讲,通常有字幕
|
||||
"BV1uA411H7K4", # 科技类视频
|
||||
"BV1MnFNz5EDL", # 之前的测试视频
|
||||
]
|
||||
|
||||
for bvid in test_videos:
|
||||
await test_video(bvid)
|
||||
await asyncio.sleep(1)
|
||||
|
||||
if __name__ == '__main__':
|
||||
asyncio.run(main())
|
||||
Reference in New Issue
Block a user