2 Commits

Author SHA1 Message Date
starmen1265 5d06056b43 fix(download): handle formatted duration strings in metadata
PR Test / lint (pull_request) Successful in 1s
Parse duration strings like "12:34" or "01:23:45" into seconds.
Previously only integer duration values were handled.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-15 18:17:03 +08:00
starmen1265 368e946cd1 fix(bilibili): avoid nested asyncio.run() in async context
BilibiliAdapter._fetch_metadata_with_retry() now calls the underlying
async methods directly instead of sync wrappers that use asyncio.run().
This prevents "asyncio.run() cannot be called from a running event loop"
error when the adapter is called from within an already-running event loop.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-15 18:17:03 +08:00
2 changed files with 19 additions and 3 deletions
+4 -2
View File
@@ -170,9 +170,11 @@ class BilibiliAdapter(PlatformAdapter):
ValueError: If content_type is not supported
"""
if content_type == "video":
return self._extractor.extract_video_metadata(content_id)
# Call async method directly to avoid nested asyncio.run()
return await self._extractor._extract_video_async(content_id)
elif content_type == "article":
return self._extractor.extract_article_metadata(content_id)
# Call async method directly to avoid nested asyncio.run()
return await self._extractor._extract_article_async(content_id)
else:
raise ValueError(f"Unsupported content type: {content_type}")
+15 -1
View File
@@ -215,7 +215,21 @@ class DownloadProcessor(BaseProcessor):
# Bilibili video duration
if "metadata" in metadata and "duration" in metadata["metadata"]:
return metadata["metadata"]["duration"]
duration = metadata["metadata"]["duration"]
# Handle formatted duration string (e.g., "12:34" or "01:23:45")
if isinstance(duration, str):
if not duration.strip():
return None
parts = duration.split(':')
try:
if len(parts) == 2:
return int(parts[0]) * 60 + int(parts[1])
elif len(parts) == 3:
return int(parts[0]) * 3600 + int(parts[1]) * 60 + int(parts[2])
except (ValueError, IndexError):
return None
elif isinstance(duration, (int, float)):
return int(duration)
return None