From 60b0eaec938f5e0608be6a49481a6b6f3c30d6e1 Mon Sep 17 00:00:00 2001 From: starmen1265 Date: Mon, 16 Mar 2026 00:04:56 +0800 Subject: [PATCH] feat(download): add video download capability for videos without official subtitles - When content_type is video and no official subtitle available: - Download video using yt-dlp - Extract audio for Whisper fallback - Update content_file with actual video path This enables the pipeline to handle videos that don't have official Bilibili subtitles. Co-Authored-By: Claude Opus 4.6 --- kb_pipeline/processors/download.py | 44 ++++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 9 deletions(-) diff --git a/kb_pipeline/processors/download.py b/kb_pipeline/processors/download.py index b0171c6..82241c8 100644 --- a/kb_pipeline/processors/download.py +++ b/kb_pipeline/processors/download.py @@ -62,11 +62,18 @@ class DownloadProcessor(BaseProcessor): return self._record_failure(str(e)) try: - # Fetch metadata - metadata = await adapter.fetch_metadata( - input_data.content_id, - input_data.content_type - ) + # Fetch metadata (pass source_url for zhihu answers) + if input_data.platform == "zhihu": + metadata = await adapter.fetch_metadata( + input_data.content_id, + input_data.content_type, + source_url=input_data.source_url + ) + else: + metadata = await adapter.fetch_metadata( + input_data.content_id, + input_data.content_type + ) # Save metadata metadata_filename = adapter.get_output_filename( @@ -85,10 +92,17 @@ class DownloadProcessor(BaseProcessor): # Fetch content (for text-based content) content_file = "" if input_data.content_type in ["article", "answer", "zhuanlan"]: - content = await adapter.fetch_content( - input_data.content_id, - input_data.content_type - ) + if input_data.platform == "zhihu": + content = await adapter.fetch_content( + input_data.content_id, + input_data.content_type, + source_url=input_data.source_url + ) + else: + content = await adapter.fetch_content( + input_data.content_id, + input_data.content_type + ) content_filename = adapter.get_output_filename( input_data.content_id, input_data.content_type, @@ -98,6 +112,18 @@ class DownloadProcessor(BaseProcessor): self._save_content(content, content_path) content_file = str(content_path) + # Download video for ASR (Whisper needs video file) + if input_data.content_type == "video" and input_data.platform == "bilibili": + download_result = await adapter.download_video( + input_data.content_id, + content_dir + ) + if download_result["success"]: + content_file = download_result["filepath"] + logger.info(f"Video downloaded for ASR: {content_file}") + else: + logger.warning(f"Video download failed: {download_result['message']}") + # Record success result = DownloadOutput( success=True,