feat(kb-bilibili-metadata): Add series/readlist/favlist metadata extraction

- Add extract_series_async() for series collection metadata
- Add extract_readlist_async() for article list metadata
- Add extract_favlist_async() for favorite list metadata
- Add CLI support for new types: series, readlist, favlist
- Update bilibili_metadata.py with new extraction functions
- Add --mid parameter for series type

Note: These types record basic info and subscription status only,
not the full content list (which may be large).
This commit is contained in:
OpenClaw Agent
2026-02-10 14:27:14 +08:00
parent 51347f671b
commit 4cdbc825ce
2 changed files with 225 additions and 1 deletions
@@ -7,6 +7,7 @@ B站元数据提取 CLI 工具
"""
import argparse
import asyncio
import json
import sys
from typing import Dict, Any
@@ -58,6 +59,39 @@ def extract_up(extractor: BilibiliExtractor, mid: str, output_file: str = None)
return result
def extract_series(extractor: BilibiliExtractor, mid: str, series_id: str, output_file: str = None) -> Dict[str, Any]:
"""提取系列合集元数据"""
result = asyncio.run(extractor._extract_series_async(mid, series_id))
if output_file:
with open(output_file, 'w', encoding='utf-8') as f:
json.dump(result, f, ensure_ascii=False, indent=2)
return result
def extract_readlist(extractor: BilibiliExtractor, rl_id: str, output_file: str = None) -> Dict[str, Any]:
"""提取专栏合集元数据"""
result = asyncio.run(extractor._extract_readlist_async(rl_id))
if output_file:
with open(output_file, 'w', encoding='utf-8') as f:
json.dump(result, f, ensure_ascii=False, indent=2)
return result
def extract_favlist(extractor: BilibiliExtractor, fid: str, output_file: str = None) -> Dict[str, Any]:
"""提取收藏夹元数据"""
result = asyncio.run(extractor._extract_favlist_async(fid))
if output_file:
with open(output_file, 'w', encoding='utf-8') as f:
json.dump(result, f, ensure_ascii=False, indent=2)
return result
def main():
"""主函数"""
parser = argparse.ArgumentParser(
@@ -74,6 +108,15 @@ def main():
# 提取UP主信息
python bilibili_metadata.py --id "7770724" --type up
# 提取系列合集信息
python bilibili_metadata.py --id "123456" --type series --mid "7770724"
# 提取专栏合集信息
python bilibili_metadata.py --id "rl123456" --type readlist
# 提取收藏夹信息
python bilibili_metadata.py --id "123456" --type favlist
# 输出到文件
python bilibili_metadata.py --id "BV1xx411c7mD" --type video --output result.json
"""
@@ -87,9 +130,13 @@ def main():
parser.add_argument(
'--type',
required=True,
choices=['video', 'article', 'up'],
choices=['video', 'article', 'up', 'series', 'readlist', 'favlist'],
help='资源类型'
)
parser.add_argument(
'--mid',
help='UP主ID (用于series类型)'
)
parser.add_argument(
'--output',
'-o',
@@ -127,6 +174,15 @@ def main():
result = extract_article(extractor, args.id, args.output)
elif args.type == 'up':
result = extract_up(extractor, args.id, args.output)
elif args.type == 'series':
if not args.mid:
print("错误: series类型需要提供 --mid 参数")
sys.exit(1)
result = extract_series(extractor, args.mid, args.id, args.output)
elif args.type == 'readlist':
result = extract_readlist(extractor, args.id, args.output)
elif args.type == 'favlist':
result = extract_favlist(extractor, args.id, args.output)
else:
print(f"错误: 不支持的类型 {args.type}")
sys.exit(1)