From f137e4c27ccaecae3fd0acb58a01e8e5faccaa88 Mon Sep 17 00:00:00 2001 From: pukkandan Date: Sun, 19 Sep 2021 17:45:41 +0530 Subject: [PATCH] [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 --- yt_dlp/utils.py | 12 ++++++++++-- 1 file 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 @@ def redirect_request(self, req, fp, code, msg, headers, newurl): def extract_timezone(date_str): m = re.search( - r'^.{8,}?(?PZ$| ?(?P\+|-)(?P[0-9]{2}):?(?P[0-9]{2})$)', - date_str) + r'''(?x) + ^.{8,}? # >=8 char non-TZ prefix, if present + (?PZ| # just the UTC Z, or + (?:(?<=.\b\d{4}|\b\d{2}:\d\d)| # preceded by 4 digits or hh:mm or + (?= 4 alpha or 2 digits + [ ]? # optional space + (?P\+|-) # +/- + (?P[0-9]{2}):?(?P[0-9]{2}) # hh[:]mm + $) + ''', date_str) if not m: timezone = datetime.timedelta() else: