From 5103a576dbf895e2aa15bdb3536ea3af649cb3a5 Mon Sep 17 00:00:00 2001 From: meisnate12 Date: Mon, 28 Nov 2022 17:00:54 -0500 Subject: [PATCH] [31] update item delete --- VERSION | 2 +- modules/builder.py | 14 ++++++++------ modules/meta.py | 7 +++++-- modules/operations.py | 7 +++++-- modules/plex.py | 9 ++++++++- plex_meta_manager.py | 6 +++--- 6 files changed, 30 insertions(+), 15 deletions(-) diff --git a/VERSION b/VERSION index a48c6270..5ac9c060 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.18.0-develop30 +1.18.0-develop31 diff --git a/modules/builder.py b/modules/builder.py index 3f289826..193d4d45 100644 --- a/modules/builder.py +++ b/modules/builder.py @@ -804,13 +804,15 @@ class CollectionBuilder: if self.build_collection: try: self.obj = self.library.get_playlist(self.name) if self.playlist else self.library.get_collection(self.name, force_search=True) + except Failed: + self.obj = None + else: if (self.smart and not self.obj.smart) or (not self.smart and self.obj.smart): logger.info("") logger.error(f"{self.Type} Error: Converting {self.obj.title} to a {'smart' if self.smart else 'normal'} collection") - self.library.query(self.obj.delete) + self.library.delete(self.obj) self.obj = None - except Failed: - self.obj = None + if self.smart: check_url = self.smart_url if self.smart_url else self.smart_label_url if self.obj and check_url != self.library.smart_filter(self.obj): @@ -2780,14 +2782,14 @@ class CollectionBuilder: else: output = "" if self.obj: - self.library.query(self.obj.delete) + self.library.delete(self.obj) if self.playlist and self.valid_users: for user in self.valid_users: try: self.library.delete_user_playlist(self.obj.title, user) output += f"\nPlaylist deleted on User {user}" - except NotFound: + except Failed: output += f"\nPlaylist not found on User {user}" return output @@ -2799,7 +2801,7 @@ class CollectionBuilder: for user in self.valid_users: try: self.library.delete_user_playlist(self.obj.title, user) - except NotFound: + except Failed: pass self.obj.copyToUser(user) logger.info(f"Playlist: {self.name} synced to {user}") diff --git a/modules/meta.py b/modules/meta.py index 58116e33..a1ffc60d 100644 --- a/modules/meta.py +++ b/modules/meta.py @@ -1005,8 +1005,11 @@ class MetadataFile(DataFile): sync.pop(other_name) self.collections[other_name] = col for col_title, col in sync.items(): - col.delete() - logger.info(f"{map_name} Dynamic Collection: {col_title} Deleted") + try: + self.library.delete(col) + logger.info(f"{map_name} Dynamic Collection: {col_title} Deleted") + except Failed as e: + logger.error(e) except Failed as e: logger.error(e) logger.error(f"{map_name} Dynamic Collection Failed") diff --git a/modules/operations.py b/modules/operations.py index 73b99642..f66371ed 100644 --- a/modules/operations.py +++ b/modules/operations.py @@ -731,8 +731,11 @@ class Operations: and (configured is None or (configured is True and col.title in self.library.collections) or (configured is False and col.title not in self.library.collections)): - self.library.query(col.delete) - logger.info(f"{col.title} Deleted") + try: + self.library.delete(col) + logger.info(f"{col.title} Deleted") + except Failed as e: + logger.error(e) else: if "PMM" not in labels: unmanaged_collections.append(col) diff --git a/modules/plex.py b/modules/plex.py index f995abda..21f5048b 100644 --- a/modules/plex.py +++ b/modules/plex.py @@ -555,6 +555,13 @@ class Plex(Library): def query(self, method): return method() + def delete(self, obj): + try: + return self.query(obj.delete) + except Exception: + logger.stacktrace() + raise Failed(f"Plex Error: Failed to delete {obj.title}") + @retry(stop_max_attempt_number=6, wait_fixed=10000, retry_on_exception=util.retry_if_not_plex) def query_data(self, method, data): return method(data) @@ -708,7 +715,7 @@ class Plex(Library): return self._users def delete_user_playlist(self, title, user): - self.PlexServer.switchUser(user).playlist(title).delete() + self.delete(self.PlexServer.switchUser(user).playlist(title)) @property def account(self): diff --git a/plex_meta_manager.py b/plex_meta_manager.py index 4b1b348d..fb31c68b 100644 --- a/plex_meta_manager.py +++ b/plex_meta_manager.py @@ -459,10 +459,10 @@ def run_libraries(config): logger.info("") for collection in library.get_all_collections(): try: - library.query(collection.delete) + library.delete(collection) logger.info(f"Collection {collection.title} Deleted") - except NotFound: - logger.error(f"Collection {collection.title} Failed to Delete") + except Failed as e: + logger.error(e) library_status[library.name]["All Collections Deleted"] = str(datetime.now() - time_start).split('.')[0] if delete_labels and not playlist_only: