Skip to content

Commit

Permalink
Add client_data parameter to YouTube.api_request method
Browse files Browse the repository at this point in the history
- Allows flexibility in passing client_data when building client details for the request
  • Loading branch information
MoojMidge committed Dec 7, 2024
1 parent ad42741 commit faa0c00
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions resources/lib/youtube_plugin/youtube/client/youtube.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

class YouTube(LoginClient):
CLIENTS = {
1: {
'v1': {
'url': 'https://www.youtube.com/youtubei/v1/{_endpoint}',
'method': None,
'json': {
Expand All @@ -48,7 +48,7 @@ class YouTube(LoginClient):
'Host': 'www.youtube.com',
},
},
3: {
'v3': {
'_auth_required': True,
'url': 'https://www.googleapis.com/youtube/v3/{_endpoint}',
'method': None,
Expand Down Expand Up @@ -330,7 +330,7 @@ def unsubscribe(self, subscription_id, **kwargs):

def unsubscribe_channel(self, channel_id, **kwargs):
post_data = {'channelIds': [channel_id]}
return self.api_request(version=1,
return self.api_request(client='v1',
method='POST',
path='subscription/unsubscribe',
post_data=post_data,
Expand Down Expand Up @@ -460,7 +460,7 @@ def get_recommended_for_home(self,
}
post_data['context'] = context

result = self.api_request(version=1,
result = self.api_request(client='v1',
method='POST',
path='browse',
post_data=post_data)
Expand Down Expand Up @@ -1099,8 +1099,9 @@ def get_related_videos(self,
if page_token:
post_data['continuation'] = page_token

result = self.api_request(version=('tv' if retry == 1 else
'tv_embed' if retry == 2 else 1),
result = self.api_request(client=('tv' if retry == 1 else
'tv_embed' if retry == 2 else
'v1'),
method='POST',
path='next',
post_data=post_data,
Expand Down Expand Up @@ -2052,7 +2053,7 @@ def _perform(_playlist_idx, _page_token, _offset, _result):
else:
_post_data['browseId'] = 'FEmy_youtube'

_json_data = self.api_request(version=1,
_json_data = self.api_request(client='v1',
method='POST',
path='browse',
post_data=_post_data)
Expand Down Expand Up @@ -2147,7 +2148,7 @@ def _perform(_playlist_idx, _page_token, _offset, _result):
}

playlist_index = None
json_data = self.api_request(version=1,
json_data = self.api_request(client='v1',
method='POST',
path='browse',
post_data=_en_post_data)
Expand Down Expand Up @@ -2247,18 +2248,20 @@ def _error_hook(self, **kwargs):
return '', info, details, data, False, exception

def api_request(self,
version=3,
client='v3',
method='GET',
client_data=None,
path=None,
params=None,
post_data=None,
headers=None,
no_login=False,
**kwargs):
client_data = {
'_endpoint': path.strip('/'),
'method': method,
}
if not client_data:
client_data = {}
client_data.setdefault('method', method)
if path:
client_data['_endpoint'] = path.strip('/')
if headers:
client_data['headers'] = headers
if method in {'POST', 'PUT'}:
Expand All @@ -2279,7 +2282,7 @@ def api_request(self,
if self._access_token_tv:
client_data['_access_token_tv'] = self._access_token_tv

client = self.build_client(version, client_data)
client = self.build_client(client, client_data)
if not client:
client = {}
abort = True
Expand Down Expand Up @@ -2323,13 +2326,13 @@ def api_request(self,

context = self._context
context.log_debug('API request:'
'\n\tversion: |{version}|'
'\n\ttype: |{type}|'
'\n\tmethod: |{method}|'
'\n\tpath: |{path}|'
'\n\tparams: |{params}|'
'\n\tpost_data: |{data}|'
'\n\theaders: |{headers}|'
.format(version=version,
.format(type=client.get('_name'),
method=method,
path=path,
params=log_params,
Expand Down

0 comments on commit faa0c00

Please sign in to comment.