]> git.bitcoin.ninja Git - youtube-dl/commitdiff
[utils] Improve parse_duration
authorYen Chi Hsuan <yan12125@gmail.com>
Wed, 22 Jul 2015 15:15:22 +0000 (23:15 +0800)
committerYen Chi Hsuan <yan12125@gmail.com>
Wed, 22 Jul 2015 15:15:22 +0000 (23:15 +0800)
Now dots are parsed. For example '87 Min.'

test/test_utils.py
youtube_dl/utils.py

index e13e11b59f7f427e8c082f003c650268895ef6f3..65692a9fbb2bdc0dd6dbc5203439f1ca12bf5c46 100644 (file)
@@ -324,6 +324,7 @@ class TestUtil(unittest.TestCase):
         self.assertEqual(parse_duration('02:03:04'), 7384)
         self.assertEqual(parse_duration('01:02:03:04'), 93784)
         self.assertEqual(parse_duration('1 hour 3 minutes'), 3780)
+        self.assertEqual(parse_duration('87 Min.'), 5220)
 
     def test_fix_xml_ampersands(self):
         self.assertEqual(
index 942f76d2452c06a261d75e03cebc999fff02874c..ae813099dded05c15ed57d27e51be7704e778520 100644 (file)
@@ -1309,10 +1309,10 @@ def parse_duration(s):
     m = re.match(
         r'''(?ix)(?:P?T)?
         (?:
-            (?P<only_mins>[0-9.]+)\s*(?:mins?|minutes?)\s*|
+            (?P<only_mins>[0-9.]+)\s*(?:mins?\.?|minutes?)\s*|
             (?P<only_hours>[0-9.]+)\s*(?:hours?)|
 
-            \s*(?P<hours_reversed>[0-9]+)\s*(?:[:h]|hours?)\s*(?P<mins_reversed>[0-9]+)\s*(?:[:m]|mins?|minutes?)\s*|
+            \s*(?P<hours_reversed>[0-9]+)\s*(?:[:h]|hours?)\s*(?P<mins_reversed>[0-9]+)\s*(?:[:m]|mins?\.?|minutes?)\s*|
             (?:
                 (?:
                     (?:(?P<days>[0-9]+)\s*(?:[:d]|days?)\s*)?