From a7939f8b241966fd4b8883658c8e2cc9cacb6270 Mon Sep 17 00:00:00 2001 From: croneter Date: Sun, 11 Mar 2018 11:47:04 +0100 Subject: [PATCH] Also delete orphaned path entries in Kodi DB --- resources/lib/itemtypes.py | 2 ++ resources/lib/kodidb_functions.py | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/resources/lib/itemtypes.py b/resources/lib/itemtypes.py index 9b2e2736..73c727ac 100644 --- a/resources/lib/itemtypes.py +++ b/resources/lib/itemtypes.py @@ -307,6 +307,7 @@ class Movies(Items): if update_item: LOG.info("UPDATE movie itemid: %s - Title: %s", itemid, title) if fileid != old_fileid: + LOG.debug('Removing old file entry: %s', old_fileid) self.kodi_db.remove_file(old_fileid) # Update the movie entry if v.KODIVERSION >= 17: @@ -869,6 +870,7 @@ class TVShows(Items): if update_item: LOG.info("UPDATE episode itemid: %s", itemid) if fileid != old_fileid: + LOG.debug('Removing old file entry: %s', old_fileid) self.kodi_db.remove_file(old_fileid) # Update the movie entry if v.KODIVERSION >= 17: diff --git a/resources/lib/kodidb_functions.py b/resources/lib/kodidb_functions.py index 1bb14c3c..6579a117 100644 --- a/resources/lib/kodidb_functions.py +++ b/resources/lib/kodidb_functions.py @@ -209,6 +209,9 @@ class KodiDBMethods(object): Removes the entry for file_id from the files table. Will also delete entries from the associated tables: bookmark, settings, streamdetails """ + self.cursor.execute('SELECT idPath FROM files WHERE idFile = ? LIMIT 1', + (file_id,)) + path_id = self.cursor.fetchone()[0] self.cursor.execute('DELETE FROM files WHERE idFile = ?', (file_id,)) self.cursor.execute('DELETE FROM bookmark WHERE idFile = ?', @@ -217,6 +220,14 @@ class KodiDBMethods(object): (file_id,)) self.cursor.execute('DELETE FROM streamdetails WHERE idFile = ?', (file_id,)) + self.cursor.execute('DELETE FROM stacktimes WHERE idFile = ?', + (file_id,)) + # Delete orphaned path entry + self.cursor.execute('SELECT idFile FROM files WHERE idPath = ? LIMIT 1', + (path_id,)) + if self.cursor.fetchone() is None: + self.cursor.execute('DELETE FROM path WHERE idPath = ?', + (path_id,)) def getFile(self, fileid):