aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcoletdjnz <colethedj@protonmail.com>2022-01-20 15:02:01 +0000
committerGitHub <noreply@github.com>2022-01-20 20:32:01 +0530
commit396a76f7bf1623f8c0e90d6305315502da2f6ba7 (patch)
tree127e86dfb6d142719298ea429eb2097eeda9dfbd
parent301d07fc4bb37ae3bec607b62d52f3ee6c087df1 (diff)
downloadhypervideo-pre-396a76f7bf1623f8c0e90d6305315502da2f6ba7.tar.lz
hypervideo-pre-396a76f7bf1623f8c0e90d6305315502da2f6ba7.tar.xz
hypervideo-pre-396a76f7bf1623f8c0e90d6305315502da2f6ba7.zip
[youtube] Enforce UTC (#2402)
and [utils] use `utcnow` in `datetime_from_str` Related: #2223 Authored by: coletdjnz
-rw-r--r--yt_dlp/extractor/youtube.py10
-rw-r--r--yt_dlp/utils.py2
2 files changed, 7 insertions, 5 deletions
diff --git a/yt_dlp/extractor/youtube.py b/yt_dlp/extractor/youtube.py
index 44ec579c0..988135516 100644
--- a/yt_dlp/extractor/youtube.py
+++ b/yt_dlp/extractor/youtube.py
@@ -373,7 +373,7 @@ class YoutubeBaseInfoExtractor(InfoExtractor):
pref = dict(compat_urlparse.parse_qsl(pref_cookie.value))
except ValueError:
self.report_warning('Failed to parse user PREF cookie' + bug_reports_message())
- pref.update({'hl': 'en'})
+ pref.update({'hl': 'en', 'tz': 'UTC'})
self._set_cookie('.youtube.com', name='PREF', value=compat_urllib_parse_urlencode(pref))
def _real_initialize(self):
@@ -412,8 +412,9 @@ class YoutubeBaseInfoExtractor(InfoExtractor):
def _extract_context(self, ytcfg=None, default_client='web'):
context = get_first(
(ytcfg, self._get_default_ytcfg(default_client)), 'INNERTUBE_CONTEXT', expected_type=dict)
- # Enforce language for extraction
- traverse_obj(context, 'client', expected_type=dict, default={})['hl'] = 'en'
+ # Enforce language and tz for extraction
+ client_context = traverse_obj(context, 'client', expected_type=dict, default={})
+ client_context.update({'hl': 'en', 'timeZone': 'UTC', 'utcOffsetMinutes': 0})
return context
_SAPISID = None
@@ -729,7 +730,8 @@ class YoutubeBaseInfoExtractor(InfoExtractor):
timestamp = (
unified_timestamp(text) or unified_timestamp(
self._search_regex(
- (r'(?:.+|^)(?:live|premieres|ed|ing)(?:\s*on)?\s*(.+\d)', r'\w+[\s,\.-]*\w+[\s,\.-]+20\d{2}'), text.lower(), 'time text', default=None)))
+ (r'(?:.+|^)(?:live|premieres|ed|ing)(?:\s*on)?\s*(.+\d)', r'\w+[\s,\.-]*\w+[\s,\.-]+20\d{2}'),
+ text.lower(), 'time text', default=None)))
if text and timestamp is None:
self.report_warning('Cannot parse localized time text' + bug_reports_message(), only_once=True)
diff --git a/yt_dlp/utils.py b/yt_dlp/utils.py
index d58c68653..89e1ca7fd 100644
--- a/yt_dlp/utils.py
+++ b/yt_dlp/utils.py
@@ -1846,7 +1846,7 @@ def datetime_from_str(date_str, precision='auto', format='%Y%m%d'):
if precision == 'auto':
auto_precision = True
precision = 'microsecond'
- today = datetime_round(datetime.datetime.now(), precision)
+ today = datetime_round(datetime.datetime.utcnow(), precision)
if date_str in ('now', 'today'):
return today
if date_str == 'yesterday':