diff --git a/resources/lib/librarysync.py b/resources/lib/librarysync.py index c011459f..fd5407f7 100644 --- a/resources/lib/librarysync.py +++ b/resources/lib/librarysync.py @@ -1200,7 +1200,11 @@ class LibrarySync(Thread): # No need to process extras or trailers continue 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 # send additional message with other codes) self.items_to_process.append({ diff --git a/resources/lib/playlists.py b/resources/lib/playlists.py index 1ad3d45b..0257f8fb 100644 --- a/resources/lib/playlists.py +++ b/resources/lib/playlists.py @@ -267,6 +267,32 @@ def _kodi_playlist_identical(xml_element): 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 def full_sync(): """ diff --git a/resources/lib/variables.py b/resources/lib/variables.py index 7ad811d2..e8fb9199 100644 --- a/resources/lib/variables.py +++ b/resources/lib/variables.py @@ -332,7 +332,8 @@ PLEX_TYPE_FROM_WEBSOCKET = { 8: PLEX_TYPE_ARTIST, 9: PLEX_TYPE_ALBUM, 10: PLEX_TYPE_SONG, - 12: PLEX_TYPE_CLIP + 12: PLEX_TYPE_CLIP, + 15: 'playlist' }