aboutsummaryrefslogtreecommitdiff
path: root/youtube_dl/utils.py
diff options
context:
space:
mode:
authorPhilipp Hagemeister <phihag@phihag.de>2013-12-26 13:49:44 +0100
committerPhilipp Hagemeister <phihag@phihag.de>2013-12-26 13:49:44 +0100
commit608d11f515c9668fa069b422b5850a41e17f52be (patch)
treec658405e840ef3cec33c5a2bf542d0eaf5e234d4 /youtube_dl/utils.py
parent723f83991198c09cf3519abd3306704f64b09af0 (diff)
[cnn] Add multiple formats, duration, and upload_date
Diffstat (limited to 'youtube_dl/utils.py')
-rw-r--r--youtube_dl/utils.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py
index 4c8bdbb0c..83a274043 100644
--- a/youtube_dl/utils.py
+++ b/youtube_dl/utils.py
@@ -1102,3 +1102,19 @@ class HEADRequest(compat_urllib_request.Request):
def int_or_none(v):
return v if v is None else int(v)
+
+
+def parse_duration(s):
+ if s is None:
+ return None
+
+ m = re.match(
+ r'(?:(?:(?P<hours>[0-9]+):)?(?P<mins>[0-9]+):)?(?P<secs>[0-9]+)$', s)
+ if not m:
+ return None
+ 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
+ return res