X-Git-Url: http://git.cielonegro.org/gitweb.cgi?a=blobdiff_plain;f=youtube_dl%2Futils.py;h=67c6af5070bbe214221b288649049913bfccadf5;hb=af6ba6a1c41aa1e8a5ea8b969e1be44b5cf2dd13;hp=8fa4cb67f3c0fd8344ad33e1bc3098d2653cc085;hpb=dd26ced164f834a337956ab57a014a8afd8b9131;p=youtube-dl.git diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py index 8fa4cb67f..67c6af507 100644 --- a/youtube_dl/utils.py +++ b/youtube_dl/utils.py @@ -751,13 +751,14 @@ class YoutubeDLHandler(compat_urllib_request.HTTPHandler): https_request = http_request https_response = http_response + def unified_strdate(date_str): """Return a string with the date in the format YYYYMMDD""" upload_date = None #Replace commas - date_str = date_str.replace(',',' ') + date_str = date_str.replace(',', ' ') # %z (UTC offset) is only supported in python>=3.2 - date_str = re.sub(r' (\+|-)[\d]*$', '', date_str) + date_str = re.sub(r' ?(\+|-)[0-9]{2}:?[0-9]{2}$', '', date_str) format_expressions = [ '%d %B %Y', '%B %d %Y', @@ -771,11 +772,12 @@ def unified_strdate(date_str): '%Y-%m-%dT%H:%M:%S.%fZ', '%Y-%m-%dT%H:%M:%S.%f0Z', '%Y-%m-%dT%H:%M:%S', + '%Y-%m-%dT%H:%M', ] for expression in format_expressions: try: upload_date = datetime.datetime.strptime(date_str, expression).strftime('%Y%m%d') - except: + except ValueError: pass if upload_date is None: timetuple = email.utils.parsedate_tz(date_str) @@ -1212,3 +1214,9 @@ class PagedList(object): if end == nextfirstid: break return res + + +def uppercase_escape(s): + return re.sub( + r'\\U([0-9a-fA-F]{8})', + lambda m: compat_chr(int(m.group(1), base=16)), s)