diff --git a/kb_pipeline/platforms/bilibili.py b/kb_pipeline/platforms/bilibili.py index 2682a6e..962e7bb 100644 --- a/kb_pipeline/platforms/bilibili.py +++ b/kb_pipeline/platforms/bilibili.py @@ -461,26 +461,17 @@ class BilibiliAdapter(PlatformAdapter): return "video" def _sanitize_filename(self, title: str, bvid: str) -> str: - """Sanitize title for use as filename. + """Generate standardized filename for video download. Args: - title: Video title - bvid: Video BV号 for fallback + title: Video title (unused, kept for API compatibility) + bvid: Video BV号 Returns: - Safe filename string + Standardized filename in format "bilibili_{bvid}" """ - # Keep alphanumeric, spaces, and common Chinese-safe chars - safe_title = "".join( - 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 + # Use standardized naming convention: platform_bvid + return f"bilibili_{bvid}" def _create_cookie_file(self, cookie: str) -> str: """Create Netscape format cookie file for yt-dlp. diff --git a/kb_pipeline/processors/analyze.py b/kb_pipeline/processors/analyze.py index 8d46e01..ba00a36 100644 --- a/kb_pipeline/processors/analyze.py +++ b/kb_pipeline/processors/analyze.py @@ -226,6 +226,28 @@ class AnalyzeProcessor(BaseProcessor): 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( self, output_path: Path, @@ -243,8 +265,11 @@ class AnalyzeProcessor(BaseProcessor): """ from kb_deep_analyzer.deep_analyzer import generate_frontmatter + # 标准化元数据(扁平化嵌套结构) + normalized_metadata = self._normalize_metadata(metadata) + # 生成 frontmatter - frontmatter = generate_frontmatter(metadata, result, content_type) + frontmatter = generate_frontmatter(normalized_metadata, result, content_type) # 获取完整分析内容 full_analysis = result.full_analysis