mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-12-28 14:15:53 +01:00
parent
596379e260
commit
8bd1c00bf3
@ -643,6 +643,8 @@ def test_parse_duration(self):
|
||||
self.assertEqual(parse_duration('PT1H0.040S'), 3600.04)
|
||||
self.assertEqual(parse_duration('PT00H03M30SZ'), 210)
|
||||
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)
|
||||
|
||||
def test_fix_xml_ampersands(self):
|
||||
self.assertEqual(
|
||||
|
@ -4094,9 +4094,14 @@ def parse_duration(s):
|
||||
return None
|
||||
|
||||
days, hours, mins, secs, ms = [None] * 5
|
||||
m = re.match(r'(?:(?:(?:(?P<days>[0-9]+):)?(?P<hours>[0-9]+):)?(?P<mins>[0-9]+):)?(?P<secs>[0-9]+)(?P<ms>\.[0-9]+)?Z?$', s)
|
||||
m = re.match(r'''(?x)
|
||||
(?P<before_secs>
|
||||
(?:(?:(?P<days>[0-9]+):)?(?P<hours>[0-9]+):)?(?P<mins>[0-9]+):)?
|
||||
(?P<secs>(?(before_secs)[0-9]{1,2}|[0-9]+))
|
||||
(?P<ms>[.:][0-9]+)?Z?$
|
||||
''', s)
|
||||
if m:
|
||||
days, hours, mins, secs, ms = m.groups()
|
||||
days, hours, mins, secs, ms = m.group('days', 'hours', 'mins', 'secs', 'ms')
|
||||
else:
|
||||
m = re.match(
|
||||
r'''(?ix)(?:P?
|
||||
@ -4141,7 +4146,7 @@ def parse_duration(s):
|
||||
if days:
|
||||
duration += float(days) * 24 * 60 * 60
|
||||
if ms:
|
||||
duration += float(ms)
|
||||
duration += float(ms.replace(':', '.'))
|
||||
return duration
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user