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):