From 70d809f1791bbc69bd15570c6e95c35692a278db Mon Sep 17 00:00:00 2001 From: croneter Date: Sat, 7 Jul 2018 19:10:52 +0200 Subject: [PATCH] Add some safety nets for playlist sync --- resources/lib/playlists.py | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/resources/lib/playlists.py b/resources/lib/playlists.py index 49db5352..0cf648c7 100644 --- a/resources/lib/playlists.py +++ b/resources/lib/playlists.py @@ -520,9 +520,14 @@ class PlaylistEventhandler(events.FileSystemEventHandler): def on_created(self, event): LOG.debug('on_created: %s', event.src_path) old_playlist = playlist_object_from_db(path=event.src_path) - if old_playlist: + if (old_playlist and old_playlist.kodi_hash == + utils.generate_file_md5(event.src_path)): LOG.debug('Playlist already in DB - skipping') return + elif old_playlist: + LOG.debug('Playlist already in DB but it has been changed') + self.on_modified(event) + return playlist = PL.Playlist_Object() playlist.kodi_path = event.src_path playlist.kodi_hash = utils.generate_file_md5(event.src_path) @@ -531,20 +536,13 @@ class PlaylistEventhandler(events.FileSystemEventHandler): except PL.PlaylistError: pass - def on_deleted(self, event): - LOG.debug('on_deleted: %s', event.src_path) - playlist = playlist_object_from_db(path=event.src_path) - if not playlist: - LOG.error('Playlist not found in DB for path %s', event.src_path) - else: - delete_plex_playlist(playlist) - def on_modified(self, event): LOG.debug('on_modified: %s', event.src_path) old_playlist = playlist_object_from_db(path=event.src_path) new_playlist = PL.Playlist_Object() if old_playlist: - # Retain the name! Might've vom from Plex + # Retain the name! Might've come from Plex + # (rename should fire on_moved) new_playlist.plex_name = old_playlist.plex_name new_playlist.kodi_path = event.src_path new_playlist.kodi_hash = utils.generate_file_md5(event.src_path) @@ -578,6 +576,14 @@ class PlaylistEventhandler(events.FileSystemEventHandler): except PL.PlaylistError: pass + def on_deleted(self, event): + LOG.debug('on_deleted: %s', event.src_path) + playlist = playlist_object_from_db(path=event.src_path) + if not playlist: + LOG.error('Playlist not found in DB for path %s', event.src_path) + else: + delete_plex_playlist(playlist) + class PlaylistQueue(OrderedSetQueue): """