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:
matchFound = True
break
KodiItem = kodiEpisodes.get(comparestring1, None)
if(KodiItem != None):
matchFound = True
if not matchFound:
#no match so we have to create it
@ -287,12 +285,9 @@ 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
WriteKodiDB().updateEpisodeToKodiLibrary(episode,KodiItem)
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)
matchFound = True
break
KodiItem = kodiEpisodes.get(comparestring1, None)
if(KodiItem != None):
matchFound = True
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
WriteKodiDB().updateEpisodeToKodiLibrary(item,KodiItem)
break
KodiItem = kodiEpisodes.get(comparestring1, None)
if(KodiItem != None):
WriteKodiDB().updateEpisodeToKodiLibrary(item, KodiItem)
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

@ -120,7 +120,7 @@ class ReadKodiDB():
tvshow = tvshows[0]
return tvshow
def getKodiEpisodes(self, id,fullInfo = True):
def getKodiEpisodes(self, id, fullInfo = True):
xbmc.sleep(sleepVal)
episodes = None
json_response = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetTVShows", "params": { "filter": {"operator": "contains", "field": "path", "value": "' + id + '"}, "properties": ["title", "file"], "sort": { "order": "ascending", "method": "label", "ignorearticle": true } }, "id": "libTvShows"}')
@ -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)