use uniqueid to check of en episode is already in the DB

This commit is contained in:
shaun 2015-04-05 09:32:42 +10:00
parent 9ce5bbf27a
commit 85482119a0
3 changed files with 19 additions and 43 deletions

View file

@ -436,16 +436,6 @@ class LibrarySync():
for tvshow in viewTVShows: for tvshow in viewTVShows:
episodeData = ReadEmbyDB().getEpisodes(tvshow,True) episodeData = ReadEmbyDB().getEpisodes(tvshow,True)
allKodiTVShows = ReadKodiDB().getKodiTvShows(False)
if allKodiTVShows != None:
kodishow = allKodiTVShows.get(tvshow,None)
if kodishow != None:
kodiEpisodes = ReadKodiDB().getKodiEpisodes(kodishow["tvshowid"],True,True)
else:
kodiEpisodes = None
else:
kodiEpisodes = None
if episodeData != None: if episodeData != None:
if(self.ShouldStop(pDialog)): if(self.ShouldStop(pDialog)):
@ -457,31 +447,10 @@ class LibrarySync():
total = len(episodeData) + 1 total = len(episodeData) + 1
count = 0 count = 0
#we have to compare the lists somehow
# TODO --> instead of matching by season and episode number we can use the uniqueid
for item in episodeData: for item in episodeData:
if(installFirstRun): #if(installFirstRun):
progressAction = "Adding" progressAction = "Adding"
WriteKodiDB().addEpisodeToKodiLibrary(item, connection, cursor) WriteKodiDB().addEpisodeToKodiLibrary(item, connection, cursor)
else:
comparestring1 = str(item.get("ParentIndexNumber")) + "-" + str(item.get("IndexNumber"))
matchFound = False
if kodiEpisodes != None:
KodiItem = kodiEpisodes.get(comparestring1, None)
if(KodiItem != None):
matchFound = True
progressAction = "Checking"
if not matchFound:
#double check the item it might me added delayed by the Kodi scanner
if ReadKodiDB().getKodiEpisodeByMbItem(item["Id"],tvshow) == None:
#no match so we have to create it
WriteKodiDB().addEpisodeToKodiLibrary(item,connection, cursor)
progressAction = "Adding"
totalItemsAdded += 1
if(self.ShouldStop(pDialog)):
return False
# update progress bar # update progress bar
if(pDialog != None): if(pDialog != None):

View file

@ -210,7 +210,7 @@ class WebSocketThread(threading.Thread):
connection = utils.KodiSQL() connection = utils.KodiSQL()
cursor = connection.cursor() cursor = connection.cursor()
LibrarySync().MoviesSync(connection, cursor, fullsync = False, installFirstRun = False, itemList = itemsToUpdate) LibrarySync().MoviesSync(connection, cursor, fullsync = False, installFirstRun = False, itemList = itemsToUpdate)
LibrarySync().TvShowsSync(connection, cursor,fullsync = False, installFirstRun = False, itemList = itemsToUpdate) LibrarySync().TvShowsSync(connection, cursor, fullsync = False, installFirstRun = False, itemList = itemsToUpdate)
cursor.close() cursor.close()
def on_error(self, ws, error): def on_error(self, ws, error):

View file

@ -844,12 +844,19 @@ class WriteKodiDB():
#adds a Episode to Kodi by directly inserting it to the DB while there is no addEpisode available on the json API #adds a Episode to Kodi by directly inserting it to the DB while there is no addEpisode available on the json API
#TODO: PR at Kodi team for a addEpisode endpoint on their API #TODO: PR at Kodi team for a addEpisode endpoint on their API
# first check the episode is not already in the DB using the Emby ID which is stored in c20
cursor.execute("SELECT idEpisode FROM episode WHERE c20 = ?",(MBitem["Id"],))
result = cursor.fetchone()
if result != None:
utils.logMsg("Emby", "TV Show already exists in DB : " + MBitem["Id"] + " - " + MBitem["Name"])
return
addon = xbmcaddon.Addon(id='plugin.video.emby') addon = xbmcaddon.Addon(id='plugin.video.emby')
port = addon.getSetting('port') port = addon.getSetting('port')
host = addon.getSetting('ipaddress') host = addon.getSetting('ipaddress')
server = host + ":" + port server = host + ":" + port
downloadUtils = DownloadUtils() #downloadUtils = DownloadUtils()
userid = downloadUtils.getUserId() #userid = downloadUtils.getUserId()
timeInfo = API().getTimeInfo(MBitem) timeInfo = API().getTimeInfo(MBitem)
userData=API().getUserData(MBitem) userData=API().getUserData(MBitem)
@ -943,9 +950,9 @@ class WriteKodiDB():
try: try:
connection.commit() connection.commit()
utils.logMsg("Emby","Added TV Show to Kodi Library",MBitem["Id"] + " - " + MBitem["Name"]) utils.logMsg("Emby","Added TV Show to Kodi Library" + MBitem["Id"] + " - " + MBitem["Name"])
except: except:
utils.logMsg("Emby","Error adding tvshow to Kodi Library",MBitem["Id"] + " - " + MBitem["Name"]) utils.logMsg("Emby","Error adding tvshow to Kodi Library" + MBitem["Id"] + " - " + MBitem["Name"])
actionPerformed = False actionPerformed = False
def deleteMovieFromKodiLibrary(self, id ): def deleteMovieFromKodiLibrary(self, id ):
@ -1097,7 +1104,7 @@ class WriteKodiDB():
cursor.execute("INSERT into art(media_id, media_type, type, url) values(?, ?, ?, ?)", (seasonid,"season","banner",API().getArtwork(season, "Banner"))) cursor.execute("INSERT into art(media_id, media_type, type, url) values(?, ?, ?, ?)", (seasonid,"season","banner",API().getArtwork(season, "Banner")))
connection.commit() connection.commit()
#cursor.close() #cursor.close()
def setKodiResumePoint(self, id, resume_seconds, total_seconds, fileType): def setKodiResumePoint(self, id, resume_seconds, total_seconds, fileType):
#use sqlite to set the resume point while json api doesn't support this yet #use sqlite to set the resume point while json api doesn't support this yet
@ -1286,7 +1293,7 @@ class WriteKodiDB():
cursor.execute(peoplesql, (actorid,id,Role,None)) cursor.execute(peoplesql, (actorid,id,Role,None))
connection.commit() connection.commit()
#cursor.close() #cursor.close()
return True return True