diff --git a/resources/lib/LibrarySync.py b/resources/lib/LibrarySync.py index 0ea00717..e50e3c8b 100644 --- a/resources/lib/LibrarySync.py +++ b/resources/lib/LibrarySync.py @@ -37,34 +37,43 @@ class LibrarySync(): startupDone = WINDOW.getProperty("startup") == "done" syncInstallRunDone = addon.getSetting("SyncInstallRunDone") == "true" + WINDOW.setProperty("SyncDatabaseRunning", "true") - completed = True - - # sync movies - if(syncInstallRunDone == False): # on first install run do a full sync with model progress dialog - completed = completed and self.TvShowsSync(True, True) - completed = completed and self.MoviesSync(True, True) - completed = completed and self.MusicVideosSync(True, True) - elif(startupDone == False): # on first run after startup do a inc then a full sync - self.TvShowsSync(False, False) - self.MoviesSync(False, False) - self.MusicVideosSync(False, False) - self.TvShowsSync(True, False) - self.MoviesSync(True, False) - self.MusicVideosSync(True, False) - else: # on scheduled sync do a full sync - self.TvShowsSync(True, False) - self.MoviesSync(True, False) - self.MusicVideosSync(True, False) - - # set the install done setting - if(syncInstallRunDone == False and completed): - addon = xbmcaddon.Addon(id='plugin.video.emby') #force a new instance of the addon - addon.setSetting("SyncInstallRunDone", "true") - - # set prop to show we have run for the first time - WINDOW.setProperty("startup", "done") - + if(WINDOW.getProperty("SyncDatabaseShouldStop") == "true"): + utils.logMsg("Sync Database", "Can not start SyncDatabaseShouldStop=True", 0) + return True + + try: + completed = True + + # sync movies + if(syncInstallRunDone == False): # on first install run do a full sync with model progress dialog + completed = completed and self.TvShowsSync(True, True) + completed = completed and self.MoviesSync(True, True) + completed = completed and self.MusicVideosSync(True, True) + elif(startupDone == False): # on first run after startup do a inc then a full sync + self.TvShowsSync(False, False) + self.MoviesSync(False, False) + self.MusicVideosSync(False, False) + self.TvShowsSync(True, False) + self.MoviesSync(True, False) + self.MusicVideosSync(True, False) + else: # on scheduled sync do a full sync + self.TvShowsSync(True, False) + self.MoviesSync(True, False) + self.MusicVideosSync(True, False) + + # set the install done setting + if(syncInstallRunDone == False and completed): + addon = xbmcaddon.Addon(id='plugin.video.emby') #force a new instance of the addon + addon.setSetting("SyncInstallRunDone", "true") + + # set prop to show we have run for the first time + WINDOW.setProperty("startup", "done") + + finally: + WINDOW.setProperty("SyncDatabaseRunning", "false") + return True def MoviesSync(self, fullsync, installFirstRun, itemList = []): @@ -734,9 +743,14 @@ class LibrarySync(): processMovies = True processTvShows = True + if(WINDOW.getProperty("SyncDatabaseShouldStop") == "true"): + utils.logMsg("Sync PlayCount", "Can not start SyncDatabaseShouldStop=True", 0) + return True + if(WINDOW.getProperty("updatePlayCounts_Running") == "true"): utils.logMsg("Sync PlayCount", "updatePlayCounts Already Running", 0) return False + WINDOW.setProperty("updatePlayCounts_Running", "true") try: @@ -977,8 +991,12 @@ class LibrarySync(): if(xbmc.Player().isPlaying() or xbmc.abortRequested): return True - else: - return False + + WINDOW = xbmcgui.Window( 10000 ) + if(WINDOW.getProperty("SyncDatabaseShouldStop") == "true"): + return True + + return False diff --git a/resources/lib/Utils.py b/resources/lib/Utils.py index 727c311e..e9a30514 100644 --- a/resources/lib/Utils.py +++ b/resources/lib/Utils.py @@ -150,6 +150,23 @@ def removeDirectory(path): xbmcvfs.rmdir(path) def reset(): + + return_value = xbmcgui.Dialog().yesno("Warning", "Are you sure you want to reset your local database?") + if return_value == 0: + return + + # first stop any db sync + WINDOW = xbmcgui.Window( 10000 ) + WINDOW.setProperty("SyncDatabaseShouldStop", "true") + + count = 0 + while(WINDOW.getProperty("SyncDatabaseRunning") == "true"): + count += 1 + if(count > 10): + dialog.ok('Warning', 'Could not stop DB sync, you should try again.') + return + xbmc.sleep(1000) + # clear video database connection = KodiSQL() cursor = connection.cursor() @@ -321,5 +338,6 @@ def reset(): addon.setSetting("SyncFirstCountsRunDone", "false") dialog = xbmcgui.Dialog() - dialog.ok('Emby Reset', 'Reset of Emby has completed, please restart.') + dialog.ok('Emby Reset', 'Reset of Emby has completed, you need to restart.') + xbmc.executebuiltin("RestartApp")