Skip to content

Commit

Permalink
Skip API requests when not authorised and not strictly required
Browse files Browse the repository at this point in the history
  • Loading branch information
MoojMidge committed Oct 2, 2024
1 parent 354a428 commit e7153cd
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions resources/lib/youtube_plugin/youtube/client/youtube.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ class YouTube(LoginClient):
'headers': {
'Host': 'www.googleapis.com',
},
'auth_required': True,
},
},
'tv': {
'url': 'https://www.youtube.com/youtubei/v1/{_endpoint}',
Expand Down Expand Up @@ -2033,10 +2035,15 @@ def api_request(self,
if params:
client_data['params'] = params

abort = False
if no_login:
pass
# a config can decide if a token is allowed
if (not no_login and self._access_token
and self._config.get('token-allowed', True)):
elif self._access_token and self._config.get('token-allowed', True):
client_data['_access_token'] = self._access_token
# abort if authentication is required but not available for request
elif self.CLIENTS.get(version, {}).get('auth_required'):
abort = True

client = self.build_client(version, client_data)

Expand Down Expand Up @@ -2084,8 +2091,10 @@ def api_request(self,
params=log_params,
data=client.get('json'),
headers=log_headers))
response = self.request(response_hook=self._response_hook,
response_hook_kwargs=kwargs,
error_hook=self._error_hook,
**client)
return response
if abort and not (kwargs.get('notify') or kwargs.get('raise_exc')):
self._context.log_warning('API request: aborted')
return {}
return self.request(response_hook=self._response_hook,
response_hook_kwargs=kwargs,
error_hook=self._error_hook,
**client)

0 comments on commit e7153cd

Please sign in to comment.