add xbmcgui.DialogProgressBG() to display current sync progress
This commit is contained in:
parent
f0fb4e3c96
commit
f587905d91
2 changed files with 218 additions and 131 deletions
|
@ -34,99 +34,155 @@ class LibrarySync():
|
||||||
def syncDatabase(self):
|
def syncDatabase(self):
|
||||||
|
|
||||||
WINDOW = xbmcgui.Window( 10000 )
|
WINDOW = xbmcgui.Window( 10000 )
|
||||||
WINDOW.setProperty("librarysync", "busy")
|
WINDOW.setProperty("librarysync", "busy")
|
||||||
updateNeeded = False
|
pDialog = None
|
||||||
|
|
||||||
#process full movies sync
|
try:
|
||||||
allMovies = list()
|
|
||||||
movieData = self.getMovies(True)
|
|
||||||
|
|
||||||
if(movieData == None):
|
pDialog = xbmcgui.DialogProgressBG()
|
||||||
return False
|
if(pDialog != None):
|
||||||
|
pDialog.create('Sync DB', 'Sync DB')
|
||||||
for item in movieData:
|
|
||||||
if not item.get('IsFolder'):
|
|
||||||
kodiItem = self.getKodiMovie(item["Id"])
|
|
||||||
allMovies.append(item["Id"])
|
|
||||||
if kodiItem == None:
|
|
||||||
self.addMovieToKodiLibrary(item)
|
|
||||||
updateNeeded = True
|
|
||||||
else:
|
|
||||||
self.updateMovieToKodiLibrary(item, kodiItem)
|
|
||||||
|
|
||||||
#process full tv shows sync
|
|
||||||
allTVShows = list()
|
|
||||||
allEpisodes = list()
|
|
||||||
tvShowData = self.getTVShows(True)
|
|
||||||
|
|
||||||
if (tvShowData == None):
|
|
||||||
return
|
|
||||||
for item in tvShowData:
|
|
||||||
if item.get('IsFolder'):
|
|
||||||
kodiItem = self.getKodiTVShow(item["Id"])
|
|
||||||
allTVShows.append(item["Id"])
|
|
||||||
if kodiItem == None:
|
|
||||||
self.addTVShowToKodiLibrary(item)
|
|
||||||
updateNeeded = True
|
|
||||||
else:
|
|
||||||
self.updateTVShowToKodiLibrary(item, kodiItem)
|
|
||||||
|
|
||||||
|
updateNeeded = False
|
||||||
#process episodes (will only be possible when tv show is scanned to library)
|
|
||||||
#TODO --> maybe pull full info only when needed ?
|
|
||||||
allEpisodes = list()
|
|
||||||
|
|
||||||
for tvshow in allTVShows:
|
|
||||||
|
|
||||||
episodeData = self.getEpisodes(tvshow,True)
|
#process full movies sync
|
||||||
kodiEpisodes = self.getKodiEpisodes(tvshow)
|
allMovies = list()
|
||||||
|
movieData = self.getMovies(True)
|
||||||
#we have to compare the lists somehow
|
|
||||||
for item in episodeData:
|
if(movieData == None):
|
||||||
xbmc.sleep(150) # sleep to not overload system --> can this be replaced by moving the sync to a different thread ?
|
return False
|
||||||
comparestring1 = str(item.get("ParentIndexNumber")) + "-" + str(item.get("IndexNumber"))
|
|
||||||
matchFound = False
|
if(pDialog != None):
|
||||||
if kodiEpisodes != None:
|
pDialog.update(0, "Sync DB : Processing Movies")
|
||||||
for KodiItem in kodiEpisodes:
|
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()
|
||||||
|
allEpisodes = list()
|
||||||
|
tvShowData = self.getTVShows(True)
|
||||||
|
|
||||||
|
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"
|
||||||
|
|
||||||
allEpisodes.append(KodiItem["episodeid"])
|
# update progress bar
|
||||||
comparestring2 = str(KodiItem["season"]) + "-" + str(KodiItem["episode"])
|
if(pDialog != None):
|
||||||
if comparestring1 == comparestring2:
|
percentage = int(((float(count) / float(total)) * 100))
|
||||||
#match found - update episode
|
pDialog.update(percentage, message=progMessage + " Tv Show: " + str(count))
|
||||||
self.updateEpisodeToKodiLibrary(item,KodiItem,tvshow)
|
count += 1
|
||||||
matchFound = True
|
|
||||||
|
|
||||||
if not matchFound:
|
#process episodes (will only be possible when tv show is scanned to library)
|
||||||
#no match so we have to create it
|
#TODO --> maybe pull full info only when needed ?
|
||||||
print "episode not found...creating it: "
|
allEpisodes = list()
|
||||||
self.addEpisodeToKodiLibrary(item,tvshow)
|
|
||||||
updateNeeded = True
|
for tvshow in allTVShows:
|
||||||
|
|
||||||
|
|
||||||
# process deletes
|
|
||||||
# TODO --> process deletes for episodes !!!
|
|
||||||
cleanNeeded = False
|
|
||||||
allLocaldirs, filesMovies = xbmcvfs.listdir(movieLibrary)
|
|
||||||
allMB3Movies = set(allMovies)
|
|
||||||
for dir in allLocaldirs:
|
|
||||||
if not dir in allMB3Movies:
|
|
||||||
self.deleteMovieFromKodiLibrary(dir)
|
|
||||||
cleanneeded = True
|
|
||||||
|
|
||||||
allLocaldirs, filesTVShows = xbmcvfs.listdir(tvLibrary)
|
|
||||||
allMB3TVShows = set(allTVShows)
|
|
||||||
for dir in allLocaldirs:
|
|
||||||
if not dir in allMB3TVShows:
|
|
||||||
self.deleteTVShowFromKodiLibrary(dir)
|
|
||||||
cleanneeded = True
|
|
||||||
|
|
||||||
if cleanNeeded:
|
episodeData = self.getEpisodes(tvshow,True)
|
||||||
xbmc.executebuiltin("CleanLibrary(video)")
|
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 ?
|
||||||
|
comparestring1 = str(item.get("ParentIndexNumber")) + "-" + str(item.get("IndexNumber"))
|
||||||
|
matchFound = False
|
||||||
|
progMessage = "Processing"
|
||||||
|
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
|
||||||
|
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)
|
||||||
|
for dir in allLocaldirs:
|
||||||
|
if not dir in allMB3Movies:
|
||||||
|
self.deleteMovieFromKodiLibrary(dir)
|
||||||
|
cleanneeded = True
|
||||||
|
|
||||||
|
allLocaldirs, filesTVShows = xbmcvfs.listdir(tvLibrary)
|
||||||
|
allMB3TVShows = set(allTVShows)
|
||||||
|
for dir in allLocaldirs:
|
||||||
|
if not dir in allMB3TVShows:
|
||||||
|
self.deleteTVShowFromKodiLibrary(dir)
|
||||||
|
cleanneeded = True
|
||||||
|
|
||||||
|
if cleanNeeded:
|
||||||
|
xbmc.executebuiltin("CleanLibrary(video)")
|
||||||
|
|
||||||
|
if updateNeeded:
|
||||||
|
xbmc.executebuiltin("UpdateLibrary(video)")
|
||||||
|
|
||||||
if updateNeeded:
|
finally:
|
||||||
xbmc.executebuiltin("UpdateLibrary(video)")
|
WINDOW.clearProperty("librarysync")
|
||||||
|
if(pDialog != None):
|
||||||
WINDOW.clearProperty("librarysync")
|
pDialog.close()
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@ -135,54 +191,83 @@ class LibrarySync():
|
||||||
|
|
||||||
WINDOW = xbmcgui.Window( 10000 )
|
WINDOW = xbmcgui.Window( 10000 )
|
||||||
WINDOW.setProperty("librarysync", "busy")
|
WINDOW.setProperty("librarysync", "busy")
|
||||||
|
pDialog = None
|
||||||
|
|
||||||
#process movies
|
try:
|
||||||
movieData = self.getMovies(False)
|
|
||||||
if(movieData == None):
|
|
||||||
return False
|
|
||||||
|
|
||||||
for item in movieData:
|
pDialog = xbmcgui.DialogProgressBG()
|
||||||
if not item.get('IsFolder'):
|
if(pDialog != None):
|
||||||
kodiItem = self.getKodiMovie(item["Id"])
|
pDialog.create('Sync PlayCounts', 'Sync PlayCounts')
|
||||||
userData=API().getUserData(item)
|
|
||||||
timeInfo = API().getTimeInfo(item)
|
|
||||||
if kodiItem != None:
|
|
||||||
if kodiItem['playcount'] != int(userData.get("PlayCount")):
|
|
||||||
xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.SetMovieDetails", "params": { "movieid": %i, "playcount": %i}, "id": 1 }' %(kodiItem['movieid'], int(userData.get("PlayCount"))))
|
|
||||||
|
|
||||||
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:
|
|
||||||
self.setKodiResumePoint(kodiItem['movieid'],resume,total,"movie")
|
|
||||||
|
|
||||||
#process Tv shows
|
#process movies
|
||||||
tvshowData = self.getTVShows(False)
|
movieData = self.getMovies(False)
|
||||||
if (tvshowData == None):
|
if(movieData == None):
|
||||||
return False
|
|
||||||
|
|
||||||
for item in tvshowData:
|
|
||||||
episodeData = self.getEpisodes(item["Id"], False)
|
|
||||||
|
|
||||||
if (episodeData == None):
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
for episode in episodeData:
|
if(pDialog != None):
|
||||||
kodiItem = self.getKodiEpisodeByMbItem(episode)
|
pDialog.update(0, "Sync PlayCounts: Processing Movies")
|
||||||
userData=API().getUserData(episode)
|
totalCount = len(movieData) + 1
|
||||||
timeInfo = API().getTimeInfo(episode)
|
count = 1
|
||||||
if kodiItem != None:
|
|
||||||
if kodiItem['playcount'] != int(userData.get("PlayCount")):
|
for item in movieData:
|
||||||
xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.SetEpisodeDetails", "params": { "episodeid": %i, "playcount": %i}, "id": 1 }' %(kodiItem['episodeid'], int(userData.get("PlayCount"))))
|
if not item.get('IsFolder'):
|
||||||
|
kodiItem = self.getKodiMovie(item["Id"])
|
||||||
kodiresume = int(round(kodiItem['resume'].get("position")))
|
userData=API().getUserData(item)
|
||||||
resume = int(round(float(timeInfo.get("ResumeTime"))))*60
|
timeInfo = API().getTimeInfo(item)
|
||||||
total = int(round(float(timeInfo.get("TotalTime"))))*60
|
if kodiItem != None:
|
||||||
if kodiresume != resume:
|
if kodiItem['playcount'] != int(userData.get("PlayCount")):
|
||||||
self.setKodiResumePoint(kodiItem['episodeid'],resume,total,"episode")
|
xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.SetMovieDetails", "params": { "movieid": %i, "playcount": %i}, "id": 1 }' %(kodiItem['movieid'], int(userData.get("PlayCount"))))
|
||||||
|
|
||||||
|
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:
|
||||||
|
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):
|
||||||
|
for episode in episodeData:
|
||||||
|
kodiItem = self.getKodiEpisodeByMbItem(episode)
|
||||||
|
userData=API().getUserData(episode)
|
||||||
|
timeInfo = API().getTimeInfo(episode)
|
||||||
|
if kodiItem != None:
|
||||||
|
if kodiItem['playcount'] != int(userData.get("PlayCount")):
|
||||||
|
xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.SetEpisodeDetails", "params": { "episodeid": %i, "playcount": %i}, "id": 1 }' %(kodiItem['episodeid'], int(userData.get("PlayCount"))))
|
||||||
|
|
||||||
|
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:
|
||||||
|
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")
|
WINDOW.clearProperty("librarysync")
|
||||||
|
if(pDialog != None):
|
||||||
|
pDialog.close()
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
|
@ -84,8 +84,9 @@ class Service():
|
||||||
|
|
||||||
#full sync
|
#full sync
|
||||||
if(cur_seconds_fullsync >= interval_FullSync):
|
if(cur_seconds_fullsync >= interval_FullSync):
|
||||||
xbmc.log("Doing_Db_Sync: syncDatabase")
|
xbmc.log("Doing_Db_Sync: syncDatabase (Started)")
|
||||||
worked = librarySync.syncDatabase()
|
worked = librarySync.syncDatabase()
|
||||||
|
xbmc.log("Doing_Db_Sync: syncDatabase (Finished) " + str(worked))
|
||||||
if(worked):
|
if(worked):
|
||||||
cur_seconds_fullsync = 0
|
cur_seconds_fullsync = 0
|
||||||
else:
|
else:
|
||||||
|
@ -95,8 +96,9 @@ class Service():
|
||||||
|
|
||||||
#incremental sync
|
#incremental sync
|
||||||
if(cur_seconds_incrsync >= interval_IncrementalSync):
|
if(cur_seconds_incrsync >= interval_IncrementalSync):
|
||||||
xbmc.log("Doing_Db_Sync: updatePlayCounts")
|
xbmc.log("Doing_Db_Sync: updatePlayCounts (Started)")
|
||||||
worked = librarySync.updatePlayCounts()
|
worked = librarySync.updatePlayCounts()
|
||||||
|
xbmc.log("Doing_Db_Sync: updatePlayCounts (Finished) " + str(worked))
|
||||||
if(worked):
|
if(worked):
|
||||||
cur_seconds_incrsync = 0
|
cur_seconds_incrsync = 0
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in a new issue