Skip to content

Commit

Permalink
Update client details
Browse files Browse the repository at this point in the history
  • Loading branch information
MoojMidge committed Aug 3, 2024
1 parent d924236 commit 0d58e29
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 96 deletions.
154 changes: 69 additions & 85 deletions resources/lib/youtube_plugin/youtube/client/request_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
},
Expand All @@ -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
Expand All @@ -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',
},
},
Expand All @@ -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]}',
Expand All @@ -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': {
Expand All @@ -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)
Expand All @@ -233,7 +215,7 @@ class YouTubeRequestClient(BaseRequestsClass):
'context': {
'client': {
'clientName': 'WEB',
'clientVersion': '2.20240304.00.00',
'clientVersion': '2.20240726.00.00',
},
},
},
Expand All @@ -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,
Expand Down Expand Up @@ -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

Expand Down
10 changes: 0 additions & 10 deletions resources/lib/youtube_plugin/youtube/client/youtube.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}',
Expand All @@ -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}',
Expand All @@ -88,9 +82,6 @@ class YouTube(LoginClient):
'headers': {
'Host': 'www.youtube.com',
},
'params': {
'key': 'AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8',
},
},
'_common': {
'_access_token': None,
Expand Down Expand Up @@ -122,7 +113,6 @@ class YouTube(LoginClient):
' Chrome/80.0.3987.162 Mobile Safari/537.36'),
},
'params': {
'key': None,
'prettyPrint': 'false'
},
},
Expand Down
2 changes: 1 addition & 1 deletion resources/lib/youtube_plugin/youtube/helper/stream_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0d58e29

Please sign in to comment.