mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2026-03-23 18:22:09 +01:00
[ie/youtube] Fix web_embedded player client (#16177)
Closes #16077 Authored by: SparseOrnament15, bashonly Co-authored-by: bashonly <88596187+bashonly@users.noreply.github.com>
This commit is contained in:
@@ -368,7 +368,7 @@ def short_client_name(client_name):
|
|||||||
|
|
||||||
def _fix_embedded_ytcfg(ytcfg):
|
def _fix_embedded_ytcfg(ytcfg):
|
||||||
ytcfg['INNERTUBE_CONTEXT'].setdefault('thirdParty', {}).update({
|
ytcfg['INNERTUBE_CONTEXT'].setdefault('thirdParty', {}).update({
|
||||||
'embedUrl': 'https://www.youtube.com/', # Can be any valid URL
|
'embedUrl': 'https://www.reddit.com/', # Can be any valid non-YouTube URL
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
@@ -967,6 +967,7 @@ class YoutubeBaseInfoExtractor(InfoExtractor):
|
|||||||
url, video_id, note=f'Downloading {client.replace("_", " ").strip()} client config',
|
url, video_id, note=f'Downloading {client.replace("_", " ").strip()} client config',
|
||||||
headers=traverse_obj(self._get_default_ytcfg(client), {
|
headers=traverse_obj(self._get_default_ytcfg(client), {
|
||||||
'User-Agent': ('INNERTUBE_CONTEXT', 'client', 'userAgent', {str}),
|
'User-Agent': ('INNERTUBE_CONTEXT', 'client', 'userAgent', {str}),
|
||||||
|
'Referer': ('INNERTUBE_CONTEXT', 'thirdParty', 'embedUrl', {str}),
|
||||||
}))
|
}))
|
||||||
|
|
||||||
ytcfg = self.extract_ytcfg(video_id, webpage) or {}
|
ytcfg = self.extract_ytcfg(video_id, webpage) or {}
|
||||||
|
|||||||
@@ -2680,12 +2680,14 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
|
|||||||
return {'contentCheckOk': True, 'racyCheckOk': True}
|
return {'contentCheckOk': True, 'racyCheckOk': True}
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _generate_player_context(cls, sts=None, use_ad_playback_context=False):
|
def _generate_player_context(cls, sts=None, use_ad_playback_context=False, encrypted_context=None):
|
||||||
context = {
|
context = {
|
||||||
'html5Preference': 'HTML5_PREF_WANTS',
|
'html5Preference': 'HTML5_PREF_WANTS',
|
||||||
}
|
}
|
||||||
if sts is not None:
|
if sts is not None:
|
||||||
context['signatureTimestamp'] = sts
|
context['signatureTimestamp'] = sts
|
||||||
|
if encrypted_context:
|
||||||
|
context['encryptedHostFlags'] = encrypted_context
|
||||||
|
|
||||||
playback_context = {
|
playback_context = {
|
||||||
'contentPlaybackContext': context,
|
'contentPlaybackContext': context,
|
||||||
@@ -2930,7 +2932,19 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
|
|||||||
self._configuration_arg('use_ad_playback_context', ['false'])[0] != 'false'
|
self._configuration_arg('use_ad_playback_context', ['false'])[0] != 'false'
|
||||||
and traverse_obj(INNERTUBE_CLIENTS, (client, 'SUPPORTS_AD_PLAYBACK_CONTEXT', {bool})))
|
and traverse_obj(INNERTUBE_CLIENTS, (client, 'SUPPORTS_AD_PLAYBACK_CONTEXT', {bool})))
|
||||||
|
|
||||||
yt_query.update(self._generate_player_context(sts, use_ad_playback_context))
|
# web_embedded player requests may need to include encryptedHostFlags in its contentPlaybackContext.
|
||||||
|
# This can be detected with the embeds_enable_encrypted_host_flags_enforcement experiemnt flag,
|
||||||
|
# but there is no harm in including encryptedHostFlags with all web_embedded player requests.
|
||||||
|
encrypted_context = None
|
||||||
|
if client == 'web_embedded':
|
||||||
|
encrypted_context = traverse_obj(player_ytcfg, (
|
||||||
|
'WEB_PLAYER_CONTEXT_CONFIGS', 'WEB_PLAYER_CONTEXT_CONFIG_ID_EMBEDDED_PLAYER', 'encryptedHostFlags'))
|
||||||
|
|
||||||
|
yt_query.update(
|
||||||
|
self._generate_player_context(
|
||||||
|
sts=sts,
|
||||||
|
use_ad_playback_context=use_ad_playback_context,
|
||||||
|
encrypted_context=encrypted_context))
|
||||||
|
|
||||||
return self._extract_response(
|
return self._extract_response(
|
||||||
item_id=video_id, ep='player', query=yt_query,
|
item_id=video_id, ep='player', query=yt_query,
|
||||||
|
|||||||
Reference in New Issue
Block a user