fix: Regex bug when parsing time.

This commit is contained in:
Terry Geng
2020-07-07 21:44:10 +08:00
parent 892fa502e6
commit c9b170d865
2 changed files with 3 additions and 3 deletions

View File

@ -366,14 +366,14 @@ def get_media_duration(path):
def parse_time(human):
match = re.search("(?:(\d\d):)?(?:(\d\d):)?(\d\d(?:\.\d*)?)", human, flags=re.IGNORECASE)
match = re.search("(?:(\d\d):)?(?:(\d\d):)?(\d+(?:\.\d*)?)", human, flags=re.IGNORECASE)
if match:
if match[1] is None and match[2] is None:
return float(match[3])
elif match[2] is None:
return float(match[3]) + 60 * int(match[1])
else:
return float(match[3]) + 60 * int(match[2]) + 3600 * int(match[2])
return float(match[3]) + 60 * int(match[2]) + 3600 * int(match[1])
else:
raise ValueError("Invalid time string given.")