From b3619201c18566106130b9d4932579bc18cae4c6 Mon Sep 17 00:00:00 2001 From: xnappo Date: Fri, 8 May 2015 11:23:22 -0500 Subject: [PATCH] Re-implement delete Also restores accidently removed items --- resources/lib/KodiMonitor.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/resources/lib/KodiMonitor.py b/resources/lib/KodiMonitor.py index 8e3a439c..954fd6ab 100644 --- a/resources/lib/KodiMonitor.py +++ b/resources/lib/KodiMonitor.py @@ -56,6 +56,31 @@ class Kodi_Monitor(xbmc.Monitor): libSync = LibrarySync().FullLibrarySync() utils.logMsg("Doing_Db_Sync Post Resume: syncDatabase (Finished) " + str(libSync),1) + if method == "VideoLibrary.OnRemove": + xbmc.log('Intercepted remove from sender: ' + sender + ' method: ' + method + ' data: ' + data) + jsondata = json.loads(data) + id = ReadKodiDB().getEmbyIdByKodiId(jsondata.get("id"), jsondata.get("type")) + if id == None: + return + xbmc.log("Deleting Emby ID: " + id + " from database") + connection = utils.KodiSQL() + cursor = connection.cursor() + cursor.execute("DELETE FROM emby WHERE emby_id = ?", (id,)) + connection.commit() + + if jsondata != None: + if jsondata.get("type") == "episode": + url='{server}/mediabrowser/Items?Ids=' + id + '&format=json' + #This is a check to see if the item exists on the server, if it doesn't it may have already been deleted by another client + result = DownloadUtils().downloadUrl(url) + item = result.get("Items")[0] + if data != "": + return_value = xbmcgui.Dialog().yesno("Confirm Delete", "Delete file on Emby Server?") + if return_value: + url='{server}/mediabrowser/Items/' + id + xbmc.log('Deleting via URL: ' + url) + DownloadUtils().downloadUrl(url, type="DELETE") + def clearProperty(self,type,id): # The sleep is necessary since VideoLibrary.OnUpdate # triggers 3 times in a row.