Delete people entries from Kodi DB
This commit is contained in:
parent
b79ed87ea7
commit
411f691547
2 changed files with 60 additions and 0 deletions
|
@ -481,6 +481,7 @@ class Movies(Items):
|
||||||
|
|
||||||
if kodi_type == v.KODI_TYPE_MOVIE:
|
if kodi_type == v.KODI_TYPE_MOVIE:
|
||||||
self.kodi_db.delete_countries(kodi_id, kodi_type)
|
self.kodi_db.delete_countries(kodi_id, kodi_type)
|
||||||
|
self.kodi_db.delete_people(kodi_id, kodi_type)
|
||||||
# Delete kodi movie and file
|
# Delete kodi movie and file
|
||||||
kodicursor.execute("DELETE FROM movie WHERE idMovie = ?",
|
kodicursor.execute("DELETE FROM movie WHERE idMovie = ?",
|
||||||
(kodi_id,))
|
(kodi_id,))
|
||||||
|
@ -1226,6 +1227,7 @@ class TVShows(Items):
|
||||||
Remove an episode, and episode only
|
Remove an episode, and episode only
|
||||||
"""
|
"""
|
||||||
kodicursor = self.kodicursor
|
kodicursor = self.kodicursor
|
||||||
|
self.kodi_db.delete_people(kodi_id, v.KODI_TYPE_EPISODE)
|
||||||
self.artwork.deleteArtwork(kodi_id, "episode", kodicursor)
|
self.artwork.deleteArtwork(kodi_id, "episode", kodicursor)
|
||||||
kodicursor.execute("DELETE FROM episode WHERE idEpisode = ?",
|
kodicursor.execute("DELETE FROM episode WHERE idEpisode = ?",
|
||||||
(kodi_id,))
|
(kodi_id,))
|
||||||
|
|
|
@ -370,6 +370,64 @@ class KodiDBMethods(object):
|
||||||
person['Type'].lower(), "thumb",
|
person['Type'].lower(), "thumb",
|
||||||
self.cursor)
|
self.cursor)
|
||||||
|
|
||||||
|
def delete_people(self, kodi_id, kodi_type):
|
||||||
|
"""
|
||||||
|
Assuming that the video kodi_id, kodi_type gets deleted, will delete any
|
||||||
|
associated actor_, director_, writer_links and also deletes
|
||||||
|
orphaned actors
|
||||||
|
"""
|
||||||
|
# Actors
|
||||||
|
query = '''
|
||||||
|
SELECT actor_id FROM actor_link
|
||||||
|
WHERE media_id = ? AND media_type = ?
|
||||||
|
'''
|
||||||
|
self.cursor.execute(query, (kodi_id, kodi_type))
|
||||||
|
actor_ids = self.cursor.fetchall()
|
||||||
|
query = 'DELETE FROM actor_link WHERE media_id = ? AND media_type = ?'
|
||||||
|
self.cursor.execute(query, (kodi_id, kodi_type))
|
||||||
|
# Directors
|
||||||
|
query = '''
|
||||||
|
SELECT actor_id FROM director_link
|
||||||
|
WHERE media_id = ? AND media_type = ?
|
||||||
|
'''
|
||||||
|
self.cursor.execute(query, (kodi_id, kodi_type))
|
||||||
|
actor_ids.extend(self.cursor.fetchall())
|
||||||
|
query = '''
|
||||||
|
DELETE FROM director_link WHERE media_id = ? AND media_type = ?
|
||||||
|
'''
|
||||||
|
self.cursor.execute(query, (kodi_id, kodi_type))
|
||||||
|
# Writers
|
||||||
|
query = '''
|
||||||
|
SELECT actor_id FROM writer_link
|
||||||
|
WHERE media_id = ? AND media_type = ?
|
||||||
|
'''
|
||||||
|
self.cursor.execute(query, (kodi_id, kodi_type))
|
||||||
|
actor_ids.extend(self.cursor.fetchall())
|
||||||
|
query = '''
|
||||||
|
DELETE FROM writer_link WHERE media_id = ? AND media_type = ?
|
||||||
|
'''
|
||||||
|
self.cursor.execute(query, (kodi_id, kodi_type))
|
||||||
|
# Which people are now orphaned?
|
||||||
|
query_actor = 'SELECT actor_id FROM actor_link WHERE actor_id = ?'
|
||||||
|
query_director = 'SELECT actor_id FROM director_link WHERE actor_id = ?'
|
||||||
|
query_writer = 'SELECT actor_id FROM writer_link WHERE actor_id = ?'
|
||||||
|
query_delete = 'DELETE FROM actor WHERE actor_id = ?'
|
||||||
|
# Delete orphaned people
|
||||||
|
for actor_id in actor_ids:
|
||||||
|
self.cursor.execute(query_actor, (actor_id,))
|
||||||
|
if self.cursor.fetchone() is None:
|
||||||
|
self.cursor.execute(query_director, (actor_id,))
|
||||||
|
if self.cursor.fetchone() is None:
|
||||||
|
self.cursor.execute(query_writer, (actor_id,))
|
||||||
|
if self.cursor.fetchone() is None:
|
||||||
|
# Delete the person itself from actor table
|
||||||
|
self.cursor.execute(query_delete, (actor_id,))
|
||||||
|
# Delete any associated artwork
|
||||||
|
self.artwork.deleteArtwork(actor_id,
|
||||||
|
'actor',
|
||||||
|
self.cursor)
|
||||||
|
|
||||||
|
|
||||||
def existingArt(self, kodiId, mediaType, refresh=False):
|
def existingArt(self, kodiId, mediaType, refresh=False):
|
||||||
"""
|
"""
|
||||||
For kodiId, returns an artwork dict with already existing art from
|
For kodiId, returns an artwork dict with already existing art from
|
||||||
|
|
Loading…
Reference in a new issue