Remove uniqueid and ratings entries if item deleted

This commit is contained in:
tomkat83 2017-02-02 16:53:50 +01:00
parent 874e9a8fc5
commit dd0339b51c
2 changed files with 43 additions and 27 deletions

View file

@ -460,38 +460,40 @@ class Movies(Items):
plex_dbitem = plex_db.getItem_byId(itemid)
try:
kodiid = plex_dbitem[0]
fileid = plex_dbitem[1]
mediatype = plex_dbitem[4]
log.info("Removing %sid: %s fileid: %s"
% (mediatype, kodiid, fileid))
kodi_id = plex_dbitem[0]
file_id = plex_dbitem[1]
kodi_type = plex_dbitem[4]
log.info("Removing %sid: %s file_id: %s"
% (kodi_type, kodi_id, file_id))
except TypeError:
return
# Remove the plex reference
plex_db.removeItem(itemid)
# Remove artwork
artwork.deleteArtwork(kodiid, mediatype, kodicursor)
artwork.deleteArtwork(kodi_id, kodi_type, kodicursor)
if mediatype == "movie":
if kodi_type == v.KODI_TYPE_MOVIE:
# Delete kodi movie and file
kodicursor.execute("DELETE FROM movie WHERE idMovie = ?", (kodiid,))
kodicursor.execute("DELETE FROM files WHERE idFile = ?", (fileid,))
elif mediatype == "set":
kodicursor.execute("DELETE FROM movie WHERE idMovie = ?",
(kodi_id,))
kodicursor.execute("DELETE FROM files WHERE idFile = ?",
(file_id,))
if v.KODIVERSION >= 17:
plex_db.remove_uniqueid(kodi_id, kodi_type)
plex_db.remove_ratings(kodi_id, kodi_type)
elif kodi_type == v.KODI_TYPE_SET:
# Delete kodi boxset
boxset_movies = plex_db.getItem_byParentId(kodiid, "movie")
boxset_movies = plex_db.getItem_byParentId(kodi_id,
v.KODI_TYPE_MOVIE)
for movie in boxset_movies:
plexid = movie[0]
movieid = movie[1]
self.kodi_db.removefromBoxset(movieid)
# Update plex reference
plex_db.updateParentId(plexid, None)
kodicursor.execute("DELETE FROM sets WHERE idSet = ?", (kodiid,))
log.info("Deleted %s %s from kodi database"
% (mediatype, itemid))
kodicursor.execute("DELETE FROM sets WHERE idSet = ?", (kodi_id,))
log.info("Deleted %s %s from kodi database" % (kodi_type, itemid))
class TVShows(Items):
@ -1081,7 +1083,6 @@ class TVShows(Items):
try:
kodiid = plex_dbitem[0]
fileid = plex_dbitem[1]
pathid = plex_dbitem[2]
parentid = plex_dbitem[3]
mediatype = plex_dbitem[4]
log.info("Removing %s kodiid: %s fileid: %s"
@ -1094,7 +1095,6 @@ class TVShows(Items):
# Remove the plex reference
plex_db.removeItem(itemid)
##### IF EPISODE #####
if mediatype == v.KODI_TYPE_EPISODE:
@ -1107,7 +1107,6 @@ class TVShows(Items):
showid = season[1]
except TypeError:
return
season_episodes = plex_db.getItem_byParentId(parentid,
v.KODI_TYPE_EPISODE)
if not season_episodes:
@ -1139,14 +1138,14 @@ class TVShows(Items):
##### IF TVSHOW #####
elif mediatype == "tvshow":
elif mediatype == v.KODI_TYPE_SHOW:
# Remove episodes, seasons, tvshow
seasons = plex_db.getItem_byParentId(kodiid,
v.KODI_TYPE_SEASON)
for season in seasons:
seasonid = season[1]
season_episodes = plex_db.getItem_byParentId(seasonid,
v.KODI_TYPE_EPISODE)
season_episodes = plex_db.getItem_byParentId(
seasonid, v.KODI_TYPE_EPISODE)
for episode in season_episodes:
self.removeEpisode(episode[1], episode[2])
else:
@ -1185,11 +1184,14 @@ class TVShows(Items):
log.debug("Deleted %s: %s from kodi database" % (mediatype, itemid))
def removeShow(self, kodiid):
def removeShow(self, kodi_id):
kodicursor = self.kodicursor
self.artwork.deleteArtwork(kodiid, "tvshow", kodicursor)
kodicursor.execute("DELETE FROM tvshow WHERE idShow = ?", (kodiid,))
log.info("Removed tvshow: %s." % kodiid)
self.artwork.deleteArtwork(kodi_id, v.KODI_TYPE_SHOW, kodicursor)
kodicursor.execute("DELETE FROM tvshow WHERE idShow = ?", (kodi_id,))
if v.KODIVERSION >= 17:
self.plex_db.remove_uniqueid(kodi_id, v.KODI_TYPE_SHOW)
self.plex_db.remove_ratings(kodi_id, v.KODI_TYPE_SHOW)
log.info("Removed tvshow: %s." % kodi_id)
def removeSeason(self, kodiid):
kodicursor = self.kodicursor

View file

@ -1454,6 +1454,13 @@ class Kodidb_Functions():
'''
self.cursor.execute(query, (args))
def remove_uniqueid(self, kodi_id, kodi_type):
query = '''
DELETE FROM uniqueid
WHERE media_id = ? AND media_type = ?
'''
self.cursor.execute(query, (kodi_id, kodi_type))
def create_entry_rating(self):
self.cursor.execute("select coalesce(max(rating_id),0) from rating")
return self.cursor.fetchone()[0] + 1
@ -1496,6 +1503,13 @@ class Kodidb_Functions():
'''
self.cursor.execute(query, (args))
def remove_ratings(self, kodi_id, kodi_type):
query = '''
DELETE FROM rating
WHERE media_id = ? AND media_type = ?
'''
self.cursor.execute(query, (kodi_id, kodi_type))
def get_kodiid_from_filename(file):
"""