Remove uniqueid and ratings entries if item deleted
This commit is contained in:
parent
874e9a8fc5
commit
dd0339b51c
2 changed files with 43 additions and 27 deletions
|
@ -460,38 +460,40 @@ class Movies(Items):
|
||||||
|
|
||||||
plex_dbitem = plex_db.getItem_byId(itemid)
|
plex_dbitem = plex_db.getItem_byId(itemid)
|
||||||
try:
|
try:
|
||||||
kodiid = plex_dbitem[0]
|
kodi_id = plex_dbitem[0]
|
||||||
fileid = plex_dbitem[1]
|
file_id = plex_dbitem[1]
|
||||||
mediatype = plex_dbitem[4]
|
kodi_type = plex_dbitem[4]
|
||||||
log.info("Removing %sid: %s fileid: %s"
|
log.info("Removing %sid: %s file_id: %s"
|
||||||
% (mediatype, kodiid, fileid))
|
% (kodi_type, kodi_id, file_id))
|
||||||
except TypeError:
|
except TypeError:
|
||||||
return
|
return
|
||||||
|
|
||||||
# Remove the plex reference
|
# Remove the plex reference
|
||||||
plex_db.removeItem(itemid)
|
plex_db.removeItem(itemid)
|
||||||
# Remove artwork
|
# 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
|
# Delete kodi movie and file
|
||||||
kodicursor.execute("DELETE FROM movie WHERE idMovie = ?", (kodiid,))
|
kodicursor.execute("DELETE FROM movie WHERE idMovie = ?",
|
||||||
kodicursor.execute("DELETE FROM files WHERE idFile = ?", (fileid,))
|
(kodi_id,))
|
||||||
|
kodicursor.execute("DELETE FROM files WHERE idFile = ?",
|
||||||
elif mediatype == "set":
|
(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
|
# 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:
|
for movie in boxset_movies:
|
||||||
plexid = movie[0]
|
plexid = movie[0]
|
||||||
movieid = movie[1]
|
movieid = movie[1]
|
||||||
self.kodi_db.removefromBoxset(movieid)
|
self.kodi_db.removefromBoxset(movieid)
|
||||||
# Update plex reference
|
# Update plex reference
|
||||||
plex_db.updateParentId(plexid, None)
|
plex_db.updateParentId(plexid, None)
|
||||||
|
kodicursor.execute("DELETE FROM sets WHERE idSet = ?", (kodi_id,))
|
||||||
kodicursor.execute("DELETE FROM sets WHERE idSet = ?", (kodiid,))
|
log.info("Deleted %s %s from kodi database" % (kodi_type, itemid))
|
||||||
|
|
||||||
log.info("Deleted %s %s from kodi database"
|
|
||||||
% (mediatype, itemid))
|
|
||||||
|
|
||||||
|
|
||||||
class TVShows(Items):
|
class TVShows(Items):
|
||||||
|
@ -1081,7 +1083,6 @@ class TVShows(Items):
|
||||||
try:
|
try:
|
||||||
kodiid = plex_dbitem[0]
|
kodiid = plex_dbitem[0]
|
||||||
fileid = plex_dbitem[1]
|
fileid = plex_dbitem[1]
|
||||||
pathid = plex_dbitem[2]
|
|
||||||
parentid = plex_dbitem[3]
|
parentid = plex_dbitem[3]
|
||||||
mediatype = plex_dbitem[4]
|
mediatype = plex_dbitem[4]
|
||||||
log.info("Removing %s kodiid: %s fileid: %s"
|
log.info("Removing %s kodiid: %s fileid: %s"
|
||||||
|
@ -1094,7 +1095,6 @@ class TVShows(Items):
|
||||||
# Remove the plex reference
|
# Remove the plex reference
|
||||||
plex_db.removeItem(itemid)
|
plex_db.removeItem(itemid)
|
||||||
|
|
||||||
|
|
||||||
##### IF EPISODE #####
|
##### IF EPISODE #####
|
||||||
|
|
||||||
if mediatype == v.KODI_TYPE_EPISODE:
|
if mediatype == v.KODI_TYPE_EPISODE:
|
||||||
|
@ -1107,7 +1107,6 @@ class TVShows(Items):
|
||||||
showid = season[1]
|
showid = season[1]
|
||||||
except TypeError:
|
except TypeError:
|
||||||
return
|
return
|
||||||
|
|
||||||
season_episodes = plex_db.getItem_byParentId(parentid,
|
season_episodes = plex_db.getItem_byParentId(parentid,
|
||||||
v.KODI_TYPE_EPISODE)
|
v.KODI_TYPE_EPISODE)
|
||||||
if not season_episodes:
|
if not season_episodes:
|
||||||
|
@ -1139,14 +1138,14 @@ class TVShows(Items):
|
||||||
|
|
||||||
##### IF TVSHOW #####
|
##### IF TVSHOW #####
|
||||||
|
|
||||||
elif mediatype == "tvshow":
|
elif mediatype == v.KODI_TYPE_SHOW:
|
||||||
# Remove episodes, seasons, tvshow
|
# Remove episodes, seasons, tvshow
|
||||||
seasons = plex_db.getItem_byParentId(kodiid,
|
seasons = plex_db.getItem_byParentId(kodiid,
|
||||||
v.KODI_TYPE_SEASON)
|
v.KODI_TYPE_SEASON)
|
||||||
for season in seasons:
|
for season in seasons:
|
||||||
seasonid = season[1]
|
seasonid = season[1]
|
||||||
season_episodes = plex_db.getItem_byParentId(seasonid,
|
season_episodes = plex_db.getItem_byParentId(
|
||||||
v.KODI_TYPE_EPISODE)
|
seasonid, v.KODI_TYPE_EPISODE)
|
||||||
for episode in season_episodes:
|
for episode in season_episodes:
|
||||||
self.removeEpisode(episode[1], episode[2])
|
self.removeEpisode(episode[1], episode[2])
|
||||||
else:
|
else:
|
||||||
|
@ -1185,11 +1184,14 @@ class TVShows(Items):
|
||||||
|
|
||||||
log.debug("Deleted %s: %s from kodi database" % (mediatype, itemid))
|
log.debug("Deleted %s: %s from kodi database" % (mediatype, itemid))
|
||||||
|
|
||||||
def removeShow(self, kodiid):
|
def removeShow(self, kodi_id):
|
||||||
kodicursor = self.kodicursor
|
kodicursor = self.kodicursor
|
||||||
self.artwork.deleteArtwork(kodiid, "tvshow", kodicursor)
|
self.artwork.deleteArtwork(kodi_id, v.KODI_TYPE_SHOW, kodicursor)
|
||||||
kodicursor.execute("DELETE FROM tvshow WHERE idShow = ?", (kodiid,))
|
kodicursor.execute("DELETE FROM tvshow WHERE idShow = ?", (kodi_id,))
|
||||||
log.info("Removed tvshow: %s." % kodiid)
|
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):
|
def removeSeason(self, kodiid):
|
||||||
kodicursor = self.kodicursor
|
kodicursor = self.kodicursor
|
||||||
|
|
|
@ -1454,6 +1454,13 @@ class Kodidb_Functions():
|
||||||
'''
|
'''
|
||||||
self.cursor.execute(query, (args))
|
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):
|
def create_entry_rating(self):
|
||||||
self.cursor.execute("select coalesce(max(rating_id),0) from rating")
|
self.cursor.execute("select coalesce(max(rating_id),0) from rating")
|
||||||
return self.cursor.fetchone()[0] + 1
|
return self.cursor.fetchone()[0] + 1
|
||||||
|
@ -1496,6 +1503,13 @@ class Kodidb_Functions():
|
||||||
'''
|
'''
|
||||||
self.cursor.execute(query, (args))
|
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):
|
def get_kodiid_from_filename(file):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in a new issue