fix(download): handle formatted duration strings in metadata
PR Test / lint (pull_request) Successful in 1s
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>
This commit is contained in:
@@ -215,7 +215,21 @@ class DownloadProcessor(BaseProcessor):
|
|||||||
|
|
||||||
# Bilibili video duration
|
# Bilibili video duration
|
||||||
if "metadata" in metadata and "duration" in metadata["metadata"]:
|
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
|
return None
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user