Extend websocket listening to Plex playlist changes
This commit is contained in:
parent
0baa081dc6
commit
2971dd3f7c
3 changed files with 33 additions and 2 deletions
|
@ -1200,7 +1200,11 @@ class LibrarySync(Thread):
|
||||||
# No need to process extras or trailers
|
# No need to process extras or trailers
|
||||||
continue
|
continue
|
||||||
status = int(item['state'])
|
status = int(item['state'])
|
||||||
if status == 9:
|
if typus == 'playlist':
|
||||||
|
playlists.process_websocket(plex_id=str(item['itemID']),
|
||||||
|
updated_at=str(item['updatedAt']),
|
||||||
|
state=status)
|
||||||
|
elif status == 9:
|
||||||
# Immediately and always process deletions (as the PMS will
|
# Immediately and always process deletions (as the PMS will
|
||||||
# send additional message with other codes)
|
# send additional message with other codes)
|
||||||
self.items_to_process.append({
|
self.items_to_process.append({
|
||||||
|
|
|
@ -267,6 +267,32 @@ def _kodi_playlist_identical(xml_element):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def process_websocket(plex_id, updated_at, state):
|
||||||
|
"""
|
||||||
|
Hit by librarysync to process websocket messages concerning playlists
|
||||||
|
"""
|
||||||
|
create = False
|
||||||
|
playlist = playlist_object_from_db(plex_id=plex_id)
|
||||||
|
if playlist and state == 9:
|
||||||
|
LOG.debug('Plex deletion of playlist detected: %s', playlist)
|
||||||
|
delete_kodi_playlist(playlist)
|
||||||
|
elif playlist and playlist.plex_updatedat == updated_at:
|
||||||
|
LOG.debug('Playlist with id %s already synced: %s', plex_id, playlist)
|
||||||
|
elif playlist:
|
||||||
|
LOG.debug('Change of Plex playlist detected: %s', playlist)
|
||||||
|
delete_kodi_playlist(playlist)
|
||||||
|
create = True
|
||||||
|
elif not playlist and not state == 9:
|
||||||
|
LOG.debug('Creation of new Plex playlist detected: %s', plex_id)
|
||||||
|
create = True
|
||||||
|
# To the actual work
|
||||||
|
if create:
|
||||||
|
try:
|
||||||
|
create_kodi_playlist(plex_id=plex_id, updated_at=updated_at)
|
||||||
|
except PL.PlaylistError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
@utils.log_time
|
@utils.log_time
|
||||||
def full_sync():
|
def full_sync():
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -332,7 +332,8 @@ PLEX_TYPE_FROM_WEBSOCKET = {
|
||||||
8: PLEX_TYPE_ARTIST,
|
8: PLEX_TYPE_ARTIST,
|
||||||
9: PLEX_TYPE_ALBUM,
|
9: PLEX_TYPE_ALBUM,
|
||||||
10: PLEX_TYPE_SONG,
|
10: PLEX_TYPE_SONG,
|
||||||
12: PLEX_TYPE_CLIP
|
12: PLEX_TYPE_CLIP,
|
||||||
|
15: 'playlist'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue