Make sure that LOCK is released after adding one element
- Partially fixes #446
This commit is contained in:
parent
dcf2b9b4e4
commit
c05b772e90
1 changed files with 36 additions and 34 deletions
|
@ -179,39 +179,42 @@ class PlayqueueMonitor(Thread):
|
|||
elif identical:
|
||||
LOG.debug('Detected playqueue item %s moved to position %s',
|
||||
i + j, i)
|
||||
PL.move_playlist_item(playqueue, i + j, i)
|
||||
with LOCK:
|
||||
PL.move_playlist_item(playqueue, i + j, i)
|
||||
del old[j], index[j]
|
||||
break
|
||||
else:
|
||||
LOG.debug('Detected new Kodi element at position %s: %s ',
|
||||
i, new_item)
|
||||
try:
|
||||
if playqueue.id is None:
|
||||
PL.init_Plex_playlist(playqueue, kodi_item=new_item)
|
||||
with LOCK:
|
||||
try:
|
||||
if playqueue.id is None:
|
||||
PL.init_Plex_playlist(playqueue, kodi_item=new_item)
|
||||
else:
|
||||
PL.add_item_to_PMS_playlist(playqueue,
|
||||
i,
|
||||
kodi_item=new_item)
|
||||
except PL.PlaylistError:
|
||||
# Could not add the element
|
||||
pass
|
||||
except IndexError:
|
||||
# This is really a hack - happens when using Addon Paths
|
||||
# and repeatedly starting the same element. Kodi will
|
||||
# then not pass kodi id nor file path AND will also not
|
||||
# start-up playback. Hence kodimonitor kicks off
|
||||
# playback. Also see kodimonitor.py - _playlist_onadd()
|
||||
pass
|
||||
else:
|
||||
PL.add_item_to_PMS_playlist(playqueue,
|
||||
i,
|
||||
kodi_item=new_item)
|
||||
except PL.PlaylistError:
|
||||
# Could not add the element
|
||||
pass
|
||||
except IndexError:
|
||||
# This is really a hack - happens when using Addon Paths
|
||||
# and repeatedly starting the same element. Kodi will then
|
||||
# not pass kodi id nor file path AND will also not
|
||||
# start-up playback. Hence kodimonitor kicks off playback.
|
||||
# Also see kodimonitor.py - _playlist_onadd()
|
||||
pass
|
||||
else:
|
||||
for j in range(i, len(index)):
|
||||
index[j] += 1
|
||||
for j in range(i, len(index)):
|
||||
index[j] += 1
|
||||
for i in reversed(index):
|
||||
if self.stopped():
|
||||
# Chances are that we got an empty Kodi playlist due to
|
||||
# Kodi exit
|
||||
return
|
||||
LOG.debug('Detected deletion of playqueue element at pos %s', i)
|
||||
PL.delete_playlist_item_from_PMS(playqueue, i)
|
||||
with LOCK:
|
||||
PL.delete_playlist_item_from_PMS(playqueue, i)
|
||||
LOG.debug('Done comparing playqueues')
|
||||
|
||||
def run(self):
|
||||
|
@ -223,18 +226,17 @@ class PlayqueueMonitor(Thread):
|
|||
if stopped():
|
||||
break
|
||||
sleep(1000)
|
||||
with LOCK:
|
||||
for playqueue in PLAYQUEUES:
|
||||
kodi_pl = js.playlist_get_items(playqueue.playlistid)
|
||||
if playqueue.old_kodi_pl != kodi_pl:
|
||||
if playqueue.id is None and (not state.DIRECT_PATHS or
|
||||
state.CONTEXT_MENU_PLAY):
|
||||
# Only initialize if directly fired up using direct
|
||||
# paths. Otherwise let default.py do its magic
|
||||
LOG.debug('Not yet initiating playback')
|
||||
else:
|
||||
# compare old and new playqueue
|
||||
self._compare_playqueues(playqueue, kodi_pl)
|
||||
playqueue.old_kodi_pl = list(kodi_pl)
|
||||
for playqueue in PLAYQUEUES:
|
||||
kodi_pl = js.playlist_get_items(playqueue.playlistid)
|
||||
if playqueue.old_kodi_pl != kodi_pl:
|
||||
if playqueue.id is None and (not state.DIRECT_PATHS or
|
||||
state.CONTEXT_MENU_PLAY):
|
||||
# Only initialize if directly fired up using direct
|
||||
# paths. Otherwise let default.py do its magic
|
||||
LOG.debug('Not yet initiating playback')
|
||||
else:
|
||||
# compare old and new playqueue
|
||||
self._compare_playqueues(playqueue, kodi_pl)
|
||||
playqueue.old_kodi_pl = list(kodi_pl)
|
||||
sleep(200)
|
||||
LOG.info("----===## PlayqueueMonitor stopped ##===----")
|
||||
|
|
Loading…
Reference in a new issue