fixed issue with episode sync

This commit is contained in:
Marcel van der Veldt 2015-05-02 14:57:43 +02:00
parent 6e9983edba
commit a05bdeb844
3 changed files with 15 additions and 6 deletions

View file

@ -174,15 +174,14 @@ class LibrarySync():
if kodiShow == None: if kodiShow == None:
# Tv show doesn't exist in Kodi yet so proceed and add it # 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: else:
kodiId = kodishow[0]
# If there are changes to the item, perform a full sync of the item # If there are changes to the item, perform a full sync of the item
if kodiShow[2] != API().getChecksum(item): if kodiShow[2] != API().getChecksum(item):
WriteKodiDB().addOrUpdateTvShowToKodiLibrary(item["Id"],connection, cursor, view.get('title')) WriteKodiDB().addOrUpdateTvShowToKodiLibrary(item["Id"],connection, cursor, view.get('title'))
#### PROCESS EPISODES ###### #### PROCESS EPISODES ######
self.EpisodesFullSync(connection,cursor,item["Id"], kodiId) self.EpisodesFullSync(connection,cursor,item["Id"])
#### TVSHOW: PROCESS DELETES ##### #### TVSHOW: PROCESS DELETES #####
allEmbyTvShowIds = set(allEmbyTvShowIds) allEmbyTvShowIds = set(allEmbyTvShowIds)
@ -192,14 +191,18 @@ class LibrarySync():
WriteKodiDB().deleteItemFromKodiLibrary(kodiId, connection, cursor) WriteKodiDB().deleteItemFromKodiLibrary(kodiId, connection, cursor)
def EpisodesFullSync(self,connection,cursor,embyShowId, kodiShowId): def EpisodesFullSync(self,connection,cursor,showId):
WINDOW = xbmcgui.Window( 10000 ) WINDOW = xbmcgui.Window( 10000 )
allKodiEpisodeIds = list() allKodiEpisodeIds = list()
allEmbyEpisodeIds = 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) allKodiEpisodes = ReadKodiDB().getKodiEpisodes(connection, cursor, kodiShowId)
for kodiepisode in allKodiEpisodes: for kodiepisode in allKodiEpisodes:
@ -222,6 +225,8 @@ class LibrarySync():
else: else:
# If there are changes to the item, perform a full sync of the item # If there are changes to the item, perform a full sync of the item
if kodiEpisode[2] != API().getChecksum(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) WriteKodiDB().addOrUpdateEpisodeToKodiLibrary(item["Id"], kodiShowId, connection, cursor)
#### EPISODES: PROCESS DELETES ##### #### EPISODES: PROCESS DELETES #####

View file

@ -37,6 +37,7 @@ class ReadKodiDB():
cursor.execute("SELECT kodi_id, emby_id, checksum FROM emby WHERE media_type=?",("episode",)) cursor.execute("SELECT kodi_id, emby_id, checksum FROM emby WHERE media_type=?",("episode",))
else: else:
cursor.execute("SELECT kodi_id, emby_id, checksum FROM emby WHERE media_type=? AND parent_id=?",("episode", showid)) cursor.execute("SELECT kodi_id, emby_id, checksum FROM emby WHERE media_type=? AND parent_id=?",("episode", showid))
allepisodes = cursor.fetchall() allepisodes = cursor.fetchall()
#this will return a list with tuples of all items returned from the database #this will return a list with tuples of all items returned from the database
return allepisodes return allepisodes

View file

@ -333,7 +333,6 @@ class WriteKodiDB():
#commit changes and return the id #commit changes and return the id
connection.commit() connection.commit()
return showid
def addMusicVideoToKodiLibrary( self, MBitem, connection, cursor ): def addMusicVideoToKodiLibrary( self, MBitem, connection, cursor ):
@ -567,6 +566,10 @@ class WriteKodiDB():
if media_type == "musicvideo": if media_type == "musicvideo":
utils.logMsg("deleting musicvideo from Kodi library --> ",id) utils.logMsg("deleting musicvideo from Kodi library --> ",id)
cursor.execute("DELETE FROM musicvideo WHERE idMVideo = ?", (kodi_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() connection.commit()
def updateSeasons(self,embyTvShowId, kodiTvShowId, connection, cursor): def updateSeasons(self,embyTvShowId, kodiTvShowId, connection, cursor):