From af86873218c24c3859ccf575a87f2b00a73b49d0 Mon Sep 17 00:00:00 2001 From: bashonly Date: Thu, 20 Jul 2023 08:40:31 -0500 Subject: [PATCH] [utils] Improve `parse_duration` Authored by: bashonly --- test/test_utils.py | 2 ++ yt_dlp/utils/_utils.py | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/test/test_utils.py b/test/test_utils.py index 768edfd0cf..b36bc04c2f 100644 --- a/test/test_utils.py +++ b/test/test_utils.py @@ -655,6 +655,8 @@ def test_parse_duration(self): self.assertEqual(parse_duration('P0Y0M0DT0H4M20.880S'), 260.88) self.assertEqual(parse_duration('01:02:03:050'), 3723.05) self.assertEqual(parse_duration('103:050'), 103.05) + self.assertEqual(parse_duration('1HR 3MIN'), 3780) + self.assertEqual(parse_duration('2hrs 3mins'), 7380) def test_fix_xml_ampersands(self): self.assertEqual( diff --git a/yt_dlp/utils/_utils.py b/yt_dlp/utils/_utils.py index 2e619f9ea4..abae0f17e4 100644 --- a/yt_dlp/utils/_utils.py +++ b/yt_dlp/utils/_utils.py @@ -2021,7 +2021,7 @@ def parse_duration(s): )? T)? (?: - (?P[0-9]+)\s*h(?:ours?)?,?\s* + (?P[0-9]+)\s*h(?:(?:ou)?rs?)?,?\s* )? (?: (?P[0-9]+)\s*m(?:in(?:ute)?s?)?,?\s*