Merge pull request #1690 from croneter/py3-fix-addon

Fix generating new unique device ID for PKC not working
This commit is contained in:
croneter 2021-11-03 07:59:46 +01:00 committed by GitHub
commit a89f7fa63b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 38 additions and 46 deletions

View file

@ -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)

View file

@ -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

View file

@ -496,6 +496,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:

View file

@ -114,7 +114,7 @@ def settings(setting, value=None):
"""
# We need to instantiate every single time to read changed variables!
with SETTINGS_LOCK:
addon = xbmcaddon.Addon()
addon = xbmcaddon.Addon('plugin.video.plexkodiconnect')
if value is not None:
# Takes string or unicode by default!
addon.setSetting(setting, value)

View file

@ -21,7 +21,7 @@ MARK_PLAYED_AT = 0.9
# watched?
IGNORE_SECONDS_AT_START = 60
_ADDON = Addon()
_ADDON = Addon('plugin.video.plexkodiconnect')
ADDON_NAME = 'PlexKodiConnect'
ADDON_ID = 'plugin.video.plexkodiconnect'
ADDON_VERSION = _ADDON.getAddonInfo('version')

View file

@ -198,14 +198,19 @@ class PlexWebSocketApp(websocket.WebSocketApp,
log.exception('Exception of type %s occured: %s', type(err), err)
finally:
self.close()
if self._enabled:
# Status = Not connected
message = utils.lang(15208)
else:
# Status = Disabled
message = utils.lang(24023)
utils.settings(self.name + SETTINGS_STRING,
value=utils.lang(15208))
value=message)
app.APP.deregister_thread(self)
log.info("----===## %s stopped ##===----", self.name)
def _run(self):
while not self.should_cancel():
while not self.should_cancel() and self._enabled:
# In the event the server goes offline
while self.should_suspend():
# We will be caught in this loop if either another thread
@ -231,16 +236,13 @@ class PlexWebSocketApp(websocket.WebSocketApp,
class PMSWebsocketApp(PlexWebSocketApp):
name = 'pms_websocket'
def __init__(self, *args, **kwargs):
self._enabled = utils.settings('enableBackgroundSync') == 'true'
super().__init__(*args, **kwargs)
def get_uri(self):
return get_pms_uri()
def should_suspend(self):
"""
Returns True if the thread needs to suspend.
"""
return (self._suspended or
utils.settings('enableBackgroundSync') != 'true')
def set_suspension_settings_status(self):
if utils.settings('enableBackgroundSync') != 'true':
# Status = Disabled
@ -255,6 +257,10 @@ class PMSWebsocketApp(PlexWebSocketApp):
class AlexaWebsocketApp(PlexWebSocketApp):
name = 'alexa_websocket'
def __init__(self, *args, **kwargs):
self._enabled = utils.settings('enable_alexa') == 'true'
super().__init__(*args, **kwargs)
def get_uri(self):
return get_alexa_uri()
@ -263,7 +269,6 @@ class AlexaWebsocketApp(PlexWebSocketApp):
Returns True if the thread needs to suspend.
"""
return self._suspended or \
utils.settings('enable_alexa') != 'true' or \
app.ACCOUNT.restricted_user or \
not app.ACCOUNT.plex_token

View file

@ -994,8 +994,7 @@ class WindowProperty(object):
class GlobalProperty(object):
def __init__(self, prop, val='1', end=None):
import xbmcaddon
self._addonID = xbmcaddon.Addon().getAddonInfo('id')
self._addonID = 'plugin.video.plexkodiconnect'
self.prop = prop
self.val = val
self.end = end