Skip to content

Commit

Permalink
[utils] Add support for zero years and months in parse_duration
Browse files Browse the repository at this point in the history
  • Loading branch information
dstftw committed Oct 29, 2017
1 parent c3206d0 commit 056653b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions test/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,7 @@ def test_parse_duration(self):
self.assertEqual(parse_duration('87 Min.'), 5220)
self.assertEqual(parse_duration('PT1H0.040S'), 3600.04)
self.assertEqual(parse_duration('PT00H03M30SZ'), 210)
self.assertEqual(parse_duration('P0Y0M0DT0H4M20.880S'), 260.88)

def test_fix_xml_ampersands(self):
self.assertEqual(
Expand Down
12 changes: 11 additions & 1 deletion youtube_dl/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1835,10 +1835,20 @@ def parse_duration(s):
days, hours, mins, secs, ms = m.groups()
else:
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*
)?
T)?
(?:
(?P<hours>[0-9]+)\s*h(?:ours?)?\s*
)?
Expand Down

0 comments on commit 056653b

Please sign in to comment.