incremental episodes sync and new settings

This commit is contained in:
Marcel van der Veldt 2015-03-18 18:43:57 +01:00
parent 380b934316
commit deb0fa57c1
3 changed files with 57 additions and 19 deletions

View File

@ -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()

View File

@ -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)

View File

@ -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