fix(download): return author name instead of mid in _extract_author
PR Test / lint (pull_request) Successful in 1s

- 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 <noreply@anthropic.com>
This commit is contained in:
2026-03-17 13:50:02 +08:00
parent 2dce679cca
commit ee0fc74378
2 changed files with 97 additions and 4 deletions
+4 -4
View File
@@ -216,13 +216,13 @@ class DownloadProcessor(BaseProcessor):
platform: Platform name platform: Platform name
Returns: Returns:
Author string Author string (author name, not mid)
""" """
if platform == "bilibili": if platform == "bilibili":
# Bilibili metadata structure: {metadata: {mid: ...}, ...} # Bilibili metadata structure: {metadata: {author: ..., mid: ...}, ...}
if "metadata" in metadata: if "metadata" in metadata:
return str(metadata["metadata"].get("mid", "")) return str(metadata["metadata"].get("author", ""))
return str(metadata.get("mid", "")) return str(metadata.get("author", ""))
else: else:
return metadata.get("author", "") return metadata.get("author", "")
+93
View File
@@ -137,6 +137,7 @@ class TestDownloadProcessorMetadata:
adapter.fetch_metadata = AsyncMock(return_value={ adapter.fetch_metadata = AsyncMock(return_value={
"metadata": { "metadata": {
"title": "Test Video Title", "title": "Test Video Title",
"author": "Test UP Author",
"mid": 12345, "mid": 12345,
"bvid": "BV1xx", "bvid": "BV1xx",
}, },
@@ -347,6 +348,7 @@ class TestDownloadProcessorContent:
adapter.fetch_metadata = AsyncMock(return_value={ adapter.fetch_metadata = AsyncMock(return_value={
"metadata": { "metadata": {
"title": "Test Video Title", "title": "Test Video Title",
"author": "Test Video Author",
"mid": 12345, "mid": 12345,
"bvid": "BV1xx", "bvid": "BV1xx",
"duration": 300, "duration": 300,
@@ -481,3 +483,94 @@ class TestDownloadProcessorModuleExport:
assert ParseProcessor is not None assert ParseProcessor is not None
assert DownloadProcessor is not None assert DownloadProcessor is not None
assert ASRProcessor 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 == ""