From a9a4d43cb21a29c6cd950f625a04f1553aa2ba45 Mon Sep 17 00:00:00 2001 From: croneter Date: Sat, 9 Jan 2021 17:00:18 +0100 Subject: [PATCH] Improve logic when writing credentials to settings file --- resources/lib/plex_tv.py | 30 +++++------------------------- resources/lib/service_entry.py | 3 +++ 2 files changed, 8 insertions(+), 25 deletions(-) diff --git a/resources/lib/plex_tv.py b/resources/lib/plex_tv.py index 0e4ce524..ac9fb2a3 100644 --- a/resources/lib/plex_tv.py +++ b/resources/lib/plex_tv.py @@ -34,18 +34,6 @@ class HomeUser(utils.AttributeDict): return self.restricted == '1' -def homeuser_to_settings(user): - """ - Writes one HomeUser to the Kodi settings file - """ - utils.settings('myplexlogin', 'true') - utils.settings('plexLogin', user.title) - utils.settings('plexToken', user.authToken) - utils.settings('plexid', user.id) - utils.settings('plexAvatar', user.thumb) - utils.settings('plex_status', value=utils.lang(39227)) - - def switch_home_user(userid, pin, token, machine_identifier): """ Retrieves Plex home token for a Plex home user. Returns None if this fails @@ -58,8 +46,6 @@ def switch_home_user(userid, pin, token, machine_identifier): Output: usertoken Might be empty strings if no token found for the machine_identifier that was chosen - - utils.settings('userid') and utils.settings('username') with new plex token """ LOG.info('Switching to user %s', userid) url = 'https://plex.tv/api/home/users/%s/switch' % userid @@ -78,16 +64,6 @@ def switch_home_user(userid, pin, token, machine_identifier): username = xml.get('title', '') token = xml.get('authenticationToken', '') - # Write to settings file - utils.settings('username', username) - utils.settings('accessToken', token) - utils.settings('userid', xml.get('id', '')) - utils.settings('plex_restricteduser', - 'true' if xml.get('restricted', '0') == '1' - else 'false') - app.CONN.restricted_user = True if \ - xml.get('restricted', '0') == '1' else False - # Get final token to the PMS we've chosen url = 'https://plex.tv/api/resources?includeHttps=1' xml = DU().downloadUrl(url, @@ -231,7 +207,11 @@ def sign_in_with_pin(): if xml is None: return user = HomeUser(xml.attrib) - homeuser_to_settings(user) + utils.settings('myplexlogin', 'true') + utils.settings('plex_status', value=utils.lang(39227)) + utils.settings('plexLogin', user.title) + utils.settings('plexid', user.id) + utils.settings('plexToken', user.authToken) return user diff --git a/resources/lib/service_entry.py b/resources/lib/service_entry.py index e17ac039..86356107 100644 --- a/resources/lib/service_entry.py +++ b/resources/lib/service_entry.py @@ -414,8 +414,11 @@ class Service(object): utils.settings('username', value=username) utils.settings('userid', value=user_id) utils.settings('accessToken', value=token) + utils.settings('plex_restricteduser', + 'true' if user.isManaged else 'false') app.ACCOUNT.load() app.ACCOUNT.set_authenticated() + app.CONN.restricted_user = user.isManaged return True def ServiceEntryPoint(self):