1
0
mirror of https://github.com/ytdl-org/youtube-dl.git synced 2025-01-22 19:42:14 +01:00

[YouTube] Use X-Goog-Visitor-Id

* required with tv player client
* resolves #33030
This commit is contained in:
dirkf 2025-01-22 06:52:40 +00:00
parent 63fb0fc415
commit 5975d7bb96

View File

@ -142,6 +142,7 @@ class YoutubeBaseInfoExtractor(InfoExtractor):
def _login(self): def _login(self):
""" """
Attempt to log in to YouTube. Attempt to log in to YouTube.
True is returned if successful or skipped. True is returned if successful or skipped.
False is returned if login failed. False is returned if login failed.
@ -2040,6 +2041,11 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
client_names = traverse_obj(self._INNERTUBE_CLIENTS, ( client_names = traverse_obj(self._INNERTUBE_CLIENTS, (
T(dict.items), lambda _, k_v: not k_v[1].get('REQUIRE_PO_TOKEN'), T(dict.items), lambda _, k_v: not k_v[1].get('REQUIRE_PO_TOKEN'),
0))[:1] 0))[:1]
if 'web' not in client_names:
# webpage links won't download: ignore links and playability
player_response = filter_dict(
player_response or {},
lambda k, _: k not in ('streamingData', 'playabilityStatus'))
if is_live and 'ios' not in client_names: if is_live and 'ios' not in client_names:
client_names.append('ios') client_names.append('ios')
@ -2047,7 +2053,7 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
headers = { headers = {
'Sec-Fetch-Mode': 'navigate', 'Sec-Fetch-Mode': 'navigate',
'Origin': origin, 'Origin': origin,
# 'X-Goog-Visitor-Id': self._extract_visitor_data(ytcfg) or '', 'X-Goog-Visitor-Id': self._extract_visitor_data(ytcfg) or '',
} }
auth = self._generate_sapisidhash_header(origin) auth = self._generate_sapisidhash_header(origin)
if auth is not None: if auth is not None:
@ -2059,9 +2065,9 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
query = { query = {
'playbackContext': { 'playbackContext': {
'contentPlaybackContext': pb_context, 'contentPlaybackContext': pb_context,
},
'contentCheckOk': True, 'contentCheckOk': True,
'racyCheckOk': True, 'racyCheckOk': True,
},
'context': { 'context': {
'client': merge_dicts( 'client': merge_dicts(
traverse_obj(client, ('INNERTUBE_CONTEXT', 'client')), { traverse_obj(client, ('INNERTUBE_CONTEXT', 'client')), {
@ -2088,11 +2094,10 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
'context', 'client', 'clientName')), 'context', 'client', 'clientName')),
'API JSON', delim=' ')) 'API JSON', delim=' '))
hls = [ hls = traverse_obj(
traverse_obj( (player_response, api_player_response),
resp, ('streamingData', 'hlsManifestUrl', T(url_or_none))) (Ellipsis, 'streamingData', 'hlsManifestUrl', T(url_or_none)))
for resp in (player_response, api_player_response)] if len(hls) == 2 and not hls[0] and hls[1]:
if not hls[0] and hls[1]:
player_response['streamingData']['hlsManifestUrl'] = hls[1] player_response['streamingData']['hlsManifestUrl'] = hls[1]
else: else:
video_details = merge_dicts(*traverse_obj( video_details = merge_dicts(*traverse_obj(
@ -3467,7 +3472,7 @@ class YoutubeTabIE(YoutubeBaseInfoExtractor):
if not continuation: if not continuation:
break break
if visitor_data: if visitor_data:
headers['x-goog-visitor-id'] = visitor_data headers['X-Goog-Visitor-Id'] = visitor_data
data['continuation'] = continuation['continuation'] data['continuation'] = continuation['continuation']
data['clickTracking'] = { data['clickTracking'] = {
'clickTrackingParams': continuation['itct'], 'clickTrackingParams': continuation['itct'],