From 93e3d42e23d6026422316026cf05bf4448a9ec55 Mon Sep 17 00:00:00 2001 From: croneter Date: Sun, 11 Mar 2018 18:54:05 +0100 Subject: [PATCH] Fix playstates not being copied/reset correctly --- resources/lib/kodimonitor.py | 5 +++-- resources/lib/player.py | 5 +++-- resources/lib/state.py | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/resources/lib/kodimonitor.py b/resources/lib/kodimonitor.py index 5a55a390..59973de8 100644 --- a/resources/lib/kodimonitor.py +++ b/resources/lib/kodimonitor.py @@ -4,6 +4,7 @@ PKC Kodi Monitoring implementation from logging import getLogger from json import loads from threading import Thread +import copy from xbmc import Monitor, Player, sleep, getCondVisibility, getInfoLabel, \ getLocalizedString @@ -60,8 +61,8 @@ class KodiMonitor(Monitor): self.xbmcplayer = Player() Monitor.__init__(self) for playerid in state.PLAYER_STATES: - state.PLAYER_STATES[playerid] = dict(state.PLAYSTATE) - state.OLD_PLAYER_STATES[playerid] = dict(state.PLAYSTATE) + state.PLAYER_STATES[playerid] = copy.deepcopy(state.PLAYSTATE) + state.OLD_PLAYER_STATES[playerid] = copy.deepcopy(state.PLAYSTATE) LOG.info("Kodi monitor started.") def onScanStarted(self, library): diff --git a/resources/lib/player.py b/resources/lib/player.py index 74c38411..17fa75e1 100644 --- a/resources/lib/player.py +++ b/resources/lib/player.py @@ -2,6 +2,7 @@ ############################################################################### from logging import getLogger +import copy from xbmc import Player @@ -23,9 +24,9 @@ def playback_cleanup(): """ PKC cleanup after playback ends/is stopped """ + LOG.debug('playback_cleanup called') # We might have saved a transient token from a user flinging media via # Companion (if we could not use the playqueue to store the token) - LOG.debug('playback_cleanup called') state.PLEX_TRANSIENT_TOKEN = None for playerid in state.ACTIVE_PLAYERS: status = state.PLAYER_STATES[playerid] @@ -38,7 +39,7 @@ def playback_cleanup(): '{server}/video/:/transcode/universal/stop', parameters={'session': v.PKC_MACHINE_IDENTIFIER}) # Reset the player's status - status = dict(state.PLAYSTATE) + status = copy.deepcopy(state.PLAYSTATE) # As all playback has halted, reset the players that have been active state.ACTIVE_PLAYERS = [] LOG.debug('Finished PKC playback cleanup') diff --git a/resources/lib/state.py b/resources/lib/state.py index 4fbdc907..3633267d 100644 --- a/resources/lib/state.py +++ b/resources/lib/state.py @@ -108,7 +108,7 @@ OLD_PLAYER_STATES = { 1: {}, 2: {} } -# "empty" dict for the PLAYER_STATES above +# "empty" dict for the PLAYER_STATES above. Use copy.deepcopy to duplicate! PLAYSTATE = { 'type': None, 'time': {