add progress dialog to inc sync

This commit is contained in:
shaun 2015-08-15 12:00:21 +10:00
parent 0da02868c2
commit f87cdae256

View file

@ -598,8 +598,11 @@ class LibrarySync(threading.Thread):
WINDOW.setProperty("SyncDatabaseRunning", "true") WINDOW.setProperty("SyncDatabaseRunning", "true")
#show the progress dialog #show the progress dialog
pDialog = None
if (dbSyncIndication and xbmc.Player().isPlaying() == False): if (dbSyncIndication and xbmc.Player().isPlaying() == False):
xbmcgui.Dialog().notification('Emby for Kodi', 'Performing incremental sync...', "special://home/addons/plugin.video.emby/icon.png") pDialog = xbmcgui.DialogProgressBG()
pDialog.create('Emby for Kodi', 'Incremental Sync')
self.logMsg("Doing LibraryChanged : Show Progress IncrementalSync()", 0);
connection = utils.KodiSQL("video") connection = utils.KodiSQL("video")
cursor = connection.cursor() cursor = connection.cursor()
@ -609,19 +612,29 @@ class LibrarySync(threading.Thread):
views = ReadEmbyDB().getCollections("movies") views = ReadEmbyDB().getCollections("movies")
for view in views: for view in views:
allEmbyMovies = ReadEmbyDB().getMovies(view.get('id'), itemList) allEmbyMovies = ReadEmbyDB().getMovies(view.get('id'), itemList)
count = 1
total = len(allEmbyMovies) + 1
for item in allEmbyMovies: for item in allEmbyMovies:
if(pDialog != None):
progressTitle = "Incremental Sync "+ " (" + str(count) + " of " + str(total) + ")"
percentage = int(((float(count) / float(total)) * 100))
pDialog.update(percentage, "Emby for Kodi - Incremental Sync Movies", progressTitle)
count = count + 1
if not item.get('IsFolder'): if not item.get('IsFolder'):
WriteKodiVideoDB().addOrUpdateMovieToKodiLibrary(item["Id"],connection, cursor, view.get('title')) WriteKodiVideoDB().addOrUpdateMovieToKodiLibrary(item["Id"],connection, cursor, view.get('title'))
#### PROCESS BOX SETS ##### #### PROCESS BOX SETS #####
boxsets = ReadEmbyDB().getBoxSets() boxsets = ReadEmbyDB().getBoxSets()
count = 1
total = len(boxsets) + 1
for boxset in boxsets: for boxset in boxsets:
boxsetMovies = ReadEmbyDB().getMoviesInBoxSet(boxset["Id"]) boxsetMovies = ReadEmbyDB().getMoviesInBoxSet(boxset["Id"])
WriteKodiVideoDB().addBoxsetToKodiLibrary(boxset,connection, cursor) WriteKodiVideoDB().addBoxsetToKodiLibrary(boxset,connection, cursor)
if(pDialog != None):
progressTitle = "Incremental Sync "+ " (" + str(count) + " of " + str(total) + ")"
percentage = int(((float(count) / float(total)) * 100))
pDialog.update(percentage, "Emby for Kodi - Incremental Sync BoxSet", progressTitle)
count = count + 1
for boxsetMovie in boxsetMovies: for boxsetMovie in boxsetMovies:
WriteKodiVideoDB().updateBoxsetToKodiLibrary(boxsetMovie,boxset, connection, cursor) WriteKodiVideoDB().updateBoxsetToKodiLibrary(boxsetMovie,boxset, connection, cursor)
@ -629,14 +642,29 @@ class LibrarySync(threading.Thread):
views = ReadEmbyDB().getCollections("tvshows") views = ReadEmbyDB().getCollections("tvshows")
for view in views: for view in views:
allEmbyTvShows = ReadEmbyDB().getTvShows(view.get('id'),itemList) allEmbyTvShows = ReadEmbyDB().getTvShows(view.get('id'),itemList)
count = 1
total = len(allEmbyTvShows) + 1
for item in allEmbyTvShows: for item in allEmbyTvShows:
if(pDialog != None):
progressTitle = "Incremental Sync "+ " (" + str(count) + " of " + str(total) + ")"
percentage = int(((float(count) / float(total)) * 100))
pDialog.update(percentage, "Emby for Kodi - Incremental Sync Tv", progressTitle)
count = count + 1
if item.get('IsFolder') and item.get('RecursiveItemCount') != 0: if item.get('IsFolder') and item.get('RecursiveItemCount') != 0:
kodiId = WriteKodiVideoDB().addOrUpdateTvShowToKodiLibrary(item["Id"],connection, cursor, view.get('title')) kodiId = WriteKodiVideoDB().addOrUpdateTvShowToKodiLibrary(item["Id"],connection, cursor, view.get('title'))
#### PROCESS OTHERS BY THE ITEMLIST ###### #### PROCESS OTHERS BY THE ITEMLIST ######
count = 1
total = len(itemList) + 1
for item in itemList: for item in itemList:
if(pDialog != None):
progressTitle = "Incremental Sync "+ " (" + str(count) + " of " + str(total) + ")"
percentage = int(((float(count) / float(total)) * 100))
pDialog.update(percentage, "Emby for Kodi - Incremental Sync Items", progressTitle)
count = count + 1
MBitem = ReadEmbyDB().getItem(item) MBitem = ReadEmbyDB().getItem(item)
itemType = MBitem.get('Type', "") itemType = MBitem.get('Type', "")
@ -703,12 +731,25 @@ class LibrarySync(threading.Thread):
cursor.close() cursor.close()
finally: finally:
if(pDialog != None):
pDialog.close()
self.SaveLastSync()
xbmc.executebuiltin("UpdateLibrary(video)") xbmc.executebuiltin("UpdateLibrary(video)")
WINDOW.setProperty("SyncDatabaseRunning", "false") WINDOW.setProperty("SyncDatabaseRunning", "false")
# tell any widgets to refresh because the content has changed # tell any widgets to refresh because the content has changed
WINDOW.setProperty("widgetreload", datetime.now().strftime('%Y-%m-%d %H:%M:%S')) WINDOW.setProperty("widgetreload", datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
def removefromDB(self, itemList, deleteEmbyItem = False): def removefromDB(self, itemList, deleteEmbyItem = False):
dbSyncIndication = utils.settings("dbSyncIndication") == "true"
#show the progress dialog
pDialog = None
if (dbSyncIndication and xbmc.Player().isPlaying() == False):
pDialog = xbmcgui.DialogProgressBG()
pDialog.create('Emby for Kodi', 'Incremental Sync')
self.logMsg("Doing LibraryChanged : Show Progress removefromDB()", 0);
# Delete from Kodi before Emby # Delete from Kodi before Emby
# To be able to get mediaType # To be able to get mediaType
doUtils = DownloadUtils() doUtils = DownloadUtils()
@ -722,7 +763,16 @@ class LibrarySync(threading.Thread):
connectionmusic = utils.KodiSQL("music") connectionmusic = utils.KodiSQL("music")
cursormusic = connectionmusic.cursor() cursormusic = connectionmusic.cursor()
count = 1
total = len(itemList) + 1
for item in itemList: for item in itemList:
if(pDialog != None):
progressTitle = "Incremental Sync "+ " (" + str(count) + " of " + str(total) + ")"
percentage = int(((float(count) / float(total)) * 100))
pDialog.update(percentage, "Emby for Kodi - Incremental Sync Delete ", progressTitle)
count = count + 1
# Sort by type for database deletion # Sort by type for database deletion
try: # Search video database try: # Search video database
self.logMsg("Check video database.", 1) self.logMsg("Check video database.", 1)
@ -742,8 +792,16 @@ class LibrarySync(threading.Thread):
connection = connectionvideo connection = connectionvideo
cursor = cursorvideo cursor = cursorvideo
# Process video library # Process video library
count = 1
total = len(video) + 1
for item in video: for item in video:
if(pDialog != None):
progressTitle = "Incremental Sync "+ " (" + str(count) + " of " + str(total) + ")"
percentage = int(((float(count) / float(total)) * 100))
pDialog.update(percentage, "Emby for Kodi - Incremental Sync Delete ", progressTitle)
count = count + 1
type = video[item] type = video[item]
self.logMsg("Doing LibraryChanged: Items Removed: Calling deleteItemFromKodiLibrary: %s" % item, 1) self.logMsg("Doing LibraryChanged: Items Removed: Calling deleteItemFromKodiLibrary: %s" % item, 1)
@ -788,7 +846,22 @@ class LibrarySync(threading.Thread):
doUtils.downloadUrl(url, type = "DELETE") doUtils.downloadUrl(url, type = "DELETE")
xbmc.executebuiltin("Container.Refresh") xbmc.executebuiltin("Container.Refresh")
if(pDialog != None):
pDialog.close()
self.SaveLastSync()
def setUserdata(self, listItems): def setUserdata(self, listItems):
dbSyncIndication = utils.settings("dbSyncIndication") == "true"
#show the progress dialog
pDialog = None
if (dbSyncIndication and xbmc.Player().isPlaying() == False):
pDialog = xbmcgui.DialogProgressBG()
pDialog.create('Emby for Kodi', 'Incremental Sync')
self.logMsg("Doing LibraryChanged : Show Progress setUserdata()", 0);
# We need to sort between video and music database # We need to sort between video and music database
video = [] video = []
music = [] music = []
@ -799,9 +872,17 @@ class LibrarySync(threading.Thread):
#connectionmusic = utils.KodiSQL('music') #connectionmusic = utils.KodiSQL('music')
#cursormusic = connectionmusic.cursor() #cursormusic = connectionmusic.cursor()
count = 1
total = len(listItems) + 1
for userdata in listItems: for userdata in listItems:
itemId = userdata['ItemId'] itemId = userdata['ItemId']
if(pDialog != None):
progressTitle = "Incremental Sync "+ " (" + str(count) + " of " + str(total) + ")"
percentage = int(((float(count) / float(total)) * 100))
pDialog.update(percentage, "Emby for Kodi - Incremental Sync User Data ", progressTitle)
count = count + 1
cursorvideo.execute("SELECT media_type FROM emby WHERE emby_id = ?", (itemId,)) cursorvideo.execute("SELECT media_type FROM emby WHERE emby_id = ?", (itemId,))
try: # Search video database try: # Search video database
self.logMsg("Check video database.", 1) self.logMsg("Check video database.", 1)
@ -820,7 +901,14 @@ class LibrarySync(threading.Thread):
connection = connectionvideo connection = connectionvideo
cursor = cursorvideo cursor = cursorvideo
# Process the userdata update for video library # Process the userdata update for video library
count = 1
total = len(video) + 1
for userdata in video: for userdata in video:
if(pDialog != None):
progressTitle = "Incremental Sync "+ " (" + str(count) + " of " + str(total) + ")"
percentage = int(((float(count) / float(total)) * 100))
pDialog.update(percentage, "Emby for Kodi - Incremental Sync User Data ", progressTitle)
count = count + 1
WriteKodiVideoDB().updateUserdata(userdata, connection, cursor) WriteKodiVideoDB().updateUserdata(userdata, connection, cursor)
connection.commit() connection.commit()
@ -842,10 +930,16 @@ class LibrarySync(threading.Thread):
xbmc.executebuiltin("UpdateLibrary(music)")''' xbmc.executebuiltin("UpdateLibrary(music)")'''
# Close connection # Close connection
#cursormusic.close() #cursormusic.close()
if(pDialog != None):
pDialog.close()
self.SaveLastSync() self.SaveLastSync()
def remove_items(self, itemsRemoved): def remove_items(self, itemsRemoved):
# websocket client # websocket client
if(len(itemsRemoved) > 0):
self.logMsg("Doing LibraryChanged : Processing Deleted : " + str(itemsRemoved), 0)
self.removeItems.extend(itemsRemoved) self.removeItems.extend(itemsRemoved)
def update_items(self, itemsToUpdate): def update_items(self, itemsToUpdate):
@ -856,6 +950,8 @@ class LibrarySync(threading.Thread):
def user_data_update(self, userDataList): def user_data_update(self, userDataList):
# websocket client # websocket client
if(len(userDataList) > 0):
self.logMsg("Doing LibraryChanged : Processing User Data Changed : " + str(userDataList), 0)
self.userdataItems.extend(userDataList) self.userdataItems.extend(userDataList)
def ShouldStop(self): def ShouldStop(self):