[31] update item delete

pull/1201/head
meisnate12 2 years ago
parent 71465c3378
commit 5103a576db

@ -1 +1 @@
1.18.0-develop30 1.18.0-develop31

@ -804,13 +804,15 @@ class CollectionBuilder:
if self.build_collection: if self.build_collection:
try: try:
self.obj = self.library.get_playlist(self.name) if self.playlist else self.library.get_collection(self.name, force_search=True) 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): if (self.smart and not self.obj.smart) or (not self.smart and self.obj.smart):
logger.info("") logger.info("")
logger.error(f"{self.Type} Error: Converting {self.obj.title} to a {'smart' if self.smart else 'normal'} collection") 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 self.obj = None
except Failed:
self.obj = None
if self.smart: if self.smart:
check_url = self.smart_url if self.smart_url else self.smart_label_url 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): if self.obj and check_url != self.library.smart_filter(self.obj):
@ -2780,14 +2782,14 @@ class CollectionBuilder:
else: else:
output = "" output = ""
if self.obj: if self.obj:
self.library.query(self.obj.delete) self.library.delete(self.obj)
if self.playlist and self.valid_users: if self.playlist and self.valid_users:
for user in self.valid_users: for user in self.valid_users:
try: try:
self.library.delete_user_playlist(self.obj.title, user) self.library.delete_user_playlist(self.obj.title, user)
output += f"\nPlaylist deleted on User {user}" output += f"\nPlaylist deleted on User {user}"
except NotFound: except Failed:
output += f"\nPlaylist not found on User {user}" output += f"\nPlaylist not found on User {user}"
return output return output
@ -2799,7 +2801,7 @@ class CollectionBuilder:
for user in self.valid_users: for user in self.valid_users:
try: try:
self.library.delete_user_playlist(self.obj.title, user) self.library.delete_user_playlist(self.obj.title, user)
except NotFound: except Failed:
pass pass
self.obj.copyToUser(user) self.obj.copyToUser(user)
logger.info(f"Playlist: {self.name} synced to {user}") logger.info(f"Playlist: {self.name} synced to {user}")

@ -1005,8 +1005,11 @@ class MetadataFile(DataFile):
sync.pop(other_name) sync.pop(other_name)
self.collections[other_name] = col self.collections[other_name] = col
for col_title, col in sync.items(): for col_title, col in sync.items():
col.delete() try:
logger.info(f"{map_name} Dynamic Collection: {col_title} Deleted") 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: except Failed as e:
logger.error(e) logger.error(e)
logger.error(f"{map_name} Dynamic Collection Failed") logger.error(f"{map_name} Dynamic Collection Failed")

@ -731,8 +731,11 @@ class Operations:
and (configured is None and (configured is None
or (configured is True and col.title in self.library.collections) or (configured is True and col.title in self.library.collections)
or (configured is False and col.title not in self.library.collections)): or (configured is False and col.title not in self.library.collections)):
self.library.query(col.delete) try:
logger.info(f"{col.title} Deleted") self.library.delete(col)
logger.info(f"{col.title} Deleted")
except Failed as e:
logger.error(e)
else: else:
if "PMM" not in labels: if "PMM" not in labels:
unmanaged_collections.append(col) unmanaged_collections.append(col)

@ -555,6 +555,13 @@ class Plex(Library):
def query(self, method): def query(self, method):
return 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) @retry(stop_max_attempt_number=6, wait_fixed=10000, retry_on_exception=util.retry_if_not_plex)
def query_data(self, method, data): def query_data(self, method, data):
return method(data) return method(data)
@ -708,7 +715,7 @@ class Plex(Library):
return self._users return self._users
def delete_user_playlist(self, title, user): def delete_user_playlist(self, title, user):
self.PlexServer.switchUser(user).playlist(title).delete() self.delete(self.PlexServer.switchUser(user).playlist(title))
@property @property
def account(self): def account(self):

@ -459,10 +459,10 @@ def run_libraries(config):
logger.info("") logger.info("")
for collection in library.get_all_collections(): for collection in library.get_all_collections():
try: try:
library.query(collection.delete) library.delete(collection)
logger.info(f"Collection {collection.title} Deleted") logger.info(f"Collection {collection.title} Deleted")
except NotFound: except Failed as e:
logger.error(f"Collection {collection.title} Failed to Delete") logger.error(e)
library_status[library.name]["All Collections Deleted"] = str(datetime.now() - time_start).split('.')[0] library_status[library.name]["All Collections Deleted"] = str(datetime.now() - time_start).split('.')[0]
if delete_labels and not playlist_only: if delete_labels and not playlist_only:

Loading…
Cancel
Save