Merge pull request #777 from croneter/fix-profile-switch
Fix PKC synching playstate to wrong user on profile switch. Be aware that Kodi profile switches are error-prone
This commit is contained in:
commit
a8a229967c
3 changed files with 44 additions and 22 deletions
|
@ -258,6 +258,7 @@ class FullSync(common.fullsync_mixin):
|
|||
for section in (x for x in sections.SECTIONS
|
||||
if x.section_type == kind[1]):
|
||||
if self.isCanceled():
|
||||
LOG.debug('Need to exit now')
|
||||
return
|
||||
if not section.sync_to_kodi:
|
||||
LOG.info('User chose to not sync section %s', section)
|
||||
|
@ -283,6 +284,8 @@ class FullSync(common.fullsync_mixin):
|
|||
self.section_success = False
|
||||
else:
|
||||
queue.put(element)
|
||||
except Exception:
|
||||
utils.ERROR(notify=True)
|
||||
finally:
|
||||
queue.put(None)
|
||||
|
||||
|
@ -410,7 +413,7 @@ class FullSync(common.fullsync_mixin):
|
|||
def _run(self):
|
||||
self.current_sync = timing.plex_now()
|
||||
# Get latest Plex libraries and build playlist and video node files
|
||||
if not sections.sync_from_pms(self):
|
||||
if self.isCanceled() or not sections.sync_from_pms(self):
|
||||
return
|
||||
self.successful = True
|
||||
try:
|
||||
|
@ -422,10 +425,7 @@ class FullSync(common.fullsync_mixin):
|
|||
# Actual syncing - do only new items first
|
||||
LOG.info('Running full_library_sync with repair=%s',
|
||||
self.repair)
|
||||
if not self.full_library_sync():
|
||||
self.successful = False
|
||||
return
|
||||
if self.isCanceled():
|
||||
if self.isCanceled() or not self.full_library_sync():
|
||||
self.successful = False
|
||||
return
|
||||
if common.PLAYLIST_SYNC_ENABLED and not playlists.full_sync():
|
||||
|
@ -437,6 +437,7 @@ class FullSync(common.fullsync_mixin):
|
|||
self.dialog.close()
|
||||
if self.threader:
|
||||
self.threader.shutdown()
|
||||
self.threader = None
|
||||
if not self.successful and not self.isCanceled():
|
||||
# "ERROR in library sync"
|
||||
utils.dialog('notification',
|
||||
|
|
|
@ -289,7 +289,9 @@ class SubscriptionMgr(object):
|
|||
# To avoid RuntimeError, don't use self.lastplayers
|
||||
for playerid in (0, 1, 2):
|
||||
self.last_params['state'] = 'stopped'
|
||||
self._send_pms_notification(playerid, self.last_params)
|
||||
self._send_pms_notification(playerid,
|
||||
self.last_params,
|
||||
timeout=0.0001)
|
||||
|
||||
def _plex_stream_index(self, playerid, stream_type):
|
||||
"""
|
||||
|
@ -399,7 +401,11 @@ class SubscriptionMgr(object):
|
|||
self.last_params = params
|
||||
return params
|
||||
|
||||
def _send_pms_notification(self, playerid, params):
|
||||
def _send_pms_notification(self, playerid, params, timeout=None):
|
||||
"""
|
||||
Pass a really low timeout in seconds if shutting down Kodi and we don't
|
||||
need the PMS' response
|
||||
"""
|
||||
serv = self._server_by_host(self.server)
|
||||
playqueue = PQ.PLAYQUEUES[playerid]
|
||||
xargs = params_pms()
|
||||
|
@ -416,7 +422,8 @@ class SubscriptionMgr(object):
|
|||
DU().downloadUrl(url,
|
||||
authenticate=False,
|
||||
parameters=xargs,
|
||||
headerOverride=HEADERS_PMS)
|
||||
headerOverride=HEADERS_PMS,
|
||||
timeout=timeout)
|
||||
LOG.debug("Sent server notification with parameters: %s to %s",
|
||||
xargs, url)
|
||||
|
||||
|
|
|
@ -451,12 +451,15 @@ class Service(object):
|
|||
self.choose_plex_libraries()
|
||||
elif plex_command == 'RESET-PKC':
|
||||
utils.reset()
|
||||
elif plex_command == 'EXIT-PKC':
|
||||
LOG.info('Received command from another instance to quit')
|
||||
app.APP.stop_pkc = True
|
||||
if task:
|
||||
backgroundthread.BGThreader.addTasksToFront([task])
|
||||
continue
|
||||
|
||||
if app.APP.suspend:
|
||||
app.APP.monitor.waitForAbort(0.1)
|
||||
xbmc.sleep(100)
|
||||
continue
|
||||
|
||||
# Before proceeding, need to make sure:
|
||||
|
@ -495,7 +498,7 @@ class Service(object):
|
|||
if utils.settings('enable_alexa') == 'true':
|
||||
self.alexa.start()
|
||||
|
||||
app.APP.monitor.waitForAbort(0.1)
|
||||
xbmc.sleep(100)
|
||||
|
||||
# EXITING PKC
|
||||
# Tell all threads to terminate (e.g. several lib sync threads)
|
||||
|
@ -506,26 +509,37 @@ class Service(object):
|
|||
library_sync.clear_window_vars()
|
||||
# Will block until threads have quit
|
||||
app.APP.stop_threads()
|
||||
utils.window('plex_service_started', clear=True)
|
||||
LOG.info("======== STOP %s ========", v.ADDON_NAME)
|
||||
|
||||
|
||||
def start():
|
||||
# Safety net - Kody starts PKC twice upon first installation!
|
||||
if utils.window('plex_service_started') == 'true':
|
||||
EXIT = True
|
||||
else:
|
||||
LOG.info('Another service.py instance is already running - shutting '
|
||||
'it down now')
|
||||
# Telling the other Python instance of PKC to shut down now
|
||||
i = 0
|
||||
while utils.window('plexkodiconnect.command'):
|
||||
xbmc.sleep(20)
|
||||
i += 1
|
||||
if i > 300:
|
||||
LOG.error('Could not tell other PKC instance to shut down')
|
||||
return
|
||||
utils.window('plexkodiconnect.command', value='EXIT-PKC')
|
||||
# Telling successful - now wait for actual shut-down
|
||||
i = 0
|
||||
while utils.window('plex_service_started'):
|
||||
xbmc.sleep(20)
|
||||
i += 1
|
||||
if i > 300:
|
||||
LOG.error('Could not shut down other PKC instance')
|
||||
return
|
||||
utils.window('plex_service_started', value='true')
|
||||
EXIT = False
|
||||
|
||||
# Delay option
|
||||
DELAY = int(utils.settings('startupDelay'))
|
||||
|
||||
LOG.info("Delaying Plex startup by: %s sec...", DELAY)
|
||||
if EXIT:
|
||||
LOG.error('PKC service.py already started - exiting this instance')
|
||||
elif DELAY and xbmc.Monitor().waitForAbort(DELAY):
|
||||
if DELAY and xbmc.Monitor().waitForAbort(DELAY):
|
||||
# Start the service
|
||||
LOG.info("Abort requested while waiting. PKC not started.")
|
||||
else:
|
||||
Service().ServiceEntryPoint()
|
||||
utils.window('plex_service_started', clear=True)
|
||||
LOG.info("======== STOP PlexKodiConnect service ========")
|
||||
|
|
Loading…
Reference in a new issue