Clear and remove-items from Kodi playqueues once

This commit is contained in:
tomkat83 2017-12-30 12:57:23 +01:00
parent ba0f22ac1e
commit cf15799df2
2 changed files with 54 additions and 2 deletions

View file

@ -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):

View file

@ -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,10 +85,52 @@ 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
"""
# 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 = []