From b6d09eb59b77c688422a721f2154b49177ed1234 Mon Sep 17 00:00:00 2001 From: croneter Date: Wed, 3 Nov 2021 07:43:44 +0100 Subject: [PATCH] Fix generating new PKC unique device ID not working --- default.py | 20 ++------------------ resources/lib/clientinfo.py | 27 ++++++++++++++------------- resources/lib/service_entry.py | 3 +++ 3 files changed, 19 insertions(+), 31 deletions(-) diff --git a/default.py b/default.py index 8eab9599..e2d8c187 100644 --- a/default.py +++ b/default.py @@ -117,7 +117,8 @@ class Main(object): transfer.plex_command('choose_pms_server') elif mode == 'deviceid': - self.deviceid() + LOG.info('New PKC UUID / unique device id requested') + transfer.plex_command('generate_new_uuid') elif mode == 'fanart': LOG.info('User requested fanarttv refresh') @@ -173,23 +174,6 @@ class Main(object): # Received a xbmcgui.ListItem() xbmcplugin.setResolvedUrl(HANDLE, True, result) - @staticmethod - def deviceid(): - window = xbmcgui.Window(10000) - deviceId_old = window.getProperty('plex_client_Id') - from resources.lib import clientinfo - try: - deviceId = clientinfo.getDeviceId(reset=True) - except Exception as e: - LOG.error('Failed to generate a new device Id: %s' % e) - utils.messageDialog(utils.lang(29999), utils.lang(33032)) - else: - LOG.info('Successfully removed old device ID: %s New deviceId:' - '%s' % (deviceId_old, deviceId)) - # 'Kodi will now restart to apply the changes' - utils.messageDialog(utils.lang(29999), utils.lang(33033)) - xbmc.executebuiltin('RestartApp') - if __name__ == '__main__': LOG.info('%s started' % v.ADDON_ID) diff --git a/resources/lib/clientinfo.py b/resources/lib/clientinfo.py index 92b7ebf5..5c5e51d8 100644 --- a/resources/lib/clientinfo.py +++ b/resources/lib/clientinfo.py @@ -59,10 +59,20 @@ def getDeviceId(reset=False): If id does not exist, create one and save in Kodi settings file. """ - if reset is True: - v.PKC_MACHINE_IDENTIFIER = None - utils.window('plex_client_Id', clear=True) - utils.settings('plex_client_Id', value="") + if reset: + LOG.info("Generating a new deviceid.") + from uuid import uuid4 + client_id = str(uuid4()) + utils.settings('plex_client_Id', value=client_id) + v.PKC_MACHINE_IDENTIFIER = client_id + utils.window('plex_client_Id', value=client_id) + LOG.info("Unique device Id plex_client_Id generated: %s", client_id) + # IF WE EXIT KODI NOW, THE SETTING WON'T STICK! + # 'Kodi will now restart to apply the changes' + # utils.messageDialog(utils.lang(29999), utils.lang(33033)) + # xbmc.executebuiltin('RestartApp') + utils.messageDialog(utils.lang(29999), 'Please restart Kodi now!') + return client_id client_id = v.PKC_MACHINE_IDENTIFIER if client_id: @@ -75,12 +85,3 @@ def getDeviceId(reset=False): utils.window('plex_client_Id', value=client_id) LOG.info("Unique device Id plex_client_Id loaded: %s", client_id) return client_id - - LOG.info("Generating a new deviceid.") - from uuid import uuid4 - client_id = str(uuid4()) - utils.settings('plex_client_Id', value=client_id) - v.PKC_MACHINE_IDENTIFIER = client_id - utils.window('plex_client_Id', value=client_id) - LOG.info("Unique device Id plex_client_Id generated: %s", client_id) - return client_id diff --git a/resources/lib/service_entry.py b/resources/lib/service_entry.py index ce3e9678..4c9ec757 100644 --- a/resources/lib/service_entry.py +++ b/resources/lib/service_entry.py @@ -498,6 +498,9 @@ class Service(object): elif plex_command == 'EXIT-PKC': LOG.info('Received command from another instance to quit') app.APP.stop_pkc = True + elif plex_command == 'generate_new_uuid': + LOG.info('Generating new UUID for PKC') + clientinfo.getDeviceId(reset=True) else: raise RuntimeError('Unknown command: %s', plex_command) if task: