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'].append(view.get('title'))
for kodimovie in allKodiMovies:
if item["Id"] in kodimovie["file"]:
WriteKodiDB().updateMovieToKodiLibrary(item,kodimovie)
break
kodimovie = allKodiMovies.get(item["Id"], None)
if(kodimovie != None):
WriteKodiDB().updateMovieToKodiLibrary(item,kodimovie)
if(self.ShouldStop()):
return True
@ -541,15 +540,12 @@ class LibrarySync():
for item in allMB3Movies:
if not item.get('IsFolder'):
kodiItem = None
for kodimovie in allKodiMovies:
if item["Id"] in kodimovie["file"]:
kodiItem = kodimovie
break
if not item.get('IsFolder'):
kodiItem = allKodiMovies.get(item["Id"], None)
userData=API().getUserData(item)
userData = API().getUserData(item)
timeInfo = API().getTimeInfo(item)
if kodiItem != None:
WriteKodiDB().updateProperty(kodiItem,"playcount",int(userData.get("PlayCount")),"movie")
kodiresume = int(round(kodiItem['resume'].get("position")))

View file

@ -49,26 +49,32 @@ class ReadKodiDB():
if(result.has_key('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):
# returns a list of movieIds or MB3 Id's from all movies currently in the Kodi library
allKodiMovies = self.getKodiMovies(False)
allKodiMovieIds = list()
if allKodiMovies != None:
for kodimovie in allKodiMovies:
if returnMB3Ids:
filepath = kodimovie["file"]
filepath = filepath.replace(movieLibrary + os.sep, "")
filepath = filepath.replace(".strm", "")
filepath = filepath.split(os.sep)[0]
id = filepath
else:
id = str(kodimovie["movieid"])
if(allKodiMovies == None):
return list()
if(returnMB3Ids):
allKodiMovieIds = list(allKodiMovies.keys())
return allKodiMovieIds
else:
allKodiMovieIds = list()
for kodimovie in allKodiMovies.values():
id = str(kodimovie["movieid"])
allKodiMovieIds.append(id)
return allKodiMovieIds
return allKodiMovieIds
def getKodiTvShowsIds(self,returnMB3Ids = False):
# returns a list of tvshowIds or MB3 Id's from all tvshows currently in the Kodi library