From 0d58e29cc272e7125c6afd19fbe1459bf42e592d Mon Sep 17 00:00:00 2001 From: MoojMidge <56883549+MoojMidge@users.noreply.github.com> Date: Sat, 3 Aug 2024 14:55:29 +1000 Subject: [PATCH] Update client details --- .../youtube/client/request_client.py | 154 ++++++++---------- .../youtube_plugin/youtube/client/youtube.py | 10 -- .../youtube/helper/stream_info.py | 2 +- 3 files changed, 70 insertions(+), 96 deletions(-) diff --git a/resources/lib/youtube_plugin/youtube/client/request_client.py b/resources/lib/youtube_plugin/youtube/client/request_client.py index 465cc3222..2279dc63d 100644 --- a/resources/lib/youtube_plugin/youtube/client/request_client.py +++ b/resources/lib/youtube_plugin/youtube/client/request_client.py @@ -15,32 +15,31 @@ class YouTubeRequestClient(BaseRequestsClass): - _ANDROID_PARAMS = 'CgIIAdgDAQ==' - # yt-dlp has chosen the following value, but this results in the android - # player response returning unexpected details sometimes. To be investigated - # _ANDROID_PARAMS = 'CgIIAQ==' _API_KEYS = { 'android': 'AIzaSyA8eiZmM1FaDVjRy-df2KTyQ_vz_yYM39w', 'android_embedded': 'AIzaSyCjc_pVEDi4qsv5MtC2dMXzpIaDoRFLsxw', 'ios': 'AIzaSyB-63vPrdThhKuerbB2N_l7Kwwcxj6yUAc', + 'smart_tv': 'AIzaSyDCU8hByM-4DrUqRUYnGn-3llEO78bcxq8', 'web': 'AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8', } + _PLAYER_PARAMS = { + 'android': 'CgIIAdgDAQ==', + 'android_testsuite': '2AMB', + } CLIENTS = { - # 4k no VP9 HDR - # Limited subtitle availability - 'android_testsuite': { - '_id': 30, - '_query_subtitles': True, + 'android': { + '_id': 3, + '_disabled': True, + '_query_subtitles': 'optional', 'json': { - 'params': _ANDROID_PARAMS, 'context': { 'client': { - 'clientName': 'ANDROID_TESTSUITE', - 'clientVersion': '1.9', - 'androidSdkVersion': '34', + 'clientName': 'ANDROID', + 'clientVersion': '19.29.37', + 'androidSdkVersion': '30', 'osName': 'Android', - 'osVersion': '14', + 'osVersion': '11', 'platform': 'MOBILE', }, }, @@ -49,76 +48,68 @@ class YouTubeRequestClient(BaseRequestsClass): 'User-Agent': ('com.google.android.youtube/' '{json[context][client][clientVersion]}' ' (Linux; U; {json[context][client][osName]}' - ' {json[context][client][osVersion]};' - ' {json[context][client][gl]}) gzip'), + ' {json[context][client][osVersion]}) gzip'), 'X-YouTube-Client-Name': '{_id}', 'X-YouTube-Client-Version': '{json[context][client][clientVersion]}', }, - 'params': { - 'key': _API_KEYS['android'], - }, }, - 'android': { - '_id': 3, + # Only for videos that allow embedding + # Limited to 720p on some videos + 'android_embedded': { + '_id': 55, '_disabled': True, '_query_subtitles': 'optional', 'json': { 'context': { 'client': { - 'clientName': 'ANDROID', - 'clientVersion': '19.17.34', - 'androidSdkVersion': '34', + 'clientName': 'ANDROID_EMBEDDED_PLAYER', + 'clientScreen': 'EMBED', + 'clientVersion': '19.29.37', + 'androidSdkVersion': '30', 'osName': 'Android', - 'osVersion': '14', + 'osVersion': '11', 'platform': 'MOBILE', }, }, + 'thirdParty': { + 'embedUrl': 'https://www.youtube.com/embed/{json[videoId]}', + }, }, 'headers': { 'User-Agent': ('com.google.android.youtube/' '{json[context][client][clientVersion]}' ' (Linux; U; {json[context][client][osName]}' - ' {json[context][client][osVersion]};' - ' {json[context][client][gl]}) gzip'), + ' {json[context][client][osVersion]}) gzip'), 'X-YouTube-Client-Name': '{_id}', 'X-YouTube-Client-Version': '{json[context][client][clientVersion]}', }, }, - # Only for videos that allow embedding - # Limited to 720p on some videos - 'android_embedded': { - '_id': 55, - '_disabled': True, - '_query_subtitles': 'optional', + # 4k no VP9 HDR + # Limited subtitle availability + 'android_testsuite': { + '_id': 30, + '_query_subtitles': True, 'json': { - 'params': _ANDROID_PARAMS, + 'params': _PLAYER_PARAMS['android_testsuite'], 'context': { 'client': { - 'clientName': 'ANDROID_EMBEDDED_PLAYER', - 'clientScreen': 'EMBED', - 'clientVersion': '19.17.34', - 'androidSdkVersion': '34', + 'clientName': 'ANDROID_TESTSUITE', + 'clientVersion': '1.9', + 'androidSdkVersion': '30', 'osName': 'Android', - 'osVersion': '14', + 'osVersion': '11', 'platform': 'MOBILE', }, }, - 'thirdParty': { - 'embedUrl': 'https://www.youtube.com/embed/{json[videoId]}', - }, }, 'headers': { 'User-Agent': ('com.google.android.youtube/' '{json[context][client][clientVersion]}' ' (Linux; U; {json[context][client][osName]}' - ' {json[context][client][osVersion]};' - ' {json[context][client][gl]}) gzip'), + ' {json[context][client][osVersion]}) gzip'), 'X-YouTube-Client-Name': '{_id}', 'X-YouTube-Client-Version': '{json[context][client][clientVersion]}', }, - 'params': { - 'key': _API_KEYS['android_embedded'], - }, }, # 4k with HDR # Some videos block this client, may also require embedding enabled @@ -127,14 +118,14 @@ class YouTubeRequestClient(BaseRequestsClass): '_id': 29, '_query_subtitles': True, 'json': { - 'params': _ANDROID_PARAMS, + 'params': _PLAYER_PARAMS['android'], 'context': { 'client': { 'clientName': 'ANDROID_UNPLUGGED', 'clientVersion': '8.12.0', - 'androidSdkVersion': '34', + 'androidSdkVersion': '30', 'osName': 'Android', - 'osVersion': '14', + 'osVersion': '11', 'platform': 'MOBILE', }, }, @@ -143,28 +134,25 @@ class YouTubeRequestClient(BaseRequestsClass): 'User-Agent': ('com.google.android.apps.youtube.unplugged/' '{json[context][client][clientVersion]}' ' (Linux; U; {json[context][client][osName]}' - ' {json[context][client][osVersion]};' - ' {json[context][client][gl]}) gzip'), + ' {json[context][client][osVersion]}) gzip'), 'X-YouTube-Client-Name': '{_id}', 'X-YouTube-Client-Version': '{json[context][client][clientVersion]}', }, - 'params': { - 'key': _API_KEYS['android'], - }, }, 'ios': { '_id': 5, '_os': { 'major': '17', - 'minor': '4', + 'minor': '5', 'patch': '1', - 'build': '21E236', + 'build': '21F90', }, 'json': { 'context': { 'client': { 'clientName': 'IOS', - 'clientVersion': '19.16.3', + 'clientVersion': '19.29.1', + 'deviceMake': 'Apple', 'deviceModel': 'iPhone16,2', 'osName': 'iOS', 'osVersion': '{_os[major]}.{_os[minor]}.{_os[patch]}.{_os[build]}', @@ -183,9 +171,22 @@ class YouTubeRequestClient(BaseRequestsClass): 'X-YouTube-Client-Version': '{json[context][client][clientVersion]}', }, }, + 'media_connect_frontend': { + '_id': 95, + '_query_subtitles': True, + 'json': { + 'context': { + 'client': { + 'clientName': 'MEDIA_CONNECT_FRONTEND', + 'clientVersion': '0.1', + }, + }, + }, + 'headers': {}, + }, # Used to requests captions for clients that don't provide them # Requires handling of nsig to overcome throttling (TODO) - 'smarttv_embedded': { + 'smart_tv_embedded': { '_id': 85, 'json': { 'context': { @@ -205,25 +206,6 @@ class YouTubeRequestClient(BaseRequestsClass): ' AppleWebKit/537.36 (KHTML, like Gecko)' ' 85.0.4183.93/6.5 TV Safari/537.36'), }, - 'params': { - 'key': _API_KEYS['web'], - }, - }, - 'media_connect_frontend': { - '_id': 95, - '_query_subtitles': True, - 'json': { - 'context': { - 'client': { - 'clientName': 'MEDIA_CONNECT_FRONTEND', - 'clientVersion': '0.1', - }, - }, - }, - 'headers': {}, - 'params': { - 'key': _API_KEYS['web'], - }, }, # Used for misc api requests by default # Requires handling of nsig to overcome throttling (TODO) @@ -233,7 +215,7 @@ class YouTubeRequestClient(BaseRequestsClass): 'context': { 'client': { 'clientName': 'WEB', - 'clientVersion': '2.20240304.00.00', + 'clientVersion': '2.20240726.00.00', }, }, }, @@ -245,9 +227,6 @@ class YouTubeRequestClient(BaseRequestsClass): ' Chrome/80.0.3987.162 Mobile Safari/537.36'), 'Referer': 'https://www.youtube.com/watch?v={json[videoId]}' }, - 'params': { - 'key': _API_KEYS['web'], - }, }, '_common': { '_access_token': None, @@ -374,10 +353,15 @@ def build_client(cls, client_name=None, data=None): client['_name'] = client_name try: + params = client['params'] if client.get('_access_token'): - del client['params']['key'] - elif 'Authorization' in client['headers']: - del client['headers']['Authorization'] + if 'key' in params: + del params['key'] + else: + if 'Authorization' in client['headers']: + del client['headers']['Authorization'] + if 'key' in params and not params['key']: + del params['key'] except KeyError: pass diff --git a/resources/lib/youtube_plugin/youtube/client/youtube.py b/resources/lib/youtube_plugin/youtube/client/youtube.py index aa80b0b06..f467d11f5 100644 --- a/resources/lib/youtube_plugin/youtube/client/youtube.py +++ b/resources/lib/youtube_plugin/youtube/client/youtube.py @@ -45,9 +45,6 @@ class YouTube(LoginClient): 'headers': { 'Host': 'www.youtube.com', }, - 'params': { - 'key': 'AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8', - }, }, 3: { 'url': 'https://www.googleapis.com/youtube/v3/{_endpoint}', @@ -70,9 +67,6 @@ class YouTube(LoginClient): 'headers': { 'Host': 'www.youtube.com', }, - 'params': { - 'key': 'AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8', - }, }, 'tv_embed': { 'url': 'https://www.youtube.com/youtubei/v1/{_endpoint}', @@ -88,9 +82,6 @@ class YouTube(LoginClient): 'headers': { 'Host': 'www.youtube.com', }, - 'params': { - 'key': 'AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8', - }, }, '_common': { '_access_token': None, @@ -122,7 +113,6 @@ class YouTube(LoginClient): ' Chrome/80.0.3987.162 Mobile Safari/537.36'), }, 'params': { - 'key': None, 'prettyPrint': 'false' }, }, diff --git a/resources/lib/youtube_plugin/youtube/helper/stream_info.py b/resources/lib/youtube_plugin/youtube/helper/stream_info.py index 35b3901f5..aeedbf1b3 100644 --- a/resources/lib/youtube_plugin/youtube/helper/stream_info.py +++ b/resources/lib/youtube_plugin/youtube/helper/stream_info.py @@ -1651,7 +1651,7 @@ def load_stream_info(self, video_id): query_subtitles is True or (query_subtitles and subtitles.sub_selection == subtitles.LANG_ALL)): - for client_name in ('smarttv_embedded', 'web', 'android'): + for client_name in ('smart_tv_embedded', 'web', 'android'): caption_client = self.build_client(client_name, client_data) if not caption_client: continue