From 62e973dbe28997ce1c98e3046414f91aba5333ca Mon Sep 17 00:00:00 2001 From: croneter Date: Tue, 6 Mar 2018 18:23:56 +0100 Subject: [PATCH] Fixes to add-on paths playback startup --- resources/lib/kodimonitor.py | 21 ++++++++++++--------- resources/lib/player.py | 4 ---- resources/lib/playlist_func.py | 15 +++++++++++++++ 3 files changed, 27 insertions(+), 13 deletions(-) diff --git a/resources/lib/kodimonitor.py b/resources/lib/kodimonitor.py index 7cf72e64..289dbe22 100644 --- a/resources/lib/kodimonitor.py +++ b/resources/lib/kodimonitor.py @@ -209,17 +209,15 @@ class KodiMonitor(Monitor): } Will NOT be called if playback initiated by Kodi widgets """ - kodi_item = js.get_item(data['playlistid']) - if (state.RESUMABLE is True and not kodi_item['file'] and - data['position'] == 0 and - data['item'].get('title') is not None and - getCondVisibility('Window.IsVisible(MyVideoNav.xml)')): + old = state.OLD_PLAYER_STATES[data['playlistid']] + if (not state.DIRECT_PATHS and data['position'] == 0 and + not PQ.PLAYQUEUES[data['playlistid']].items and + data['item']['type'] == old['kodi_type'] and + data['item']['id'] == old['kodi_id']): # Hack we need for RESUMABLE items because Kodi lost the path of the # last played item that is now being replayed (see playback.py's - # Player().play()) - # Also see playqueue.py _compare_playqueues() + # Player().play()) Also see playqueue.py _compare_playqueues() LOG.info('Detected re-start of playback of last item') - old = state.OLD_PLAYER_STATES[data['playlistid']] kwargs = { 'plex_id': old['plex_id'], 'plex_type': old['plex_type'], @@ -240,6 +238,7 @@ class KodiMonitor(Monitor): """ pass + @LOCKER.lockthis def _playlist_onclear(self, data): """ Called if a Kodi playlist is cleared. Example data dict: @@ -247,7 +246,11 @@ class KodiMonitor(Monitor): u'playlistid': 1, } """ - pass + playqueue = PQ.PLAYQUEUES[data['playlistid']] + if not playqueue.is_pkc_clear(): + playqueue.clear(kodi=False) + else: + LOG.debug('Detected PKC clear - ignoring') def _get_ids(self, json_item): """ diff --git a/resources/lib/player.py b/resources/lib/player.py index 64710f66..74c38411 100644 --- a/resources/lib/player.py +++ b/resources/lib/player.py @@ -37,10 +37,6 @@ def playback_cleanup(): DU().downloadUrl( '{server}/video/:/transcode/universal/stop', parameters={'session': v.PKC_MACHINE_IDENTIFIER}) - # Kodi will not clear the playqueue (because there is not really any) - # if there is only 1 item in it - if len(PQ.PLAYQUEUES[playerid].items) == 1: - PQ.PLAYQUEUES[playerid].clear() # Reset the player's status status = dict(state.PLAYSTATE) # As all playback has halted, reset the players that have been active diff --git a/resources/lib/playlist_func.py b/resources/lib/playlist_func.py index ac73cbd9..17cbd5ae 100644 --- a/resources/lib/playlist_func.py +++ b/resources/lib/playlist_func.py @@ -48,6 +48,8 @@ class PlaylistObjectBaseclase(object): self.plex_transient_token = None # Need a hack for detecting swaps of elements self.old_kodi_pl = [] + # Workaround to avoid endless loops of detecting PL clears + self._clear_list = [] def __repr__(self): """ @@ -67,6 +69,18 @@ class PlaylistObjectBaseclase(object): answ += '\'%s\': %s, ' % (key, str(getattr(self, key))) return answ + '\'items\': %s}}' % self.items + def is_pkc_clear(self): + """ + Returns True if PKC has cleared the Kodi playqueue just recently. + Then this clear will be ignored from now on + """ + try: + self._clear_list.pop() + except IndexError: + return False + else: + return True + def clear(self, kodi=True): """ Resets the playlist object to an empty playlist. @@ -76,6 +90,7 @@ class PlaylistObjectBaseclase(object): # kodi monitor's on_clear method will only be called if there were some # items to begin with if kodi and self.kodi_pl.size() != 0: + self._clear_list.append(None) self.kodi_pl.clear() # Clear Kodi playlist object self.items = [] self.id = None