Skip to content

Commit

Permalink
YouTubeVideoUrl: use android test suite client, thx SamantazFox
Browse files Browse the repository at this point in the history
  • Loading branch information
Taapat committed Apr 29, 2024
1 parent aa1d1ad commit 3d0cd83
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions src/YouTubeVideoUrl.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,8 @@ def _extract_dash_audio_format(self, streaming_formats, player_id):
def _extract_player_response(self, video_id, client):
player_id = None
url = 'https://www.youtube.com/youtubei/v1/player?key=%s&bpctr=9999999999&has_verified=1' % (YT_EMBKEY if client == 85 else YT_KEY)
ANDROID = '18.48.37'
USER_AGENT = 'com.google.android.youtube/%s(Linux; U; Android 13; en_US; sdk_gphone64_x86_64 Build/UPB4.230623.005) gzip' % ANDROID
ANDROID = '1.9'
USER_AGENT = 'com.google.android.youtube/%s (Linux; U; Android 12; US) gzip' % ANDROID
data = {
'videoId': video_id,
'playbackContext': {
Expand All @@ -280,7 +280,8 @@ def _extract_player_response(self, video_id, client):
}
headers = {
'content-type': 'application/json',
'Origin': 'https://www.youtube.com'
'Origin': 'https://www.youtube.com',
'X-YouTube-Client-Name': client
}
if client in (1, 85):
player_id = self._extract_player_info()
Expand All @@ -304,7 +305,6 @@ def _extract_player_response(self, video_id, client):
'embedUrl': 'https://www.youtube.com/'
}
}
headers['X-YouTube-Client-Name'] = 85
headers['X-YouTube-Client-Version'] = '2.0'
else:
data['context'] = {
Expand All @@ -314,22 +314,20 @@ def _extract_player_response(self, video_id, client):
'clientVersion': '2.20220801.00.00',
}
}
headers['X-YouTube-Client-Name'] = 1
headers['X-YouTube-Client-Version'] = '2.20220801.00.00'
else:
data['context'] = {
'client': {
'hl': config.plugins.YouTube.searchLanguage.value,
'clientVersion': ANDROID,
'androidSdkVersion': 33,
'clientName': 'ANDROID',
'androidSdkVersion': 31,
'clientName': 'ANDROID_TESTSUITE',
'osName': 'Android',
'osVersion': '13',
'osVersion': '12',
'userAgent': USER_AGENT
}
}
data['params'] = 'wgYCCAA='
headers['X-YouTube-Client-Name'] = 3
data['params'] = '2AMB'
headers['X-YouTube-Client-Version'] = ANDROID
headers['User-Agent'] = USER_AGENT
try:
Expand All @@ -353,7 +351,7 @@ def _real_extract(self, video_id):
)
url = ''

player_response, player_id = self._extract_player_response(video_id, 3)
player_response, player_id = self._extract_player_response(video_id, 30)
if not player_response:
raise RuntimeError('Player response not found!')

Expand Down

0 comments on commit 3d0cd83

Please sign in to comment.