mirror of
https://codeberg.org/polarisfm/youtube-dl
synced 2024-11-22 16:44:32 +01:00
[utils] Add support for zero years and months in parse_duration
This commit is contained in:
parent
c3206d02e9
commit
056653bbb1
@ -540,6 +540,7 @@ class TestUtil(unittest.TestCase):
|
|||||||
self.assertEqual(parse_duration('87 Min.'), 5220)
|
self.assertEqual(parse_duration('87 Min.'), 5220)
|
||||||
self.assertEqual(parse_duration('PT1H0.040S'), 3600.04)
|
self.assertEqual(parse_duration('PT1H0.040S'), 3600.04)
|
||||||
self.assertEqual(parse_duration('PT00H03M30SZ'), 210)
|
self.assertEqual(parse_duration('PT00H03M30SZ'), 210)
|
||||||
|
self.assertEqual(parse_duration('P0Y0M0DT0H4M20.880S'), 260.88)
|
||||||
|
|
||||||
def test_fix_xml_ampersands(self):
|
def test_fix_xml_ampersands(self):
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
|
@ -1835,10 +1835,20 @@ def parse_duration(s):
|
|||||||
days, hours, mins, secs, ms = m.groups()
|
days, hours, mins, secs, ms = m.groups()
|
||||||
else:
|
else:
|
||||||
m = re.match(
|
m = re.match(
|
||||||
r'''(?ix)(?:P?T)?
|
r'''(?ix)(?:P?
|
||||||
|
(?:
|
||||||
|
[0-9]+\s*y(?:ears?)?\s*
|
||||||
|
)?
|
||||||
|
(?:
|
||||||
|
[0-9]+\s*m(?:onths?)?\s*
|
||||||
|
)?
|
||||||
|
(?:
|
||||||
|
[0-9]+\s*w(?:eeks?)?\s*
|
||||||
|
)?
|
||||||
(?:
|
(?:
|
||||||
(?P<days>[0-9]+)\s*d(?:ays?)?\s*
|
(?P<days>[0-9]+)\s*d(?:ays?)?\s*
|
||||||
)?
|
)?
|
||||||
|
T)?
|
||||||
(?:
|
(?:
|
||||||
(?P<hours>[0-9]+)\s*h(?:ours?)?\s*
|
(?P<hours>[0-9]+)\s*h(?:ours?)?\s*
|
||||||
)?
|
)?
|
||||||
|
Loading…
Reference in New Issue
Block a user