Delete empty movie sets from Kodi DB
This commit is contained in:
parent
9540e3505c
commit
769fe8b926
2 changed files with 26 additions and 0 deletions
|
@ -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)
|
||||
|
|
|
@ -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((
|
||||
|
|
Loading…
Reference in a new issue