]> git.bitcoin.ninja Git - youtube-dl/blobdiff - youtube_dl/utils.py
release 2014.09.01
[youtube-dl] / youtube_dl / utils.py
index 4f02108720d5699a017a78fb25bb30ae3c23c831..8a36e619ae7246da1f18a4d5fd6cee7b364b81b7 100644 (file)
@@ -1318,6 +1318,7 @@ def str_or_none(v, default=None):
 
 
 def str_to_int(int_str):
+    """ A more relaxed version of int_or_none """
     if int_str is None:
         return None
     int_str = re.sub(r'[,\.]', u'', int_str)
@@ -1332,8 +1333,10 @@ def parse_duration(s):
     if s is None:
         return None
 
+    s = s.strip()
+
     m = re.match(
-        r'(?:(?:(?P<hours>[0-9]+)[:h])?(?P<mins>[0-9]+)[:m])?(?P<secs>[0-9]+)s?(?::[0-9]+)?(?P<ms>\.[0-9]+)?$', s)
+        r'(?:(?:(?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)
     if not m:
         return None
     res = int(m.group('secs'))