aboutsummaryrefslogtreecommitdiff
path: root/youtube_dl/utils.py
diff options
context:
space:
mode:
authorPhilipp Hagemeister <phihag@phihag.de>2014-12-04 17:35:40 +0100
committerPhilipp Hagemeister <phihag@phihag.de>2014-12-04 17:35:40 +0100
commite8df5cee12378acd708b6686130a73c5edc06f0e (patch)
tree8d58243d31366dd03ae335426c188bab4db6b99e /youtube_dl/utils.py
parentab07963b5cc79812c6fb7e4f9e363533d8123830 (diff)
[minhateca] Fix duration parsing
Diffstat (limited to 'youtube_dl/utils.py')
-rw-r--r--youtube_dl/utils.py19
1 files changed, 15 insertions, 4 deletions
diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py
index 5e9ae7a42..5efb4c59a 100644
--- a/youtube_dl/utils.py
+++ b/youtube_dl/utils.py
@@ -1206,18 +1206,29 @@ def parse_duration(s):
m = re.match(
r'''(?ix)T?
+ (?:
+ (?P<only_mins>[0-9.]+)\s*(?:mins?|minutes?)\s*|
+ (?P<only_hours>[0-9.]+)\s*(?:hours?)|
+
(?:
(?:(?P<hours>[0-9]+)\s*(?:[:h]|hours?)\s*)?
(?P<mins>[0-9]+)\s*(?:[:m]|mins?|minutes?)\s*
)?
- (?P<secs>[0-9]+)(?P<ms>\.[0-9]+)?\s*(?:s|secs?|seconds?)?$''', s)
+ (?P<secs>[0-9]+)(?P<ms>\.[0-9]+)?\s*(?:s|secs?|seconds?)?
+ )$''', s)
if not m:
return None
- res = int(m.group('secs'))
+ res = 0
+ if m.group('only_mins'):
+ return float_or_none(m.group('only_mins'), invscale=60)
+ if m.group('only_hours'):
+ return float_or_none(m.group('only_hours'), invscale=60 * 60)
+ if m.group('secs'):
+ res += int(m.group('secs'))
if m.group('mins'):
res += int(m.group('mins')) * 60
- if m.group('hours'):
- res += int(m.group('hours')) * 60 * 60
+ if m.group('hours'):
+ res += int(m.group('hours')) * 60 * 60
if m.group('ms'):
res += float(m.group('ms'))
return res