mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-09-06 02:49:35 +02:00
[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
This commit is contained in:
parent
4762621925
commit
f137e4c27c
@ -3034,8 +3034,16 @@ def redirect_request(self, req, fp, code, msg, headers, newurl):
|
|||||||
|
|
||||||
def extract_timezone(date_str):
|
def extract_timezone(date_str):
|
||||||
m = re.search(
|
m = re.search(
|
||||||
r'^.{8,}?(?P<tz>Z$| ?(?P<sign>\+|-)(?P<hours>[0-9]{2}):?(?P<minutes>[0-9]{2})$)',
|
r'''(?x)
|
||||||
date_str)
|
^.{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:
|
if not m:
|
||||||
timezone = datetime.timedelta()
|
timezone = datetime.timedelta()
|
||||||
else:
|
else:
|
||||||
|
Loading…
Reference in New Issue
Block a user