From 53fb4a9207de1fcdfbaa7dd240e02d75a2b59b7a Mon Sep 17 00:00:00 2001 From: Marcel van der Veldt Date: Wed, 18 Mar 2015 22:38:02 +0100 Subject: [PATCH] small changes --- resources/lib/LibrarySync.py | 167 ++++++++++++++++++----------------- 1 file changed, 85 insertions(+), 82 deletions(-) diff --git a/resources/lib/LibrarySync.py b/resources/lib/LibrarySync.py index 299bafaf..5b0a4211 100644 --- a/resources/lib/LibrarySync.py +++ b/resources/lib/LibrarySync.py @@ -218,93 +218,96 @@ class LibrarySync(): # incremental sync --> new episodes only if not fullsync: + latestMBEpisodes = ReadEmbyDB().getLatestEpisodes(True) - allKodiTvShowsIds = set(ReadKodiDB().getKodiTvShowsIds(True)) - updateNeeded = False - - # process new episodes - for tvshow in latestMBEpisodes: - if tvshow["SeriesId"] in allKodiTvShowsIds: - #only process tvshows that already exist in the db at incremental updates - kodiEpisodes = ReadKodiDB().getKodiEpisodes(tvshow["SeriesId"]) - - if(self.ShouldStop()): - return True - - if(pDialog != None): - pDialog.update(0, "Sync DB : Processing Episodes") - total = len(latestMBEpisodes) + 1 - count = 0 - - #we have to compare the lists somehow - xbmc.sleep(sleepVal) - comparestring1 = str(tvshow.get("ParentIndexNumber")) + "-" + str(tvshow.get("IndexNumber")) - matchFound = False - progMessage = "Processing" - if kodiEpisodes != None: - for KodiItem in kodiEpisodes: - - comparestring2 = str(KodiItem["season"]) + "-" + str(KodiItem["episode"]) - if comparestring1 == comparestring2: - matchFound = True - - if not matchFound: - #no match so we have to create it - WriteKodiDB().addEpisodeToKodiLibrary(tvshow,tvshow) - updateNeeded = True - progMessage = "Adding" - - if(self.ShouldStop()): - return True - - # update progress bar - if(pDialog != None): - percentage = int(((float(count) / float(total)) * 100)) - pDialog.update(percentage, message=progMessage + " Episode: " + str(count)) - count += 1 - - #initiate library update and wait for finish before processing any updates - if updateNeeded: - self.doKodiLibraryUpdate() + if latestMBEpisodes != None: + allKodiTvShowsIds = set(ReadKodiDB().getKodiTvShowsIds(True)) + updateNeeded = False - - #process updates - for tvshow in latestMBEpisodes: - if tvshow["SeriesId"] in allKodiTvShowsIds: - #only process tvshows that already exist in the db at incremental updates - kodiEpisodes = ReadKodiDB().getKodiEpisodes(tvshow["SeriesId"]) - - if(self.ShouldStop()): - return True - - if(pDialog != None): - pDialog.update(0, "Sync DB : Processing Episodes") - total = len(latestMBEpisodes) + 1 - count = 0 - - #we have to compare the lists somehow - xbmc.sleep(sleepVal) - comparestring1 = str(tvshow.get("ParentIndexNumber")) + "-" + str(tvshow.get("IndexNumber")) - progMessage = "Processing" - if kodiEpisodes != None: - for KodiItem in kodiEpisodes: - comparestring2 = str(KodiItem["season"]) + "-" + str(KodiItem["episode"]) - if comparestring1 == comparestring2: - #match found - update episode - - progMessage = "Updating" + + # process new episodes + for tvshow in latestMBEpisodes: + if tvshow["SeriesId"] in allKodiTvShowsIds: + #only process tvshows that already exist in the db at incremental updates + kodiEpisodes = ReadKodiDB().getKodiEpisodes(tvshow["SeriesId"]) - if(self.ShouldStop()): - return True - + if(self.ShouldStop()): + return True + + if(pDialog != None): + pDialog.update(0, "Sync DB : Processing Episodes") + total = len(latestMBEpisodes) + 1 + count = 0 - # update progress bar - if(pDialog != None): - percentage = int(((float(count) / float(total)) * 100)) - pDialog.update(percentage, message=progMessage + " Episode: " + str(count)) - count += 1 - + #we have to compare the lists somehow + xbmc.sleep(sleepVal) + comparestring1 = str(tvshow.get("ParentIndexNumber")) + "-" + str(tvshow.get("IndexNumber")) + matchFound = False + progMessage = "Processing" + if kodiEpisodes != None: + for KodiItem in kodiEpisodes: + + comparestring2 = str(KodiItem["season"]) + "-" + str(KodiItem["episode"]) + if comparestring1 == comparestring2: + matchFound = True + + if not matchFound: + #no match so we have to create it + WriteKodiDB().addEpisodeToKodiLibrary(tvshow,tvshow) + updateNeeded = True + progMessage = "Adding" + + if(self.ShouldStop()): + return True + + # update progress bar + if(pDialog != None): + percentage = int(((float(count) / float(total)) * 100)) + pDialog.update(percentage, message=progMessage + " Episode: " + str(count)) + count += 1 + + #initiate library update and wait for finish before processing any updates + if updateNeeded: + self.doKodiLibraryUpdate() + updateNeeded = False + + #process updates + for tvshow in latestMBEpisodes: + if tvshow["SeriesId"] in allKodiTvShowsIds: + #only process tvshows that already exist in the db at incremental updates + kodiEpisodes = ReadKodiDB().getKodiEpisodes(tvshow["SeriesId"]) + + if(self.ShouldStop()): + return True + + if(pDialog != None): + pDialog.update(0, "Sync DB : Processing Episodes") + total = len(latestMBEpisodes) + 1 + count = 0 + + #we have to compare the lists somehow + xbmc.sleep(sleepVal) + comparestring1 = str(tvshow.get("ParentIndexNumber")) + "-" + str(tvshow.get("IndexNumber")) + progMessage = "Processing" + if kodiEpisodes != None: + for KodiItem in kodiEpisodes: + comparestring2 = str(KodiItem["season"]) + "-" + str(KodiItem["episode"]) + if comparestring1 == comparestring2: + #match found - update episode + + progMessage = "Updating" + + if(self.ShouldStop()): + return True + + + # update progress bar + if(pDialog != None): + percentage = int(((float(count) / float(total)) * 100)) + pDialog.update(percentage, message=progMessage + " Episode: " + str(count)) + count += 1 + # full sync --> Tv shows and Episodes if fullsync: