remove some of the for loops searches, use a map for lookups

Do a full sync on all items for playcount
This commit is contained in:
shaun 2015-03-20 00:18:20 +11:00
parent a0099a69db
commit ad1d1d80cc
2 changed files with 25 additions and 35 deletions

View file

@ -244,11 +244,9 @@ class LibrarySync():
comparestring1 = str(episode.get("ParentIndexNumber")) + "-" + str(episode.get("IndexNumber"))
matchFound = False
if kodiEpisodes != None:
for KodiItem in kodiEpisodes:
comparestring2 = str(KodiItem["season"]) + "-" + str(KodiItem["episode"])
if comparestring1 == comparestring2:
KodiItem = kodiEpisodes.get(comparestring1, None)
if(KodiItem != None):
matchFound = True
break
if not matchFound:
#no match so we have to create it
@ -287,13 +285,10 @@ class LibrarySync():
comparestring1 = str(episode.get("ParentIndexNumber")) + "-" + str(episode.get("IndexNumber"))
if kodiEpisodes != None:
for KodiItem in kodiEpisodes:
comparestring2 = str(KodiItem["season"]) + "-" + str(KodiItem["episode"])
if comparestring1 == comparestring2:
#match found - update episode
KodiItem = kodiEpisodes.get(comparestring1, None)
if(KodiItem != None):
WriteKodiDB().updateEpisodeToKodiLibrary(episode, KodiItem)
if(self.ShouldStop()):
return True
@ -385,14 +380,9 @@ class LibrarySync():
comparestring1 = str(item.get("ParentIndexNumber")) + "-" + str(item.get("IndexNumber"))
matchFound = False
if kodiEpisodes != None:
for KodiItem in kodiEpisodes:
allEpisodes.append(KodiItem["episodeid"])
comparestring2 = str(KodiItem["season"]) + "-" + str(KodiItem["episode"])
if comparestring1 == comparestring2:
#match found - update episode
WriteKodiDB().updateEpisodeToKodiLibrary(item,KodiItem)
KodiItem = kodiEpisodes.get(comparestring1, None)
if(KodiItem != None):
matchFound = True
break
if not matchFound:
#no match so we have to create it
@ -442,13 +432,9 @@ class LibrarySync():
comparestring1 = str(item.get("ParentIndexNumber")) + "-" + str(item.get("IndexNumber"))
matchFound = False
if kodiEpisodes != None:
for KodiItem in kodiEpisodes:
allEpisodes.append(KodiItem["episodeid"])
comparestring2 = str(KodiItem["season"]) + "-" + str(KodiItem["episode"])
if comparestring1 == comparestring2:
#match found - update episode
KodiItem = kodiEpisodes.get(comparestring1, None)
if(KodiItem != None):
WriteKodiDB().updateEpisodeToKodiLibrary(item, KodiItem)
break
if(self.ShouldStop()):
return True
@ -530,7 +516,7 @@ class LibrarySync():
viewCount = len(views)
viewCurrent = 1
for view in views:
allMB3Movies = ReadEmbyDB().getMovies(view.get('id'),False)
allMB3Movies = ReadEmbyDB().getMovies(view.get('id'),True)
allKodiMovies = ReadKodiDB().getKodiMovies(False)
if(self.ShouldStop()):
@ -579,7 +565,7 @@ class LibrarySync():
#process Tv shows
if processTvShows:
tvshowData = ReadEmbyDB().getTVShows(False)
tvshowData = ReadEmbyDB().getTVShows(True)
if(self.ShouldStop()):
return True
@ -607,11 +593,7 @@ class LibrarySync():
comparestring1 = str(episode.get("ParentIndexNumber")) + "-" + str(episode.get("IndexNumber"))
matchFound = False
if kodiEpisodes != None:
for KodiEpisode in kodiEpisodes:
comparestring2 = str(KodiEpisode["season"]) + "-" + str(KodiEpisode["episode"])
if comparestring1 == comparestring2:
kodiItem = KodiEpisode
break
kodiItem = kodiEpisodes.get(comparestring1, None)
userData=API().getUserData(episode)
timeInfo = API().getTimeInfo(episode)

View file

@ -141,7 +141,15 @@ class ReadKodiDB():
result = jsonobject['result']
if(result.has_key('episodes')):
episodes = result['episodes']
return episodes
episodeMap = None
if(episodes != None):
episodeMap = {}
for KodiItem in episodes:
key = str(KodiItem["season"]) + "-" + str(KodiItem["episode"])
episodeMap[key] = KodiItem
return episodeMap
def getKodiEpisodeByMbItem(self, MBitem):
xbmc.sleep(sleepVal)