diff --git a/resources/lib/LibrarySync.py b/resources/lib/LibrarySync.py index 7e356342..c53fdcc3 100644 --- a/resources/lib/LibrarySync.py +++ b/resources/lib/LibrarySync.py @@ -174,15 +174,14 @@ class LibrarySync(): if kodiShow == None: # Tv show doesn't exist in Kodi yet so proceed and add it - kodiId = WriteKodiDB().addOrUpdateTvShowToKodiLibrary(item["Id"],connection, cursor, view.get('title')) + WriteKodiDB().addOrUpdateTvShowToKodiLibrary(item["Id"],connection, cursor, view.get('title')) else: - kodiId = kodishow[0] # If there are changes to the item, perform a full sync of the item if kodiShow[2] != API().getChecksum(item): WriteKodiDB().addOrUpdateTvShowToKodiLibrary(item["Id"],connection, cursor, view.get('title')) #### PROCESS EPISODES ###### - self.EpisodesFullSync(connection,cursor,item["Id"], kodiId) + self.EpisodesFullSync(connection,cursor,item["Id"]) #### TVSHOW: PROCESS DELETES ##### allEmbyTvShowIds = set(allEmbyTvShowIds) @@ -192,14 +191,18 @@ class LibrarySync(): WriteKodiDB().deleteItemFromKodiLibrary(kodiId, connection, cursor) - def EpisodesFullSync(self,connection,cursor,embyShowId, kodiShowId): + def EpisodesFullSync(self,connection,cursor,showId): WINDOW = xbmcgui.Window( 10000 ) allKodiEpisodeIds = list() allEmbyEpisodeIds = list() - allEmbyEpisodes = ReadEmbyDB().getEpisodes(embyShowId) + #get the kodi parent id + cursor.execute("SELECT kodi_id FROM emby WHERE emby_id=?",(showId,)) + kodiShowId = cursor.fetchone()[0] + + allEmbyEpisodes = ReadEmbyDB().getEpisodes(showId) allKodiEpisodes = ReadKodiDB().getKodiEpisodes(connection, cursor, kodiShowId) for kodiepisode in allKodiEpisodes: @@ -222,6 +225,8 @@ class LibrarySync(): else: # If there are changes to the item, perform a full sync of the item if kodiEpisode[2] != API().getChecksum(item): + print "previous checksum--> " + kodiEpisode[2] + print "new checksum--> " + API().getChecksum(item) WriteKodiDB().addOrUpdateEpisodeToKodiLibrary(item["Id"], kodiShowId, connection, cursor) #### EPISODES: PROCESS DELETES ##### diff --git a/resources/lib/ReadKodiDB.py b/resources/lib/ReadKodiDB.py index 9909f4f9..f0fc70ec 100644 --- a/resources/lib/ReadKodiDB.py +++ b/resources/lib/ReadKodiDB.py @@ -37,6 +37,7 @@ class ReadKodiDB(): cursor.execute("SELECT kodi_id, emby_id, checksum FROM emby WHERE media_type=?",("episode",)) else: cursor.execute("SELECT kodi_id, emby_id, checksum FROM emby WHERE media_type=? AND parent_id=?",("episode", showid)) + allepisodes = cursor.fetchall() #this will return a list with tuples of all items returned from the database return allepisodes diff --git a/resources/lib/WriteKodiDB.py b/resources/lib/WriteKodiDB.py index a852b022..7666a4c9 100644 --- a/resources/lib/WriteKodiDB.py +++ b/resources/lib/WriteKodiDB.py @@ -333,7 +333,6 @@ class WriteKodiDB(): #commit changes and return the id connection.commit() - return showid def addMusicVideoToKodiLibrary( self, MBitem, connection, cursor ): @@ -567,6 +566,10 @@ class WriteKodiDB(): if media_type == "musicvideo": utils.logMsg("deleting musicvideo from Kodi library --> ",id) cursor.execute("DELETE FROM musicvideo WHERE idMVideo = ?", (kodi_id,)) + + #delete the record in emby table + cursor.execute("DELETE FROM emby WHERE emby_id = ?", (id,)) + connection.commit() def updateSeasons(self,embyTvShowId, kodiTvShowId, connection, cursor):