fix(bilibili): correct metadata and filename in archive
PR Test / lint (pull_request) Successful in 1s
PR Test / lint (pull_request) Successful in 1s
- Add _normalize_metadata() to flatten nested metadata structure
- Fix generate_frontmatter() to use correct metadata fields
- Change _sanitize_filename() to return standardized "bilibili_{bvid}" format
Fixes: analysis.md frontmatter showing "未命名"/0/"未知" instead of actual values
Fixes: audio filename using video title instead of platform_bvid format
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -461,26 +461,17 @@ class BilibiliAdapter(PlatformAdapter):
|
|||||||
return "video"
|
return "video"
|
||||||
|
|
||||||
def _sanitize_filename(self, title: str, bvid: str) -> str:
|
def _sanitize_filename(self, title: str, bvid: str) -> str:
|
||||||
"""Sanitize title for use as filename.
|
"""Generate standardized filename for video download.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
title: Video title
|
title: Video title (unused, kept for API compatibility)
|
||||||
bvid: Video BV号 for fallback
|
bvid: Video BV号
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
Safe filename string
|
Standardized filename in format "bilibili_{bvid}"
|
||||||
"""
|
"""
|
||||||
# Keep alphanumeric, spaces, and common Chinese-safe chars
|
# Use standardized naming convention: platform_bvid
|
||||||
safe_title = "".join(
|
return f"bilibili_{bvid}"
|
||||||
c for c in title
|
|
||||||
if c.isalnum() or c in (' ', '-', '_', '丨', '|')
|
|
||||||
).strip()[:50]
|
|
||||||
|
|
||||||
# Use bvid if title is empty
|
|
||||||
if not safe_title:
|
|
||||||
safe_title = f"video_{bvid}"
|
|
||||||
|
|
||||||
return safe_title
|
|
||||||
|
|
||||||
def _create_cookie_file(self, cookie: str) -> str:
|
def _create_cookie_file(self, cookie: str) -> str:
|
||||||
"""Create Netscape format cookie file for yt-dlp.
|
"""Create Netscape format cookie file for yt-dlp.
|
||||||
|
|||||||
@@ -226,6 +226,28 @@ class AnalyzeProcessor(BaseProcessor):
|
|||||||
base_url=base_url
|
base_url=base_url
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def _normalize_metadata(self, metadata: Dict) -> Dict:
|
||||||
|
"""标准化元数据结构(扁平化嵌套结构)
|
||||||
|
|
||||||
|
Args:
|
||||||
|
metadata: 原始元数据字典,可能是嵌套结构
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
扁平化的元数据字典
|
||||||
|
"""
|
||||||
|
if not metadata:
|
||||||
|
return {}
|
||||||
|
|
||||||
|
# 如果已经是扁平结构(顶层有 title)
|
||||||
|
if 'title' in metadata:
|
||||||
|
return metadata
|
||||||
|
|
||||||
|
# 处理嵌套结构 {metadata: {...}, stats: {...}}
|
||||||
|
if 'metadata' in metadata:
|
||||||
|
return metadata['metadata'].copy()
|
||||||
|
|
||||||
|
return metadata
|
||||||
|
|
||||||
def _write_analysis_report(
|
def _write_analysis_report(
|
||||||
self,
|
self,
|
||||||
output_path: Path,
|
output_path: Path,
|
||||||
@@ -243,8 +265,11 @@ class AnalyzeProcessor(BaseProcessor):
|
|||||||
"""
|
"""
|
||||||
from kb_deep_analyzer.deep_analyzer import generate_frontmatter
|
from kb_deep_analyzer.deep_analyzer import generate_frontmatter
|
||||||
|
|
||||||
|
# 标准化元数据(扁平化嵌套结构)
|
||||||
|
normalized_metadata = self._normalize_metadata(metadata)
|
||||||
|
|
||||||
# 生成 frontmatter
|
# 生成 frontmatter
|
||||||
frontmatter = generate_frontmatter(metadata, result, content_type)
|
frontmatter = generate_frontmatter(normalized_metadata, result, content_type)
|
||||||
|
|
||||||
# 获取完整分析内容
|
# 获取完整分析内容
|
||||||
full_analysis = result.full_analysis
|
full_analysis = result.full_analysis
|
||||||
|
|||||||
Reference in New Issue
Block a user