X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;ds=sidebyside;f=youtube_dl%2Futils.py;h=f2342b10a0e2521be52c8ffed0c279bceaa15e5c;hb=086d7b4500dad720e548233e425b4c08bfe99e3e;hp=3a2f0022fb87f9c6426f295cbc5da214e6370b72;hpb=81df121dd3497a9a00fc76a58d667b5afef3b8d1;p=youtube-dl diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py index 3a2f0022f..f2342b10a 100644 --- a/youtube_dl/utils.py +++ b/youtube_dl/utils.py @@ -430,6 +430,28 @@ def decodeOption(optval): assert isinstance(optval, compat_str) return optval +def formatSeconds(secs): + if secs > 3600: + return '%d:%02d:%02d' % (secs // 3600, (secs % 3600) // 60, secs % 60) + elif secs > 60: + return '%d:%02d' % (secs // 60, secs % 60) + else: + return '%d' % secs + +def make_HTTPS_handler(opts): + if sys.version_info < (3,2): + # Python's 2.x handler is very simplistic + return compat_urllib_request.HTTPSHandler() + else: + import ssl + context = ssl.SSLContext(ssl.PROTOCOL_SSLv23) + context.set_default_verify_paths() + + context.verify_mode = (ssl.CERT_NONE + if opts.no_check_certificate + else ssl.CERT_REQUIRED) + return compat_urllib_request.HTTPSHandler(context=context) + class ExtractorError(Exception): """Error during info extraction.""" def __init__(self, msg, tb=None): @@ -586,7 +608,29 @@ def unified_strdate(date_str): return upload_date def date_from_str(date_str): - """Return a datetime object from a string in the format YYYYMMDD""" + """ + Return a datetime object from a string in the format YYYYMMDD or + (now|today)[+-][0-9](day|week|month|year)(s)?""" + today = datetime.date.today() + if date_str == 'now'or date_str == 'today': + return today + match = re.match('(now|today)(?P[+-])(?P