From ee0fc743786a00378f5c71c5fc18f151475abb56 Mon Sep 17 00:00:00 2001 From: starmen1265 Date: Tue, 17 Mar 2026 13:50:02 +0800 Subject: [PATCH] fix(download): return author name instead of mid in _extract_author MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Fix download processor to return actual author name (e.g. "HOLA小测佬") instead of B站用户ID (mid, e.g. "406636263") - Add 5 test cases for author extraction logic - Resolves report display issue where UP主名称 showed numeric ID Co-Authored-By: Claude Opus 4.6 --- kb_workflow/pipeline/processors/download.py | 8 +- tests/test_processors/test_download.py | 93 +++++++++++++++++++++ 2 files changed, 97 insertions(+), 4 deletions(-) diff --git a/kb_workflow/pipeline/processors/download.py b/kb_workflow/pipeline/processors/download.py index c3654d1..bd85a61 100644 --- a/kb_workflow/pipeline/processors/download.py +++ b/kb_workflow/pipeline/processors/download.py @@ -216,13 +216,13 @@ class DownloadProcessor(BaseProcessor): platform: Platform name Returns: - Author string + Author string (author name, not mid) """ if platform == "bilibili": - # Bilibili metadata structure: {metadata: {mid: ...}, ...} + # Bilibili metadata structure: {metadata: {author: ..., mid: ...}, ...} if "metadata" in metadata: - return str(metadata["metadata"].get("mid", "")) - return str(metadata.get("mid", "")) + return str(metadata["metadata"].get("author", "")) + return str(metadata.get("author", "")) else: return metadata.get("author", "") diff --git a/tests/test_processors/test_download.py b/tests/test_processors/test_download.py index 7d8a30b..836a9f6 100644 --- a/tests/test_processors/test_download.py +++ b/tests/test_processors/test_download.py @@ -137,6 +137,7 @@ class TestDownloadProcessorMetadata: adapter.fetch_metadata = AsyncMock(return_value={ "metadata": { "title": "Test Video Title", + "author": "Test UP Author", "mid": 12345, "bvid": "BV1xx", }, @@ -347,6 +348,7 @@ class TestDownloadProcessorContent: adapter.fetch_metadata = AsyncMock(return_value={ "metadata": { "title": "Test Video Title", + "author": "Test Video Author", "mid": 12345, "bvid": "BV1xx", "duration": 300, @@ -481,3 +483,94 @@ class TestDownloadProcessorModuleExport: assert ParseProcessor is not None assert DownloadProcessor is not None assert ASRProcessor is not None + + +class TestDownloadProcessorAuthorExtraction: + """Tests for _extract_author method - ensure it returns author name, not mid.""" + + def test_extract_author_returns_author_name_not_mid(self): + """_extract_author should return author name, not mid (user ID)""" + from kb_workflow.pipeline.processors.download import DownloadProcessor + + processor = DownloadProcessor() + + # Bilibili metadata with both author and mid + metadata = { + "metadata": { + "title": "Test Video", + "author": "HOLA小测佬", + "mid": 406636263, + "bvid": "BV1QXcCzfECp", + } + } + + author = processor._extract_author(metadata, "bilibili") + + # Should return author name, not mid + assert author == "HOLA小测佬" + assert author != "406636263" + assert author != str(metadata["metadata"]["mid"]) + + def test_extract_author_handles_nested_metadata(self): + """_extract_author should handle nested metadata structure""" + from kb_workflow.pipeline.processors.download import DownloadProcessor + + processor = DownloadProcessor() + + # Nested metadata structure + metadata = { + "metadata": { + "author": "Test Author Name", + "mid": 12345, + } + } + + author = processor._extract_author(metadata, "bilibili") + assert author == "Test Author Name" + + def test_extract_author_handles_flat_metadata(self): + """_extract_author should handle flat metadata structure""" + from kb_workflow.pipeline.processors.download import DownloadProcessor + + processor = DownloadProcessor() + + # Flat metadata structure (no nested 'metadata' key) + metadata = { + "author": "Flat Author", + "mid": 67890, + } + + author = processor._extract_author(metadata, "bilibili") + assert author == "Flat Author" + + def test_extract_author_handles_zhihu_platform(self): + """_extract_author should handle zhihu platform""" + from kb_workflow.pipeline.processors.download import DownloadProcessor + + processor = DownloadProcessor() + + # Zhihu metadata structure + metadata = { + "author": "Zhihu User", + } + + author = processor._extract_author(metadata, "zhihu") + assert author == "Zhihu User" + + def test_extract_author_returns_empty_string_for_missing_author(self): + """_extract_author should return empty string when author is missing""" + from kb_workflow.pipeline.processors.download import DownloadProcessor + + processor = DownloadProcessor() + + # Metadata without author + metadata = { + "metadata": { + "title": "Test Video", + "mid": 12345, + } + } + + author = processor._extract_author(metadata, "bilibili") + assert author == "" +