Skip to content

Commit 994c667

Browse files
committed
Re-initialise existing client instance in preference to creating new instance when context changes
- Make kodiai happy
1 parent b54a30d commit 994c667

1 file changed

Lines changed: 13 additions & 11 deletions

File tree

resources/lib/youtube_plugin/youtube/provider.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,6 @@ def get_client(self, context, refresh=False):
145145
settings = context.get_settings()
146146

147147
user = access_manager.get_current_user()
148-
api_last_origin = access_manager.get_last_origin()
149148

150149
client = self._client
151150
if not client or not client.initialised:
@@ -222,16 +221,8 @@ def get_client(self, context, refresh=False):
222221
_,
223222
) = access_manager.get_access_tokens(dev_id)
224223

225-
if client and not client.context_changed(context):
226-
if api_last_origin != origin:
227-
access_manager.set_last_origin(origin)
228-
self.log.info(('API key origin changed - Resetting client',
229-
'Previous: {old!r}',
230-
'Current: {new!r}'),
231-
old=api_last_origin,
232-
new=origin)
233-
client.initialised = False
234-
else:
224+
api_last_origin = access_manager.get_last_origin()
225+
if not client:
235226
client = YouTubePlayerClient(
236227
context=context,
237228
language=settings.get_language(),
@@ -242,6 +233,17 @@ def get_client(self, context, refresh=False):
242233
self._client = client
243234
if api_last_origin != origin:
244235
access_manager.set_last_origin(origin)
236+
elif api_last_origin != origin:
237+
access_manager.set_last_origin(origin)
238+
self.log.info(('Resetting client - API key origin changed',
239+
'Previous: {old!r}',
240+
'Current: {new!r}'),
241+
old=api_last_origin,
242+
new=origin)
243+
client.initialised = False
244+
elif client.context_changed(context):
245+
self.log.debug('Resetting client - Current context changed')
246+
client.initialised = False
245247

246248
if not client.initialised:
247249
self.reset_client(

0 commit comments

Comments
 (0)