X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=youtube_dl%2Futils.py;h=83a274043388ed9acedf175ab6ebb7783e1fbfc6;hb=241bce7aaf53ab57615434684c7bfddbddcabf01;hp=2e48f187e665dad81caa663efdb9d0c33f088936;hpb=aa94a6d3159af8333b56d16f3ed0bc3a164a882a;p=youtube-dl diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py index 2e48f187e..83a274043 100644 --- a/youtube_dl/utils.py +++ b/youtube_dl/utils.py @@ -1098,3 +1098,23 @@ def url_basename(url): class HEADRequest(compat_urllib_request.Request): def get_method(self): return "HEAD" + + +def int_or_none(v): + return v if v is None else int(v) + + +def parse_duration(s): + if s is None: + return None + + m = re.match( + r'(?:(?:(?P[0-9]+):)?(?P[0-9]+):)?(?P[0-9]+)$', s) + if not m: + return None + res = int(m.group('secs')) + if m.group('mins'): + res += int(m.group('mins')) * 60 + if m.group('hours'): + res += int(m.group('hours')) * 60 * 60 + return res