use a map for movie to make to lookup easier and faster

This commit is contained in:
faush01 2015-03-20 14:04:54 +11:00
parent d1aabaf803
commit 5dd145a8e8
2 changed files with 26 additions and 24 deletions

View file

@ -159,10 +159,9 @@ class LibrarySync():
item['Tag'] = [] item['Tag'] = []
item['Tag'].append(view.get('title')) item['Tag'].append(view.get('title'))
for kodimovie in allKodiMovies: kodimovie = allKodiMovies.get(item["Id"], None)
if item["Id"] in kodimovie["file"]: if(kodimovie != None):
WriteKodiDB().updateMovieToKodiLibrary(item,kodimovie) WriteKodiDB().updateMovieToKodiLibrary(item,kodimovie)
break
if(self.ShouldStop()): if(self.ShouldStop()):
return True return True
@ -542,14 +541,11 @@ class LibrarySync():
for item in allMB3Movies: for item in allMB3Movies:
if not item.get('IsFolder'): if not item.get('IsFolder'):
kodiItem = None kodiItem = allKodiMovies.get(item["Id"], None)
for kodimovie in allKodiMovies:
if item["Id"] in kodimovie["file"]:
kodiItem = kodimovie
break
userData=API().getUserData(item) userData = API().getUserData(item)
timeInfo = API().getTimeInfo(item) timeInfo = API().getTimeInfo(item)
if kodiItem != None: if kodiItem != None:
WriteKodiDB().updateProperty(kodiItem,"playcount",int(userData.get("PlayCount")),"movie") WriteKodiDB().updateProperty(kodiItem,"playcount",int(userData.get("PlayCount")),"movie")
kodiresume = int(round(kodiItem['resume'].get("position"))) kodiresume = int(round(kodiItem['resume'].get("position")))

View file

@ -49,22 +49,28 @@ class ReadKodiDB():
if(result.has_key('movies')): if(result.has_key('movies')):
movies = result['movies'] movies = result['movies']
return movies kodiMovieMap = None
if(movies != None and len(movies) > 0):
kodiMovieMap = {}
for kodimovie in movies:
key = kodimovie["file"][-37:-5] #extract the id from the file name
kodiMovieMap[key] = kodimovie
return kodiMovieMap
def getKodiMoviesIds(self,returnMB3Ids = False): def getKodiMoviesIds(self,returnMB3Ids = False):
# returns a list of movieIds or MB3 Id's from all movies currently in the Kodi library # returns a list of movieIds or MB3 Id's from all movies currently in the Kodi library
allKodiMovies = self.getKodiMovies(False) allKodiMovies = self.getKodiMovies(False)
allKodiMovieIds = list()
if allKodiMovies != None: if(allKodiMovies == None):
for kodimovie in allKodiMovies: return list()
if returnMB3Ids:
filepath = kodimovie["file"] if(returnMB3Ids):
filepath = filepath.replace(movieLibrary + os.sep, "") allKodiMovieIds = list(allKodiMovies.keys())
filepath = filepath.replace(".strm", "") return allKodiMovieIds
filepath = filepath.split(os.sep)[0]
id = filepath
else: else:
allKodiMovieIds = list()
for kodimovie in allKodiMovies.values():
id = str(kodimovie["movieid"]) id = str(kodimovie["movieid"])
allKodiMovieIds.append(id) allKodiMovieIds.append(id)