Merge pull request #1173 from croneter/fix-websocket
Fix websocket threads; enable PKC background sync for all Plex Home users!
This commit is contained in:
commit
50888c445c
8 changed files with 63 additions and 39 deletions
|
@ -30,3 +30,11 @@ def init(entrypoint=False):
|
||||||
SYNC = Sync(entrypoint)
|
SYNC = Sync(entrypoint)
|
||||||
if not entrypoint:
|
if not entrypoint:
|
||||||
PLAYSTATE = PlayState()
|
PLAYSTATE = PlayState()
|
||||||
|
|
||||||
|
def reload():
|
||||||
|
"""
|
||||||
|
Reload PKC settings from xml file, e.g. on user-switch
|
||||||
|
"""
|
||||||
|
global APP, SYNC
|
||||||
|
APP.reload()
|
||||||
|
SYNC.reload()
|
||||||
|
|
|
@ -22,7 +22,7 @@ class App(object):
|
||||||
if entrypoint:
|
if entrypoint:
|
||||||
self.load_entrypoint()
|
self.load_entrypoint()
|
||||||
else:
|
else:
|
||||||
self.load()
|
self.reload()
|
||||||
# Quit PKC?
|
# Quit PKC?
|
||||||
self.stop_pkc = False
|
self.stop_pkc = False
|
||||||
# This will suspend the main thread also
|
# This will suspend the main thread also
|
||||||
|
@ -134,7 +134,7 @@ class App(object):
|
||||||
thread.suspend(block=True)
|
thread.suspend(block=True)
|
||||||
else:
|
else:
|
||||||
break
|
break
|
||||||
return xbmc.abortRequested
|
return xbmc.Monitor().abortRequested()
|
||||||
|
|
||||||
def resume_threads(self):
|
def resume_threads(self):
|
||||||
"""
|
"""
|
||||||
|
@ -144,7 +144,7 @@ class App(object):
|
||||||
LOG.debug('Resuming threads: %s', self.threads)
|
LOG.debug('Resuming threads: %s', self.threads)
|
||||||
for thread in self.threads:
|
for thread in self.threads:
|
||||||
thread.resume()
|
thread.resume()
|
||||||
return xbmc.abortRequested
|
return xbmc.Monitor().abortRequested()
|
||||||
|
|
||||||
def stop_threads(self, block=True):
|
def stop_threads(self, block=True):
|
||||||
"""
|
"""
|
||||||
|
@ -160,7 +160,7 @@ class App(object):
|
||||||
if xbmc.sleep(100):
|
if xbmc.sleep(100):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def load(self):
|
def reload(self):
|
||||||
# Number of items to fetch and display in widgets
|
# Number of items to fetch and display in widgets
|
||||||
self.fetch_pms_item_number = int(utils.settings('fetch_pms_item_number'))
|
self.fetch_pms_item_number = int(utils.settings('fetch_pms_item_number'))
|
||||||
# Hack to force Kodi widget for "in progress" to show up if it was empty
|
# Hack to force Kodi widget for "in progress" to show up if it was empty
|
||||||
|
|
|
@ -80,6 +80,7 @@ class Sync(object):
|
||||||
# List of section_ids we're synching to Kodi - will be automatically
|
# List of section_ids we're synching to Kodi - will be automatically
|
||||||
# re-built if sections are set a-new
|
# re-built if sections are set a-new
|
||||||
self.section_ids = set()
|
self.section_ids = set()
|
||||||
|
self.enable_alexa = None
|
||||||
|
|
||||||
self.load()
|
self.load()
|
||||||
|
|
||||||
|
@ -99,7 +100,6 @@ class Sync(object):
|
||||||
self.artwork = utils.settings('usePlexArtwork') == 'true'
|
self.artwork = utils.settings('usePlexArtwork') == 'true'
|
||||||
self.replace_smb_path = utils.settings('replaceSMB') == 'true'
|
self.replace_smb_path = utils.settings('replaceSMB') == 'true'
|
||||||
self.remap_path = utils.settings('remapSMB') == 'true'
|
self.remap_path = utils.settings('remapSMB') == 'true'
|
||||||
self.force_transcode_pix = utils.settings('force_transcode_pix') == 'true'
|
|
||||||
self.remapSMBmovieOrg = remove_trailing_slash(utils.settings('remapSMBmovieOrg'))
|
self.remapSMBmovieOrg = remove_trailing_slash(utils.settings('remapSMBmovieOrg'))
|
||||||
self.remapSMBmovieNew = remove_trailing_slash(utils.settings('remapSMBmovieNew'))
|
self.remapSMBmovieNew = remove_trailing_slash(utils.settings('remapSMBmovieNew'))
|
||||||
self.remapSMBtvOrg = remove_trailing_slash(utils.settings('remapSMBtvOrg'))
|
self.remapSMBtvOrg = remove_trailing_slash(utils.settings('remapSMBtvOrg'))
|
||||||
|
@ -110,14 +110,24 @@ class Sync(object):
|
||||||
self.remapSMBphotoNew = remove_trailing_slash(utils.settings('remapSMBphotoNew'))
|
self.remapSMBphotoNew = remove_trailing_slash(utils.settings('remapSMBphotoNew'))
|
||||||
self.escape_path = utils.settings('escapePath') == 'true'
|
self.escape_path = utils.settings('escapePath') == 'true'
|
||||||
self.indicate_media_versions = utils.settings('indicate_media_versions') == "true"
|
self.indicate_media_versions = utils.settings('indicate_media_versions') == "true"
|
||||||
self.show_extras_instead_of_playing_trailer = utils.settings('showExtrasInsteadOfTrailer') == 'true'
|
|
||||||
self.sync_specific_plex_playlists = utils.settings('syncSpecificPlexPlaylists') == 'true'
|
self.sync_specific_plex_playlists = utils.settings('syncSpecificPlexPlaylists') == 'true'
|
||||||
self.sync_specific_kodi_playlists = utils.settings('syncSpecificKodiPlaylists') == 'true'
|
self.sync_specific_kodi_playlists = utils.settings('syncSpecificKodiPlaylists') == 'true'
|
||||||
self.sync_dialog = utils.settings('dbSyncIndicator') == 'true'
|
|
||||||
|
|
||||||
self.full_sync_intervall = int(utils.settings('fullSyncInterval')) * 60
|
|
||||||
self.background_sync_disabled = utils.settings('enableBackgroundSync') == 'false'
|
|
||||||
self.backgroundsync_saftymargin = int(utils.settings('backgroundsync_saftyMargin'))
|
|
||||||
self.sync_thread_number = int(utils.settings('syncThreadNumber'))
|
self.sync_thread_number = int(utils.settings('syncThreadNumber'))
|
||||||
|
self.reload()
|
||||||
|
|
||||||
|
def reload(self):
|
||||||
|
"""
|
||||||
|
Any settings unrelated to syncs to the Kodi database - can thus be
|
||||||
|
safely reset without a Kodi reboot
|
||||||
|
"""
|
||||||
|
self.background_sync_disabled = utils.settings('enableBackgroundSync') == 'false'
|
||||||
|
self.enable_alexa = utils.settings('enable_alexa') == 'true'
|
||||||
|
self.sync_dialog = utils.settings('dbSyncIndicator') == 'true'
|
||||||
|
self.full_sync_intervall = int(utils.settings('fullSyncInterval')) * 60
|
||||||
|
self.backgroundsync_saftymargin = int(utils.settings('backgroundsync_saftyMargin'))
|
||||||
|
|
||||||
self.image_sync_notifications = utils.settings('imageSyncNotifications') == 'true'
|
self.image_sync_notifications = utils.settings('imageSyncNotifications') == 'true'
|
||||||
|
|
||||||
|
self.force_transcode_pix = utils.settings('force_transcode_pix') == 'true'
|
||||||
|
# Trailers in Kodi DB will remain UNTIL DB is reset!
|
||||||
|
self.show_extras_instead_of_playing_trailer = utils.settings('showExtrasInsteadOfTrailer') == 'true'
|
||||||
|
|
|
@ -305,7 +305,7 @@ class Task(object):
|
||||||
self._canceled = True
|
self._canceled = True
|
||||||
|
|
||||||
def should_cancel(self):
|
def should_cancel(self):
|
||||||
return self._canceled or xbmc.abortRequested
|
return self._canceled or xbmc.Monitor().abortRequested()
|
||||||
|
|
||||||
def isValid(self):
|
def isValid(self):
|
||||||
return not self.finished and not self._canceled
|
return not self.finished and not self._canceled
|
||||||
|
@ -370,7 +370,7 @@ class BackgroundWorker(object):
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def aborted(self):
|
def aborted(self):
|
||||||
return self._abort or xbmc.abortRequested
|
return self._abort or xbmc.Monitor().abortRequested()
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
if self._thread and self._thread.isAlive():
|
if self._thread and self._thread.isAlive():
|
||||||
|
@ -452,7 +452,7 @@ class BackgroundThreader:
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def aborted(self):
|
def aborted(self):
|
||||||
return self._abort or xbmc.abortRequested
|
return self._abort or xbmc.Monitor().abortRequested()
|
||||||
|
|
||||||
def shutdown(self, block=True):
|
def shutdown(self, block=True):
|
||||||
self.abort()
|
self.abort()
|
||||||
|
|
|
@ -66,8 +66,7 @@ def _wait_for_auth():
|
||||||
xbmcplugin.endOfDirectory(int(argv[1]), False) if failed
|
xbmcplugin.endOfDirectory(int(argv[1]), False) if failed
|
||||||
|
|
||||||
WARNING - this will potentially stall the shutdown of Kodi since we cannot
|
WARNING - this will potentially stall the shutdown of Kodi since we cannot
|
||||||
poll xbmc.Monitor().abortRequested() or waitForAbort() or
|
poll xbmc.Monitor().abortRequested() or waitForAbort()
|
||||||
xbmc.abortRequested
|
|
||||||
"""
|
"""
|
||||||
counter = 0
|
counter = 0
|
||||||
startupdelay = int(utils.settings('startupDelay') or 0)
|
startupdelay = int(utils.settings('startupDelay') or 0)
|
||||||
|
|
|
@ -102,7 +102,7 @@ class Service(object):
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def should_cancel():
|
def should_cancel():
|
||||||
return xbmc.abortRequested or app.APP.stop_pkc
|
return xbmc.Monitor().abortRequested() or app.APP.stop_pkc
|
||||||
|
|
||||||
def on_connection_check(self, result):
|
def on_connection_check(self, result):
|
||||||
"""
|
"""
|
||||||
|
@ -248,6 +248,7 @@ class Service(object):
|
||||||
icon='{plex}',
|
icon='{plex}',
|
||||||
time=2000,
|
time=2000,
|
||||||
sound=False)
|
sound=False)
|
||||||
|
app.reload()
|
||||||
app.APP.resume_threads()
|
app.APP.resume_threads()
|
||||||
self.auth_running = False
|
self.auth_running = False
|
||||||
|
|
||||||
|
@ -535,7 +536,6 @@ class Service(object):
|
||||||
self.sync.start()
|
self.sync.start()
|
||||||
self.plexcompanion.start()
|
self.plexcompanion.start()
|
||||||
self.playqueue.start()
|
self.playqueue.start()
|
||||||
if utils.settings('enable_alexa') == 'true':
|
|
||||||
self.alexa.start()
|
self.alexa.start()
|
||||||
|
|
||||||
xbmc.sleep(100)
|
xbmc.sleep(100)
|
||||||
|
|
|
@ -22,6 +22,11 @@ class WebSocket(backgroundthread.KillableThread):
|
||||||
self.sleeptime = 0.0
|
self.sleeptime = 0.0
|
||||||
super(WebSocket, self).__init__()
|
super(WebSocket, self).__init__()
|
||||||
|
|
||||||
|
def close_websocket(self):
|
||||||
|
if self.ws is not None:
|
||||||
|
self.ws.close()
|
||||||
|
self.ws = None
|
||||||
|
|
||||||
def process(self, opcode, message):
|
def process(self, opcode, message):
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
@ -62,9 +67,7 @@ class WebSocket(backgroundthread.KillableThread):
|
||||||
try:
|
try:
|
||||||
self._run()
|
self._run()
|
||||||
finally:
|
finally:
|
||||||
# Close websocket connection on shutdown
|
self.close_websocket()
|
||||||
if self.ws is not None:
|
|
||||||
self.ws.close()
|
|
||||||
app.APP.deregister_thread(self)
|
app.APP.deregister_thread(self)
|
||||||
LOG.info("##===---- %s Stopped ----===##", self.__class__.__name__)
|
LOG.info("##===---- %s Stopped ----===##", self.__class__.__name__)
|
||||||
|
|
||||||
|
@ -73,9 +76,7 @@ class WebSocket(backgroundthread.KillableThread):
|
||||||
# In the event the server goes offline
|
# In the event the server goes offline
|
||||||
if self.should_suspend():
|
if self.should_suspend():
|
||||||
# Set in service.py
|
# Set in service.py
|
||||||
if self.ws is not None:
|
self.close_websocket()
|
||||||
self.ws.close()
|
|
||||||
self.ws = None
|
|
||||||
if self.wait_while_suspended():
|
if self.wait_while_suspended():
|
||||||
# Abort was requested while waiting. We should exit
|
# Abort was requested while waiting. We should exit
|
||||||
return
|
return
|
||||||
|
@ -132,9 +133,7 @@ class WebSocket(backgroundthread.KillableThread):
|
||||||
import traceback
|
import traceback
|
||||||
LOG.error("%s: Traceback:\n%s",
|
LOG.error("%s: Traceback:\n%s",
|
||||||
self.__class__.__name__, traceback.format_exc())
|
self.__class__.__name__, traceback.format_exc())
|
||||||
if self.ws is not None:
|
self.close_websocket()
|
||||||
self.ws.close()
|
|
||||||
self.ws = None
|
|
||||||
|
|
||||||
|
|
||||||
class PMS_Websocket(WebSocket):
|
class PMS_Websocket(WebSocket):
|
||||||
|
@ -143,9 +142,13 @@ class PMS_Websocket(WebSocket):
|
||||||
"""
|
"""
|
||||||
def should_suspend(self):
|
def should_suspend(self):
|
||||||
"""
|
"""
|
||||||
Returns True if the thread is suspended
|
Returns True if the thread is suspended.
|
||||||
"""
|
"""
|
||||||
return self._suspended or app.SYNC.background_sync_disabled
|
suspend = self._suspended or app.SYNC.background_sync_disabled
|
||||||
|
if suspend:
|
||||||
|
# This thread needs to clear the Event() _is_not_suspended itself!
|
||||||
|
self.suspend()
|
||||||
|
return suspend
|
||||||
|
|
||||||
def getUri(self):
|
def getUri(self):
|
||||||
if self.redirect_uri:
|
if self.redirect_uri:
|
||||||
|
@ -159,9 +162,8 @@ class PMS_Websocket(WebSocket):
|
||||||
else:
|
else:
|
||||||
server = "ws%s" % server[4:]
|
server = "ws%s" % server[4:]
|
||||||
uri = "%s/:/websockets/notifications" % server
|
uri = "%s/:/websockets/notifications" % server
|
||||||
# Need to use plex.tv token, if any. NOT user token
|
if app.ACCOUNT.pms_token:
|
||||||
if app.ACCOUNT.plex_token:
|
uri += '?X-Plex-Token=%s' % app.ACCOUNT.pms_token
|
||||||
uri += '?X-Plex-Token=%s' % app.ACCOUNT.plex_token
|
|
||||||
sslopt = {}
|
sslopt = {}
|
||||||
if v.KODIVERSION == 17 and utils.settings('sslverify') == "false":
|
if v.KODIVERSION == 17 and utils.settings('sslverify') == "false":
|
||||||
sslopt["cert_reqs"] = CERT_NONE
|
sslopt["cert_reqs"] = CERT_NONE
|
||||||
|
@ -210,9 +212,14 @@ class Alexa_Websocket(WebSocket):
|
||||||
"""
|
"""
|
||||||
Overwrite method since we need to check for plex token
|
Overwrite method since we need to check for plex token
|
||||||
"""
|
"""
|
||||||
return (self._suspended or
|
suspend = self._suspended or \
|
||||||
not app.ACCOUNT.plex_token or
|
not app.SYNC.enable_alexa or \
|
||||||
app.ACCOUNT.restricted_user)
|
app.ACCOUNT.restricted_user or \
|
||||||
|
not app.ACCOUNT.plex_token
|
||||||
|
if suspend:
|
||||||
|
# This thread needs to clear the Event() _is_not_suspended itself!
|
||||||
|
self.suspend()
|
||||||
|
return suspend
|
||||||
|
|
||||||
def getUri(self):
|
def getUri(self):
|
||||||
if self.redirect_uri:
|
if self.redirect_uri:
|
||||||
|
|
|
@ -737,7 +737,7 @@ class MultiWindow(object):
|
||||||
return mw
|
return mw
|
||||||
|
|
||||||
def _open(self):
|
def _open(self):
|
||||||
while not xbmc.abortRequested and not self._allClosed:
|
while not xbmc.Monitor().abortRequested() and not self._allClosed:
|
||||||
self._setupCurrent(self._next)
|
self._setupCurrent(self._next)
|
||||||
self._current.modal()
|
self._current.modal()
|
||||||
|
|
||||||
|
@ -922,9 +922,9 @@ class PropertyTimer():
|
||||||
self._callback()
|
self._callback()
|
||||||
|
|
||||||
def _wait(self):
|
def _wait(self):
|
||||||
while not xbmc.abortRequested and time.time() < self._endTime:
|
while not xbmc.Monitor().abortRequested() and time.time() < self._endTime:
|
||||||
app.APP.monitor.waitForAbort(0.1)
|
app.APP.monitor.waitForAbort(0.1)
|
||||||
if xbmc.abortRequested:
|
if xbmc.Monitor().abortRequested():
|
||||||
return
|
return
|
||||||
if self._endTime == 0:
|
if self._endTime == 0:
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in a new issue