From deb0fa57c1930d4771d0a775f7334f7118d646cb Mon Sep 17 00:00:00 2001 From: Marcel van der Veldt Date: Wed, 18 Mar 2015 18:43:57 +0100 Subject: [PATCH] incremental episodes sync and new settings --- resources/lib/LibrarySync.py | 66 ++++++++++++++++++++++++++++-------- resources/lib/ReadEmbyDB.py | 4 +-- resources/lib/ReadKodiDB.py | 6 ++-- 3 files changed, 57 insertions(+), 19 deletions(-) diff --git a/resources/lib/LibrarySync.py b/resources/lib/LibrarySync.py index c866c4a3..3bfbf9c6 100644 --- a/resources/lib/LibrarySync.py +++ b/resources/lib/LibrarySync.py @@ -214,22 +214,23 @@ class LibrarySync(): # incremental sync --> new episodes only if not fullsync: - latestMBEpisodes = ReadEmbyDB().getTVShows(True,True) - allKodiTvShowsIds = set(ReadKodiDB().getKodiTvShowsIds()) - + latestMBEpisodes = ReadEmbyDB().getLatestEpisodes(True) + allKodiTvShowsIds = set(ReadKodiDB().getKodiTvShowsIds(True)) + + updateNeeded = False + + # process new episodes for tvshow in latestMBEpisodes: - - if tvshow["ParentId"] in allKodiTvShowsIds: + if tvshow["SeriesId"] in allKodiTvShowsIds: #only process tvshows that already exist in the db at incremental updates - - kodiEpisodes = ReadKodiDB().getKodiEpisodes(tvshow["ParentId"]) + kodiEpisodes = ReadKodiDB().getKodiEpisodes(tvshow["SeriesId"]) if(self.ShouldStop()): return True if(pDialog != None): pDialog.update(0, "Sync DB : Processing Episodes") - total = len(episodeData) + 1 + total = len(latestMBEpisodes) + 1 count = 0 #we have to compare the lists somehow @@ -240,30 +241,67 @@ class LibrarySync(): 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(tvshow,KodiItem,tvshow) matchFound = True - progMessage = "Updating" if not matchFound: #no match so we have to create it - print "episode not found...creating it: " WriteKodiDB().addEpisodeToKodiLibrary(tvshow,tvshow) updateNeeded = True progMessage = "Adding" if(self.ShouldStop()): return True - + # update progress bar if(pDialog != None): percentage = int(((float(count) / float(total)) * 100)) pDialog.update(percentage, message=progMessage + " Episode: " + str(count)) count += 1 + #initiate library update and wait for finish before processing any updates + if updateNeeded: + self.doKodiLibraryUpdate() + updateNeeded = False + + #process updates + for tvshow in latestMBEpisodes: + if tvshow["SeriesId"] in allKodiTvShowsIds: + #only process tvshows that already exist in the db at incremental updates + kodiEpisodes = ReadKodiDB().getKodiEpisodes(tvshow["SeriesId"]) + + if(self.ShouldStop()): + return True + + if(pDialog != None): + pDialog.update(0, "Sync DB : Processing Episodes") + total = len(latestMBEpisodes) + 1 + count = 0 + + #we have to compare the lists somehow + xbmc.sleep(sleepVal) + comparestring1 = str(tvshow.get("ParentIndexNumber")) + "-" + str(tvshow.get("IndexNumber")) + progMessage = "Processing" + if kodiEpisodes != None: + for KodiItem in kodiEpisodes: + comparestring2 = str(KodiItem["season"]) + "-" + str(KodiItem["episode"]) + if comparestring1 == comparestring2: + #match found - update episode + + progMessage = "Updating" + + if(self.ShouldStop()): + return True + + + # update progress bar + if(pDialog != None): + percentage = int(((float(count) / float(total)) * 100)) + pDialog.update(percentage, message=progMessage + " Episode: " + str(count)) + count += 1 + + # full sync --> Tv shows and Episodes if fullsync: allTVShows = list() diff --git a/resources/lib/ReadEmbyDB.py b/resources/lib/ReadEmbyDB.py index 311af485..c92c3d30 100644 --- a/resources/lib/ReadEmbyDB.py +++ b/resources/lib/ReadEmbyDB.py @@ -107,9 +107,9 @@ class ReadEmbyDB(): userid = downloadUtils.getUserId() if fullinfo: - url = server + '/mediabrowser/Users/' + userid + '/Items?Limit=20&SortBy=DateCreated&IsVirtualUnaired=false&IsMissing=False&Fields=Path,Genres,SortName,Studios,Writer,ProductionYear,Taglines,CommunityRating,OfficialRating,CumulativeRunTimeTicks,Metascore,AirTime,DateCreated,MediaStreams,People,Overview&Recursive=true&SortOrder=Descending&IncludeItemTypes=Episode&format=json&ImageTypeLimit=1' + url = server + '/mediabrowser/Users/' + userid + '/Items?Limit=20&SortBy=DateCreated&IsVirtualUnaired=false&IsMissing=False&Fields=ParentId,Path,Genres,SortName,Studios,Writer,ProductionYear,Taglines,CommunityRating,OfficialRating,CumulativeRunTimeTicks,Metascore,AirTime,DateCreated,MediaStreams,People,Overview&Recursive=true&SortOrder=Descending&IncludeItemTypes=Episode&format=json&ImageTypeLimit=1' else: - url = server + '/mediabrowser/Users/' + userid + '/Items?Limit=20&SortBy=DateCreated&IsVirtualUnaired=false&IsMissing=False&Fields=Name,SortName,CumulativeRunTimeTicks&Recursive=true&SortOrder=Descending&IncludeItemTypes=Episode&format=json&ImageTypeLimit=1' + url = server + '/mediabrowser/Users/' + userid + '/Items?Limit=20&SortBy=DateCreated&IsVirtualUnaired=false&IsMissing=False&Fields=ParentId,Name,SortName,CumulativeRunTimeTicks&Recursive=true&SortOrder=Descending&IncludeItemTypes=Episode&format=json&ImageTypeLimit=1' jsonData = downloadUtils.downloadUrl(url, suppress=True, popup=0) diff --git a/resources/lib/ReadKodiDB.py b/resources/lib/ReadKodiDB.py index 83211b01..c175e2d7 100644 --- a/resources/lib/ReadKodiDB.py +++ b/resources/lib/ReadKodiDB.py @@ -79,7 +79,7 @@ class ReadKodiDB(): filepath = filepath.split(os.sep)[0] id = filepath else: - id = str(kodimovie["movieid"]) + id = str(kodishow["tvshowid"]) allKodiTvShowsIds.append(id) return allKodiTvShowsIds @@ -94,11 +94,11 @@ class ReadKodiDB(): json_response = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetTVShows", "params": { "filter": {"operator": "contains", "field": "path", "value": "plugin.video.mb3sync"}, "properties": ["sorttitle", "title", "playcount", "file"], "sort": { "order": "ascending", "method": "label", "ignorearticle": true } }, "id": "libTvShows"}') jsonobject = json.loads(json_response.decode('utf-8','replace')) tvshows = None - + if(jsonobject.has_key('result')): result = jsonobject['result'] if(result.has_key('tvshows')): - movies = result['tvshows'] + tvshows = result['tvshows'] return tvshows