diff --git a/resources/lib/itemtypes.py b/resources/lib/itemtypes.py index 3ba7b452..31fca00b 100644 --- a/resources/lib/itemtypes.py +++ b/resources/lib/itemtypes.py @@ -480,6 +480,7 @@ class Movies(Items): artwork.deleteArtwork(kodi_id, kodi_type, kodicursor) if kodi_type == v.KODI_TYPE_MOVIE: + set_id = self.kodi_db.get_set_id(kodi_id) self.kodi_db.delete_countries(kodi_id, kodi_type) self.kodi_db.delete_people(kodi_id, kodi_type) self.kodi_db.delete_genre(kodi_id, kodi_type) @@ -490,6 +491,8 @@ class Movies(Items): (kodi_id,)) kodicursor.execute("DELETE FROM files WHERE idFile = ?", (file_id,)) + if set_id: + self.kodi_db.delete_possibly_empty_set(set_id) if v.KODIVERSION >= 17: self.kodi_db.remove_uniqueid(kodi_id, kodi_type) self.kodi_db.remove_ratings(kodi_id, kodi_type) diff --git a/resources/lib/kodidb_functions.py b/resources/lib/kodidb_functions.py index 8015ef33..f77a09e8 100644 --- a/resources/lib/kodidb_functions.py +++ b/resources/lib/kodidb_functions.py @@ -990,6 +990,29 @@ class KodiDBMethods(object): )) self.cursor.execute(query, (movieid,)) + def get_set_id(self, kodi_id): + """ + Returns the set_id for the movie with kodi_id or None + """ + query = 'SELECT idSet FROM movie WHERE idMovie = ?' + self.cursor.execute(query, (kodi_id,)) + try: + answ = self.cursor.fetchone()[0] + except TypeError: + answ = None + return answ + + def delete_possibly_empty_set(self, set_id): + """ + Checks whether there are other movies in the set set_id. If not, + deletes the set + """ + query = 'SELECT idSet FROM movie WHERE idSet = ?' + self.cursor.execute(query, (set_id,)) + if self.cursor.fetchone() is None: + query = 'DELETE FROM sets WHERE idSet = ?' + self.cursor.execute(query, (set_id,)) + def addSeason(self, showid, seasonnumber): query = ' '.join((