From 593d9696696463be2395e596a535279f2c7d0152 Mon Sep 17 00:00:00 2001 From: Marcel van der Veldt Date: Thu, 19 Mar 2015 10:52:21 +0100 Subject: [PATCH] speed boost playcount sync --- resources/lib/LibrarySync.py | 22 ++++++++++++++++------ resources/lib/ReadKodiDB.py | 10 ++++++---- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/resources/lib/LibrarySync.py b/resources/lib/LibrarySync.py index 5ccdc3bf..c79e7657 100644 --- a/resources/lib/LibrarySync.py +++ b/resources/lib/LibrarySync.py @@ -558,9 +558,8 @@ class LibrarySync(): count = 1 for item in allMB3Movies: - xbmc.sleep(sleepVal) + if not item.get('IsFolder'): - kodiItem = None for kodimovie in allKodiMovies: if item["Id"] in kodimovie["file"]: @@ -571,11 +570,11 @@ class LibrarySync(): timeInfo = API().getTimeInfo(item) if kodiItem != None: WriteKodiDB().updateProperty(kodiItem,"playcount",int(userData.get("PlayCount")),"movie") - kodiresume = int(round(kodiItem['resume'].get("position"))) resume = int(round(float(timeInfo.get("ResumeTime"))))*60 total = int(round(float(timeInfo.get("TotalTime"))))*60 if kodiresume != resume: + xbmc.sleep(sleepVal) print "updating resumepoint for movie " + str(kodiItem['movieid']) WriteKodiDB().setKodiResumePoint(kodiItem['movieid'],resume,total,"movie") @@ -604,8 +603,9 @@ class LibrarySync(): showCurrent = 1 for item in tvshowData: - xbmc.sleep(sleepVal) + episodeData = ReadEmbyDB().getEpisodes(item["Id"], False) + kodiEpisodes = ReadKodiDB().getKodiEpisodes(item["Id"],False) if (episodeData != None): if(pDialog != None): @@ -614,8 +614,17 @@ class LibrarySync(): count = 1 for episode in episodeData: - xbmc.sleep(sleepVal) - kodiItem = ReadKodiDB().getKodiEpisodeByMbItem(episode) + + kodiItem = None + 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 + userData=API().getUserData(episode) timeInfo = API().getTimeInfo(episode) if kodiItem != None: @@ -625,6 +634,7 @@ class LibrarySync(): resume = int(round(float(timeInfo.get("ResumeTime"))))*60 total = int(round(float(timeInfo.get("TotalTime"))))*60 if kodiresume != resume: + xbmc.sleep(sleepVal) WriteKodiDB().setKodiResumePoint(kodiItem['episodeid'],resume,total,"episode") if(self.ShouldStop()): diff --git a/resources/lib/ReadKodiDB.py b/resources/lib/ReadKodiDB.py index c175e2d7..3fa2fc60 100644 --- a/resources/lib/ReadKodiDB.py +++ b/resources/lib/ReadKodiDB.py @@ -113,9 +113,9 @@ class ReadKodiDB(): tvshow = tvshows[0] return tvshow - def getKodiEpisodes(self, id): + def getKodiEpisodes(self, id,fullInfo = True): episodes = None - json_response = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetTVShows", "params": { "filter": {"operator": "contains", "field": "path", "value": "' + id + '"}, "properties": ["sorttitle", "title", "originaltitle", "playcount", "file"], "sort": { "order": "ascending", "method": "label", "ignorearticle": true } }, "id": "libTvShows"}') + 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"}') jsonobject = json.loads(json_response.decode('utf-8','replace')) tvshow = None if(jsonobject.has_key('result')): @@ -123,8 +123,10 @@ class ReadKodiDB(): if(result.has_key('tvshows')): tvshows = result['tvshows'] tvshow = tvshows[0] - - json_response = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetEpisodes", "params": {"tvshowid": %d, "properties": ["title", "playcount", "plot", "season", "episode", "showtitle", "file", "lastplayed", "rating", "resume", "art", "streamdetails", "firstaired", "runtime", "writer", "cast", "dateadded"], "sort": {"method": "episode"}}, "id": 1}' %tvshow['tvshowid']) + if fullInfo: + json_response = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetEpisodes", "params": {"tvshowid": %d, "properties": ["title", "playcount", "plot", "season", "episode", "showtitle", "file", "lastplayed", "rating", "resume", "art", "streamdetails", "firstaired", "runtime", "writer", "cast", "dateadded"], "sort": {"method": "episode"}}, "id": 1}' %tvshow['tvshowid']) + else: + json_response = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetEpisodes", "params": {"tvshowid": %d, "properties": ["title", "playcount", "season", "episode", "lastplayed", "resume"], "sort": {"method": "episode"}}, "id": 1}' %tvshow['tvshowid']) jsonobject = json.loads(json_response.decode('utf-8','replace')) episodes = None if(jsonobject.has_key('result')):