add xbmcgui.DialogProgressBG() to display current sync progress

This commit is contained in:
faush01 2015-03-16 13:32:45 +11:00
parent f0fb4e3c96
commit f587905d91
2 changed files with 218 additions and 131 deletions

View file

@ -35,6 +35,14 @@ class LibrarySync():
WINDOW = xbmcgui.Window( 10000 )
WINDOW.setProperty("librarysync", "busy")
pDialog = None
try:
pDialog = xbmcgui.DialogProgressBG()
if(pDialog != None):
pDialog.create('Sync DB', 'Sync DB')
updateNeeded = False
#process full movies sync
@ -44,15 +52,29 @@ class LibrarySync():
if(movieData == None):
return False
if(pDialog != None):
pDialog.update(0, "Sync DB : Processing Movies")
total = len(movieData) + 1
count = 1
for item in movieData:
if not item.get('IsFolder'):
kodiItem = self.getKodiMovie(item["Id"])
allMovies.append(item["Id"])
progMessage = "Processing"
if kodiItem == None:
self.addMovieToKodiLibrary(item)
updateNeeded = True
progMessage = "Adding"
else:
self.updateMovieToKodiLibrary(item, kodiItem)
progMessage = "Updating"
# update progress bar
if(pDialog != None):
percentage = int(((float(count) / float(total)) * 100))
pDialog.update(percentage, message=progMessage + " Movie: " + str(count))
count += 1
#process full tv shows sync
allTVShows = list()
@ -61,15 +83,30 @@ class LibrarySync():
if (tvShowData == None):
return
if(pDialog != None):
pDialog.update(0, "Sync DB : Processing TV Shows")
total = len(tvShowData) + 1
count = 0
for item in tvShowData:
if item.get('IsFolder'):
kodiItem = self.getKodiTVShow(item["Id"])
allTVShows.append(item["Id"])
progMessage = "Processing"
if kodiItem == None:
self.addTVShowToKodiLibrary(item)
updateNeeded = True
progMessage = "Adding"
else:
self.updateTVShowToKodiLibrary(item, kodiItem)
progMessage = "Updating"
# update progress bar
if(pDialog != None):
percentage = int(((float(count) / float(total)) * 100))
pDialog.update(percentage, message=progMessage + " Tv Show: " + str(count))
count += 1
#process episodes (will only be possible when tv show is scanned to library)
@ -81,11 +118,17 @@ class LibrarySync():
episodeData = self.getEpisodes(tvshow,True)
kodiEpisodes = self.getKodiEpisodes(tvshow)
if(pDialog != None):
pDialog.update(0, "Sync DB : Processing Episodes")
total = len(episodeData) + 1
count = 0
#we have to compare the lists somehow
for item in episodeData:
xbmc.sleep(150) # sleep to not overload system --> can this be replaced by moving the sync to a different thread ?
#xbmc.sleep(150) # sleep to not overload system --> can this be replaced by moving the sync to a different thread ?
comparestring1 = str(item.get("ParentIndexNumber")) + "-" + str(item.get("IndexNumber"))
matchFound = False
progMessage = "Processing"
if kodiEpisodes != None:
for KodiItem in kodiEpisodes:
@ -95,16 +138,26 @@ class LibrarySync():
#match found - update episode
self.updateEpisodeToKodiLibrary(item,KodiItem,tvshow)
matchFound = True
progMessage = "Updating"
if not matchFound:
#no match so we have to create it
print "episode not found...creating it: "
self.addEpisodeToKodiLibrary(item,tvshow)
updateNeeded = True
progMessage = "Adding"
# update progress bar
if(pDialog != None):
percentage = int(((float(count) / float(total)) * 100))
pDialog.update(percentage, message=progMessage + " Episode: " + str(count))
count += 1
# process deletes
# TODO --> process deletes for episodes !!!
if(pDialog != None):
pDialog.update(0, message="Removing Deleted Items")
cleanNeeded = False
allLocaldirs, filesMovies = xbmcvfs.listdir(movieLibrary)
allMB3Movies = set(allMovies)
@ -126,7 +179,10 @@ class LibrarySync():
if updateNeeded:
xbmc.executebuiltin("UpdateLibrary(video)")
finally:
WINDOW.clearProperty("librarysync")
if(pDialog != None):
pDialog.close()
return True
@ -135,12 +191,24 @@ class LibrarySync():
WINDOW = xbmcgui.Window( 10000 )
WINDOW.setProperty("librarysync", "busy")
pDialog = None
try:
pDialog = xbmcgui.DialogProgressBG()
if(pDialog != None):
pDialog.create('Sync PlayCounts', 'Sync PlayCounts')
#process movies
movieData = self.getMovies(False)
if(movieData == None):
return False
if(pDialog != None):
pDialog.update(0, "Sync PlayCounts: Processing Movies")
totalCount = len(movieData) + 1
count = 1
for item in movieData:
if not item.get('IsFolder'):
kodiItem = self.getKodiMovie(item["Id"])
@ -156,17 +224,26 @@ class LibrarySync():
if kodiresume != resume:
self.setKodiResumePoint(kodiItem['movieid'],resume,total,"movie")
# update progress bar
if(pDialog != None):
percentage = int(((float(count) / float(totalCount)) * 100))
pDialog.update(percentage, message="Updating Movie: " + str(count))
count += 1
#process Tv shows
tvshowData = self.getTVShows(False)
if (tvshowData == None):
return False
if(pDialog != None):
pDialog.update(0, "Sync PlayCounts: Processing Episodes")
totalCount = len(movieData) + 1
count = 1
for item in tvshowData:
episodeData = self.getEpisodes(item["Id"], False)
if (episodeData == None):
return False
if (episodeData != None):
for episode in episodeData:
kodiItem = self.getKodiEpisodeByMbItem(episode)
userData=API().getUserData(episode)
@ -181,8 +258,16 @@ class LibrarySync():
if kodiresume != resume:
self.setKodiResumePoint(kodiItem['episodeid'],resume,total,"episode")
# update progress bar
if(pDialog != None):
percentage = int(((float(count) / float(totalCount)) * 100))
pDialog.update(percentage, message="Updating Episode: " + str(count))
count += 1
finally:
WINDOW.clearProperty("librarysync")
if(pDialog != None):
pDialog.close()
return True

View file

@ -84,8 +84,9 @@ class Service():
#full sync
if(cur_seconds_fullsync >= interval_FullSync):
xbmc.log("Doing_Db_Sync: syncDatabase")
xbmc.log("Doing_Db_Sync: syncDatabase (Started)")
worked = librarySync.syncDatabase()
xbmc.log("Doing_Db_Sync: syncDatabase (Finished) " + str(worked))
if(worked):
cur_seconds_fullsync = 0
else:
@ -95,8 +96,9 @@ class Service():
#incremental sync
if(cur_seconds_incrsync >= interval_IncrementalSync):
xbmc.log("Doing_Db_Sync: updatePlayCounts")
xbmc.log("Doing_Db_Sync: updatePlayCounts (Started)")
worked = librarySync.updatePlayCounts()
xbmc.log("Doing_Db_Sync: updatePlayCounts (Finished) " + str(worked))
if(worked):
cur_seconds_incrsync = 0
else: