This commit is contained in:
Marcel van der Veldt 2015-03-29 22:14:25 +02:00
commit 9fffc9cfcb
1 changed files with 82 additions and 87 deletions

View File

@ -440,10 +440,7 @@ class LibrarySync():
allKodiTVShows = ReadKodiDB().getKodiTvShows(False) allKodiTVShows = ReadKodiDB().getKodiTvShows(False)
if allKodiTVShows != None: if allKodiTVShows != None:
kodishow = allKodiTVShows.get(tvshow,None) kodishow = allKodiTVShows.get(tvshow,None)
if kodishow != None: kodiEpisodes = ReadKodiDB().getKodiEpisodes(kodishow["tvshowid"],True,True)
kodiEpisodes = ReadKodiDB().getKodiEpisodes(kodishow["tvshowid"],True,True)
else:
kodiEpisodes = None
else: else:
kodiEpisodes = None kodiEpisodes = None
@ -533,50 +530,49 @@ class LibrarySync():
for tvshow in allTVShows: for tvshow in allTVShows:
episodeData = ReadEmbyDB().getEpisodes(tvshow,True) episodeData = ReadEmbyDB().getEpisodes(tvshow,True)
kodishow = allKodiTVShows.get(tvshow,None) kodishow = allKodiTVShows.get(tvshow,None)
if kodishow != None: kodiEpisodes = ReadKodiDB().getKodiEpisodes(kodishow["tvshowid"],True,True)
kodiEpisodes = ReadKodiDB().getKodiEpisodes(kodishow["tvshowid"],True,True)
if(self.ShouldStop(pDialog)):
return False
if(pDialog != None):
progressTitle = "Sync DB : Processing Tv Show " + str(showCurrent) + " of " + str(showTotal)
pDialog.update(0, progressTitle)
total = len(episodeData) + 1
count = 0
#we have to compare the lists somehow
for item in episodeData:
#add episodeId to the list of all episodes for use later on the deletes
allMB3EpisodeIds.append(item["Id"])
comparestring1 = str(item.get("ParentIndexNumber")) + "-" + str(item.get("IndexNumber"))
matchFound = False
if kodiEpisodes != None:
KodiItem = kodiEpisodes.get(comparestring1, None)
if(KodiItem != None):
updated = WriteKodiDB().updateEpisodeToKodiLibrary(item, KodiItem)
if(updated):
totalItemsUpdated += 1
if(self.ShouldStop(pDialog)): if(self.ShouldStop(pDialog)):
return False return False
# update progress bar
if(pDialog != None): if(pDialog != None):
progressTitle = "Sync DB : Processing Tv Show " + str(showCurrent) + " of " + str(showTotal) percentage = int(((float(count) / float(total)) * 100))
pDialog.update(0, progressTitle) pDialog.update(percentage, progressTitle, "Updating Episode: " + str(count))
total = len(episodeData) + 1 count += 1
count = 0
#we have to compare the lists somehow #add all kodi episodes to a list with episodes for use later on to delete episodes
for item in episodeData: #the mediabrowser ID is set as uniqueID in the NFO... for some reason this has key 'unknown' in the json response
#add episodeId to the list of all episodes for use later on the deletes show = ReadKodiDB().getKodiEpisodes(kodishow["tvshowid"],False,False)
allMB3EpisodeIds.append(item["Id"]) if show != None:
for episode in show:
comparestring1 = str(item.get("ParentIndexNumber")) + "-" + str(item.get("IndexNumber")) dict = {'episodeid': str(episode["uniqueid"]["unknown"]),'tvshowid': tvshow}
matchFound = False allKodiEpisodeIds.append(dict)
if kodiEpisodes != None:
KodiItem = kodiEpisodes.get(comparestring1, None)
if(KodiItem != None):
updated = WriteKodiDB().updateEpisodeToKodiLibrary(item, KodiItem)
if(updated):
totalItemsUpdated += 1
if(self.ShouldStop(pDialog)):
return False
# update progress bar
if(pDialog != None):
percentage = int(((float(count) / float(total)) * 100))
pDialog.update(percentage, progressTitle, "Updating Episode: " + str(count))
count += 1
#add all kodi episodes to a list with episodes for use later on to delete episodes
#the mediabrowser ID is set as uniqueID in the NFO... for some reason this has key 'unknown' in the json response
show = ReadKodiDB().getKodiEpisodes(kodishow["tvshowid"],False,False)
if show != None:
for episode in show:
dict = {'episodeid': str(episode["uniqueid"]["unknown"]),'tvshowid': tvshow}
allKodiEpisodeIds.append(dict)
showCurrent += 1 showCurrent += 1
@ -895,49 +891,48 @@ class LibrarySync():
episodeData = ReadEmbyDB().getEpisodes(item["Id"], False) episodeData = ReadEmbyDB().getEpisodes(item["Id"], False)
allKodiTVShows = ReadKodiDB().getKodiTvShows(False) allKodiTVShows = ReadKodiDB().getKodiTvShows(False)
kodishow = allKodiTVShows.get(item["Id"],None) kodishow = allKodiTVShows.get(item["Id"],None)
if kodishow != None: kodiEpisodes = ReadKodiDB().getKodiEpisodes(kodishow["tvshowid"],False,True)
kodiEpisodes = ReadKodiDB().getKodiEpisodes(kodishow["tvshowid"],False,True)
if (episodeData != None):
if (episodeData != None): if(pDialog != None):
if(pDialog != None): progressTitle = "Sync PlayCounts: Processing TV Show " + str(showCurrent) + " of " + str(showTotal)
progressTitle = "Sync PlayCounts: Processing TV Show " + str(showCurrent) + " of " + str(showTotal) pDialog.update(0, progressTitle)
pDialog.update(0, progressTitle) totalCount = len(episodeData) + 1
totalCount = len(episodeData) + 1 count = 1
count = 1
for episode in episodeData:
for episode in episodeData:
kodiItem = None
kodiItem = None comparestring1 = str(episode.get("ParentIndexNumber")) + "-" + str(episode.get("IndexNumber"))
comparestring1 = str(episode.get("ParentIndexNumber")) + "-" + str(episode.get("IndexNumber")) matchFound = False
matchFound = False if kodiEpisodes != None:
if kodiEpisodes != None: kodiItem = kodiEpisodes.get(comparestring1, None)
kodiItem = kodiEpisodes.get(comparestring1, None)
userData=API().getUserData(episode)
userData=API().getUserData(episode) timeInfo = API().getTimeInfo(episode)
timeInfo = API().getTimeInfo(episode) if kodiItem != None:
if kodiItem != None: WINDOW = xbmcgui.Window( 10000 )
WINDOW = xbmcgui.Window( 10000 ) WINDOW.setProperty("episodeid" + str(kodiItem['episodeid']), episode.get('Name') + ";;" + episode.get('Id'))
WINDOW.setProperty("episodeid" + str(kodiItem['episodeid']), episode.get('Name') + ";;" + episode.get('Id')) kodiresume = int(round(kodiItem['resume'].get("position")))
kodiresume = int(round(kodiItem['resume'].get("position"))) resume = int(round(float(timeInfo.get("ResumeTime"))))*60
resume = int(round(float(timeInfo.get("ResumeTime"))))*60 total = int(round(float(timeInfo.get("TotalTime"))))*60
total = int(round(float(timeInfo.get("TotalTime"))))*60 if kodiresume != resume:
if kodiresume != resume: WriteKodiDB().setKodiResumePoint(kodiItem['episodeid'],resume,total,"episode")
WriteKodiDB().setKodiResumePoint(kodiItem['episodeid'],resume,total,"episode") totalPositionsUpdated += 1
totalPositionsUpdated += 1
updated = WriteKodiDB().updateProperty(kodiItem,"playcount",int(userData.get("PlayCount")),"episode")
updated = WriteKodiDB().updateProperty(kodiItem,"playcount",int(userData.get("PlayCount")),"episode") updated |= WriteKodiDB().updateProperty(kodiItem,"lastplayed",userData.get("LastPlayedDate"), "episode")
updated |= WriteKodiDB().updateProperty(kodiItem,"lastplayed",userData.get("LastPlayedDate"), "episode") if(updated):
if(updated): totalCountsUpdated += 1
totalCountsUpdated += 1 if(self.ShouldStop(pDialog)):
if(self.ShouldStop(pDialog)): return False
return False
# update progress bar
if(pDialog != None):
percentage = int(((float(count) / float(totalCount)) * 100))
pDialog.update(percentage, progressTitle, "Updating Episode: " + str(count))
count += 1
# update progress bar
if(pDialog != None):
percentage = int(((float(count) / float(totalCount)) * 100))
pDialog.update(percentage, progressTitle, "Updating Episode: " + str(count))
count += 1
showCurrent += 1 showCurrent += 1
if(playCountSyncFirstRun != "true"): if(playCountSyncFirstRun != "true"):