From 3421661e222ab97b3355c48b004298ae4c35e0fa Mon Sep 17 00:00:00 2001 From: blacktwin Date: Mon, 21 Dec 2020 13:27:59 -0500 Subject: [PATCH] adding try/except for addressing #273 --- utility/media_manager.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/utility/media_manager.py b/utility/media_manager.py index 7f33a02..24a4ec1 100644 --- a/utility/media_manager.py +++ b/utility/media_manager.py @@ -33,6 +33,7 @@ import re from collections import Counter from plexapi.server import PlexServer from plexapi.server import CONFIG +from plexapi.exceptions import NotFound from requests import Session from requests.adapters import HTTPAdapter from requests.exceptions import RequestException @@ -301,12 +302,15 @@ def plex_deletion(items, libraries, toggleDeletion): print("The following items were added before {} and marked for deletion.".format(opts.date)) for item in items: - if isinstance(item, int): - plex_item = plex.fetchItem(item) - else: - plex_item = plex.fetchItem(int(item.rating_key)) - plex_item.delete() - print("Item: {} was deleted".format(plex_item.title)) + try: + if isinstance(item, int): + plex_item = plex.fetchItem(item) + else: + plex_item = plex.fetchItem(int(item.rating_key)) + plex_item.delete() + print("Item: {} was deleted".format(plex_item.title)) + except NotFound: + print("Item: {} may already have been deleted.".format(item)) for _library in libraries: section = plex.library.sectionByID(_library.key) print("Emptying Trash from library {}".format(_library.title))