aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpukkandan <pukkandan.ytdlp@gmail.com>2021-09-19 17:45:41 +0530
committerpukkandan <pukkandan.ytdlp@gmail.com>2021-09-19 17:45:49 +0530
commitf137e4c27ccaecae3fd0acb58a01e8e5faccaa88 (patch)
tree51bc62566f347ef9d2cc5c7754950df9ec838104
parent47626219253f18dbaf578b16f2f4499705e096de (diff)
downloadhypervideo-pre-f137e4c27ccaecae3fd0acb58a01e8e5faccaa88.tar.lz
hypervideo-pre-f137e4c27ccaecae3fd0acb58a01e8e5faccaa88.tar.xz
hypervideo-pre-f137e4c27ccaecae3fd0acb58a01e8e5faccaa88.zip
[utils] Improve `extract_timezone`
Code taken from: https://github.com/ytdl-org/youtube-dl/pull/29845 Fixes: https://github.com/ytdl-org/youtube-dl/issues/29948 Authored by: dirkf
-rw-r--r--yt_dlp/utils.py12
1 files changed, 10 insertions, 2 deletions
diff --git a/yt_dlp/utils.py b/yt_dlp/utils.py
index 983ca6ced..4c0ac5a25 100644
--- a/yt_dlp/utils.py
+++ b/yt_dlp/utils.py
@@ -3034,8 +3034,16 @@ class YoutubeDLRedirectHandler(compat_urllib_request.HTTPRedirectHandler):
def extract_timezone(date_str):
m = re.search(
- r'^.{8,}?(?P<tz>Z$| ?(?P<sign>\+|-)(?P<hours>[0-9]{2}):?(?P<minutes>[0-9]{2})$)',
- date_str)
+ r'''(?x)
+ ^.{8,}? # >=8 char non-TZ prefix, if present
+ (?P<tz>Z| # just the UTC Z, or
+ (?:(?<=.\b\d{4}|\b\d{2}:\d\d)| # preceded by 4 digits or hh:mm or
+ (?<!.\b[a-zA-Z]{3}|[a-zA-Z]{4}|..\b\d\d)) # not preceded by 3 alpha word or >= 4 alpha or 2 digits
+ [ ]? # optional space
+ (?P<sign>\+|-) # +/-
+ (?P<hours>[0-9]{2}):?(?P<minutes>[0-9]{2}) # hh[:]mm
+ $)
+ ''', date_str)
if not m:
timezone = datetime.timedelta()
else: