From 0b2ccde8344fc962a08e302d6d6e944df1db7f10 Mon Sep 17 00:00:00 2001 From: tomkat83 Date: Sun, 23 Oct 2016 16:37:26 +0200 Subject: [PATCH] Message if PMS item could not be deleted --- resources/language/English/strings.xml | 1 + resources/language/German/strings.xml | 1 + resources/lib/PlexFunctions.py | 16 +++++++--------- resources/lib/context_entry.py | 3 ++- resources/lib/downloadutils.py | 4 ++++ 5 files changed, 15 insertions(+), 10 deletions(-) diff --git a/resources/language/English/strings.xml b/resources/language/English/strings.xml index 4a35817e..e3914ee5 100644 --- a/resources/language/English/strings.xml +++ b/resources/language/English/strings.xml @@ -266,6 +266,7 @@ Set custom song rating (0-5) Force transcode Enable Plex context menu in Kodi + Could not delete the Plex item. Is item deletion enabled on the Plex Media Server? Verify Host SSL Certificate (more secure) diff --git a/resources/language/German/strings.xml b/resources/language/German/strings.xml index 6263abb0..da2c8ac1 100644 --- a/resources/language/German/strings.xml +++ b/resources/language/German/strings.xml @@ -298,6 +298,7 @@ Set custom song rating (0-5) Transkodieren erzwingen Plex Kontextmenu in Kodi aktivieren + Konnte das Element nicht löschen. Ist diese Option auf dem Plex Medien Server aktiviert? Kodi wird jetzt neu gestartet um die Änderungen anzuwenden. diff --git a/resources/lib/PlexFunctions.py b/resources/lib/PlexFunctions.py index 1d008e54..aa41031b 100644 --- a/resources/lib/PlexFunctions.py +++ b/resources/lib/PlexFunctions.py @@ -535,13 +535,11 @@ def delete_item_from_pms(plexid): Returns True if successful, False otherwise """ - xml = downloadutils.DownloadUtils().downloadUrl( - '{server}/library/metadata/%s' % plexid, - action_type="DELETE") - try: - xml.attrib - except AttributeError: - log.error('Could not delete Plex id %s' % plexid) + if downloadutils.DownloadUtils().downloadUrl( + '{server}/library/metadata/%s' % plexid, + action_type="DELETE") is True: + log.info('Successfully deleted Plex id %s from the PMS' % plexid) + return True + else: + log.error('Could not delete Plex id %s from the PMS' % plexid) return False - log.info(xml.dump) - return True diff --git a/resources/lib/context_entry.py b/resources/lib/context_entry.py index 65c386ee..ea3333ca 100644 --- a/resources/lib/context_entry.py +++ b/resources/lib/context_entry.py @@ -191,4 +191,5 @@ class ContextMenu(object): if delete: log.info("Deleting Plex item with id %s", self.item_id) - delete_item_from_pms(self.item_id) + if delete_item_from_pms(self.item_id) is False: + dialog(type_="ok", heading="{plex}", line1=lang(30414)) diff --git a/resources/lib/downloadutils.py b/resources/lib/downloadutils.py index 19ed27eb..c77a123a 100644 --- a/resources/lib/downloadutils.py +++ b/resources/lib/downloadutils.py @@ -319,6 +319,10 @@ class DownloadUtils(): log.info('Received text:') log.info(r.text) return True + elif r.status_code == 403: + # E.g. deleting a PMS item + log.error('PMS sent 403: Forbidden error for url %s' % url) + return None else: log.error('Unknown answer from PMS %s with status code %s. ' 'Message:' % (url, r.status_code))