Repair entries

For the video library. This is for the scenario where Kodi erases the
entry, but it still exists in the emby database.
This commit is contained in:
angelblue05 2016-02-13 22:42:16 -06:00
parent e1d5bff89e
commit 1bcba15cd9
1 changed files with 56 additions and 2 deletions

View File

@ -283,6 +283,17 @@ class Movies(Items):
kodicursor.execute("select coalesce(max(idMovie),0) from movie") kodicursor.execute("select coalesce(max(idMovie),0) from movie")
movieid = kodicursor.fetchone()[0] + 1 movieid = kodicursor.fetchone()[0] + 1
else:
# Verification the item is still in Kodi
query = "SELECT * FROM movie WHERE idMovie = ?"
kodicursor.execute(query, (movieid,))
try:
kodicursor.fetchone()[0]
except TypeError:
# item is not found, let's recreate it.
update_item = False
self.logMsg("movieid: %s missing from Kodi, repairing the entry." % movieid, 1)
if not viewtag or not viewid: if not viewtag or not viewid:
# Get view tag from emby # Get view tag from emby
viewtag, viewid, mediatype = self.emby.getView_embyId(itemid) viewtag, viewid, mediatype = self.emby.getView_embyId(itemid)
@ -665,6 +676,17 @@ class MusicVideos(Items):
kodicursor.execute("select coalesce(max(idMVideo),0) from musicvideo") kodicursor.execute("select coalesce(max(idMVideo),0) from musicvideo")
mvideoid = kodicursor.fetchone()[0] + 1 mvideoid = kodicursor.fetchone()[0] + 1
else:
# Verification the item is still in Kodi
query = "SELECT * FROM musicvideo WHERE idMVideo = ?"
kodicursor.execute(query, (mvideoid,))
try:
kodicursor.fetchone()[0]
except TypeError:
# item is not found, let's recreate it.
update_item = False
self.logMsg("mvideoid: %s missing from Kodi, repairing the entry." % mvideoid, 1)
if not viewtag or not viewid: if not viewtag or not viewid:
# Get view tag from emby # Get view tag from emby
viewtag, viewid, mediatype = self.emby.getView_embyId(itemid) viewtag, viewid, mediatype = self.emby.getView_embyId(itemid)
@ -991,6 +1013,7 @@ class TVShows(Items):
# If the item already exist in the local Kodi DB we'll perform a full item update # If the item already exist in the local Kodi DB we'll perform a full item update
# If the item doesn't exist, we'll add it to the database # If the item doesn't exist, we'll add it to the database
update_item = True update_item = True
force_episodes = False
itemid = item['Id'] itemid = item['Id']
emby_dbitem = emby_db.getItem_byId(itemid) emby_dbitem = emby_db.getItem_byId(itemid)
try: try:
@ -1001,6 +1024,22 @@ class TVShows(Items):
except TypeError: except TypeError:
update_item = False update_item = False
self.logMsg("showid: %s not found." % itemid, 2) self.logMsg("showid: %s not found." % itemid, 2)
kodicursor.execute("select coalesce(max(idShow),0) from tvshow")
showid = kodicursor.fetchone()[0] + 1
else:
# Verification the item is still in Kodi
query = "SELECT * FROM tvshow WHERE idShow = ?"
kodicursor.execute(query, (showid,))
try:
kodicursor.fetchone()[0]
except TypeError:
# item is not found, let's recreate it.
update_item = False
self.logMsg("showid: %s missing from Kodi, repairing the entry." % showid, 1)
# Force re-add episodes after the show is re-created.
force_episodes = True
if viewtag is None or viewid is None: if viewtag is None or viewid is None:
# Get view tag from emby # Get view tag from emby
@ -1099,8 +1138,6 @@ class TVShows(Items):
pathid = kodi_db.addPath(path) pathid = kodi_db.addPath(path)
# Create the tvshow entry # Create the tvshow entry
kodicursor.execute("select coalesce(max(idShow),0) from tvshow")
showid = kodicursor.fetchone()[0] + 1
query = ( query = (
''' '''
INSERT INTO tvshow( INSERT INTO tvshow(
@ -1154,6 +1191,12 @@ class TVShows(Items):
# Process artwork # Process artwork
artwork.addArtwork(artwork.getAllArtwork(item), seasonid, "season", kodicursor) artwork.addArtwork(artwork.getAllArtwork(item), seasonid, "season", kodicursor)
if force_episodes:
# We needed to recreate the show entry. Re-add episodes now.
self.logMsg("Repairing episodes for showid: %s %s" % (showid, title), 1)
all_episodes = emby.getEpisodesbyShow(itemid)
self.added_episode(all_episodes['Items'], None)
def add_updateSeason(self, item, showid=None): def add_updateSeason(self, item, showid=None):
kodicursor = self.kodicursor kodicursor = self.kodicursor
@ -1214,6 +1257,17 @@ class TVShows(Items):
kodicursor.execute("select coalesce(max(idEpisode),0) from episode") kodicursor.execute("select coalesce(max(idEpisode),0) from episode")
episodeid = kodicursor.fetchone()[0] + 1 episodeid = kodicursor.fetchone()[0] + 1
else:
# Verification the item is still in Kodi
query = "SELECT * FROM episode WHERE idEpisode = ?"
kodicursor.execute(query, (episodeid,))
try:
kodicursor.fetchone()[0]
except TypeError:
# item is not found, let's recreate it.
update_item = False
self.logMsg("episodeid: %s missing from Kodi, repairing the entry." % episodeid, 1)
# fileId information # fileId information
checksum = API.getChecksum() checksum = API.getChecksum()
dateadded = API.getDateCreated() dateadded = API.getDateCreated()