From cf15799df22f1b70d2b8774f4157352f30783726 Mon Sep 17 00:00:00 2001 From: tomkat83 Date: Sat, 30 Dec 2017 12:57:23 +0100 Subject: [PATCH] Clear and remove-items from Kodi playqueues once --- resources/lib/kodimonitor.py | 10 +++++++- resources/lib/playlist_func.py | 46 +++++++++++++++++++++++++++++++++- 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/resources/lib/kodimonitor.py b/resources/lib/kodimonitor.py index 1f7f5619..c796f74a 100644 --- a/resources/lib/kodimonitor.py +++ b/resources/lib/kodimonitor.py @@ -229,6 +229,10 @@ class KodiMonitor(Monitor): } """ playqueue = self.playqueue.playqueues[data['playlistid']] + # Did PKC cause this add? Then lets not do anything + if playqueue.is_kodi_onremove() is False: + LOG.debug('PKC removed this item already from playqueue - ignoring') + return # Check whether we even need to update our known playqueue kodi_playqueue = js.playlist_get_items(data['playlistid']) if playqueue.old_kodi_pl == kodi_playqueue: @@ -245,7 +249,11 @@ class KodiMonitor(Monitor): u'playlistid': 1, } """ - self.playqueue.playqueues[data['playlistid']].clear() + playqueue = self.playqueue.playqueues[data['playlistid']] + if playqueue.is_kodi_onclear() is False: + LOG.debug('PKC already cleared the playqueue - ignoring') + return + playqueue.clear() @LOCKER.lockthis def PlayBackStart(self, data): diff --git a/resources/lib/playlist_func.py b/resources/lib/playlist_func.py index e5bab020..919a3f5e 100644 --- a/resources/lib/playlist_func.py +++ b/resources/lib/playlist_func.py @@ -45,6 +45,8 @@ class PlaylistObjectBaseclase(object): # Needed to not add an item twice (first through PKC, then the kodi # monitor) self._onadd_queue = [] + self._onremove_queue = [] + self._onclear_queue = [] def __repr__(self): """ @@ -83,11 +85,53 @@ class PlaylistObjectBaseclase(object): return True return False + def kodi_onremove(self): + """ + Call this before removing an item from the Kodi playqueue + """ + self._onremove_queue.append(None) + + def is_kodi_onremove(self): + """ + Returns False if the last kodimonitor on_remove was caused by PKC - so + that we are not adding a playlist item twice. + + Calling this function will remove the item from our "checklist" + """ + try: + self._onremove_queue.pop() + except IndexError: + return True + return False + + def kodi_onclear(self): + """ + Call this before clearing the Kodi playqueue IF it was not empty + """ + self._onclear_queue.append(None) + + def is_kodi_onclear(self): + """ + Returns False if the last kodimonitor on_remove was caused by PKC - so + that we are not clearing the playlist twice. + + Calling this function will remove the item from our "checklist" + """ + try: + self._onclear_queue.pop() + except IndexError: + return True + return False + def clear(self): """ Resets the playlist object to an empty playlist """ - self.kodi_pl.clear() # Clear Kodi playlist object + # kodi monitor's on_clear method will only be called if there were some + # items to begin with + if self.kodi_pl.size() != 0: + self.kodi_onclear() + self.kodi_pl.clear() # Clear Kodi playlist object self.items = [] self.old_kodi_pl = [] self.id = None