From: Sergey M. Date: Sun, 16 Feb 2014 20:46:26 +0000 (+0700) Subject: Improve parse_duration X-Git-Url: https://git.cielonegro.org/gitweb.cgi?a=commitdiff_plain;h=2db806b4aa0047002cf4c8b1ce6e3dd79ab8ee69;p=youtube-dl.git Improve parse_duration --- diff --git a/test/test_utils.py b/test/test_utils.py index 1ca5f5af8..84553b943 100644 --- a/test/test_utils.py +++ b/test/test_utils.py @@ -202,7 +202,16 @@ class TestUtil(unittest.TestCase): self.assertEqual(parse_duration('1'), 1) self.assertEqual(parse_duration('1337:12'), 80232) self.assertEqual(parse_duration('9:12:43'), 33163) + self.assertEqual(parse_duration('12:00'), 720) + self.assertEqual(parse_duration('00:01:01'), 61) self.assertEqual(parse_duration('x:y'), None) + self.assertEqual(parse_duration('3h11m53s'), 11513) + self.assertEqual(parse_duration('62m45s'), 3765) + self.assertEqual(parse_duration('6m59s'), 419) + self.assertEqual(parse_duration('49s'), 49) + self.assertEqual(parse_duration('0h0m0s'), 0) + self.assertEqual(parse_duration('0m0s'), 0) + self.assertEqual(parse_duration('0s'), 0) def test_fix_xml_ampersands(self): self.assertEqual( diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py index dd03f058f..a192a420a 100644 --- a/youtube_dl/utils.py +++ b/youtube_dl/utils.py @@ -1144,7 +1144,7 @@ def parse_duration(s): return None m = re.match( - r'(?:(?:(?P[0-9]+):)?(?P[0-9]+):)?(?P[0-9]+)$', s) + r'(?:(?:(?P[0-9]+)[:h])?(?P[0-9]+)[:m])?(?P[0-9]+)s?$', s) if not m: return None res = int(m.group('secs'))