diff --git a/resources/lib/LibrarySync.py b/resources/lib/LibrarySync.py index 71c3d27b..970fafe6 100644 --- a/resources/lib/LibrarySync.py +++ b/resources/lib/LibrarySync.py @@ -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"))) diff --git a/resources/lib/ReadKodiDB.py b/resources/lib/ReadKodiDB.py index 0f7c6677..e5b78a87 100644 --- a/resources/lib/ReadKodiDB.py +++ b/resources/lib/ReadKodiDB.py @@ -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