aboutsummaryrefslogtreecommitdiff
path: root/youtube_dl/utils.py
diff options
context:
space:
mode:
authorPhilipp Hagemeister <phihag@phihag.de>2015-02-12 08:55:06 +0100
committerPhilipp Hagemeister <phihag@phihag.de>2015-02-12 08:55:06 +0100
commit08b38d54015706d90d05371455ba86b7887cabcc (patch)
tree9dd7da977d72766f80c6415fbbfeb07cbb20c9a7 /youtube_dl/utils.py
parent024c53694d674f046fdad593e03bfaeec17cc559 (diff)
downloadyoutube-dl-08b38d54015706d90d05371455ba86b7887cabcc.tar.xz
[camdemy] Simplify and make more robust (#4938)
Do not throw errors if view count or upload date extraction fails. Dispose of re.MULTILINE, which had absolutely no effect without any ^ or $ in sight. Follow PEP8 naming conventions.
Diffstat (limited to 'youtube_dl/utils.py')
-rw-r--r--youtube_dl/utils.py27
1 files changed, 14 insertions, 13 deletions
diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py
index 03566d223..54fa17c38 100644
--- a/youtube_dl/utils.py
+++ b/youtube_dl/utils.py
@@ -666,26 +666,27 @@ class YoutubeDLHTTPSHandler(compat_urllib_request.HTTPSHandler):
req, **kwargs)
-def parse_iso8601(date_str, delimiter='T'):
+def parse_iso8601(date_str, delimiter='T', timezone=None):
""" Return a UNIX timestamp from the given date """
if date_str is None:
return None
- m = re.search(
- r'(\.[0-9]+)?(?:Z$| ?(?P<sign>\+|-)(?P<hours>[0-9]{2}):?(?P<minutes>[0-9]{2})$)',
- date_str)
- if not m:
- timezone = datetime.timedelta()
- else:
- date_str = date_str[:-len(m.group(0))]
- if not m.group('sign'):
+ if timezone is None:
+ m = re.search(
+ r'(\.[0-9]+)?(?:Z$| ?(?P<sign>\+|-)(?P<hours>[0-9]{2}):?(?P<minutes>[0-9]{2})$)',
+ date_str)
+ if not m:
timezone = datetime.timedelta()
else:
- sign = 1 if m.group('sign') == '+' else -1
- timezone = datetime.timedelta(
- hours=sign * int(m.group('hours')),
- minutes=sign * int(m.group('minutes')))
+ date_str = date_str[:-len(m.group(0))]
+ if not m.group('sign'):
+ timezone = datetime.timedelta()
+ else:
+ sign = 1 if m.group('sign') == '+' else -1
+ timezone = datetime.timedelta(
+ hours=sign * int(m.group('hours')),
+ minutes=sign * int(m.group('minutes')))
date_format = '%Y-%m-%d{0}%H:%M:%S'.format(delimiter)
dt = datetime.datetime.strptime(date_str, date_format) - timezone
return calendar.timegm(dt.timetuple())