diff options
author | Jaime Marquínez Ferrándiz <[email protected]> | 2013-04-27 15:14:20 +0200 |
---|---|---|
committer | Jaime Marquínez Ferrándiz <[email protected]> | 2013-04-27 15:14:20 +0200 |
commit | bf50b0383e4d6728bbbf1d0ee70cf586a90efb40 (patch) | |
tree | b6614ea9625d8f756aa174e4a03796270be1df61 /youtube_dl/utils.py | |
parent | bd55852517a40d011b303559f4cd78773a2f3de5 (diff) | |
download | youtube-dl-bf50b0383e4d6728bbbf1d0ee70cf586a90efb40.tar.gz youtube-dl-bf50b0383e4d6728bbbf1d0ee70cf586a90efb40.zip |
Fix some IEs that didn't return the uploade_date in the YYYYMMDD format
Create a function unified_strdate in utils.py to fix these problems
Diffstat (limited to 'youtube_dl/utils.py')
-rw-r--r-- | youtube_dl/utils.py | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py index e5d756b8b..3a2f0022f 100644 --- a/youtube_dl/utils.py +++ b/youtube_dl/utils.py @@ -569,7 +569,22 @@ 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(',',' ') + # %z (UTC offset) is only supported in python>=3.2 + date_str = re.sub(r' (\+|-)[\d]*$', '', date_str) + format_expressions = ['%d %B %Y', '%B %d %Y', '%b %d %Y', '%Y-%m-%d', '%d/%m/%Y', '%Y/%m/%d %H:%M:%S'] + for expression in format_expressions: + try: + upload_date = datetime.datetime.strptime(date_str, expression).strftime('%Y%m%d') + except: + pass + return upload_date + def date_from_str(date_str): """Return a datetime object from a string in the format YYYYMMDD""" return datetime.datetime.strptime(date_str, "%Y%m%d").date() |