diff --git a/resources/lib/LibrarySync.py b/resources/lib/LibrarySync.py index 7ae14370..a9401409 100644 --- a/resources/lib/LibrarySync.py +++ b/resources/lib/LibrarySync.py @@ -1034,11 +1034,10 @@ class LibrarySync(threading.Thread): return False def run(self): - - startupComplete = False - kodiProfile = xbmc.translatePath("special://profile") - + clientInfo = ClientInformation() self.logMsg("--- Starting Library Sync Thread ---", 0) + WINDOW = xbmcgui.Window(10000) + startupComplete = False while not self.KodiMonitor.abortRequested(): @@ -1056,22 +1055,22 @@ class LibrarySync(threading.Thread): # Only get in here for a while, can be removed later if utils.settings("dbCreatedWithVersion")=="" and utils.settings("SyncInstallRunDone") == "true": self.logMsg("Unknown DB version", 0) - return_value = xbmcgui.Dialog().yesno("DB Version", "Can't detect version of Emby for Kodi the DB was created with.\nWas it at least version " + utils.window('minDBVersion') + "?") + return_value = xbmcgui.Dialog().yesno("DB Version", "Can't detect version of Emby for Kodi the DB was created with.\nWas it at least version " + WINDOW.getProperty('minDBVersion') + "?") if return_value == 0: utils.settings("dbCreatedWithVersion","0.0.0") self.logMsg("DB version out of date according to user", 0) else: - utils.settings("dbCreatedWithVersion", utils.window('minDBVersion')) + utils.settings("dbCreatedWithVersion",WINDOW.getProperty('minDBVersion')) self.logMsg("DB version okay according to user", 0) # END TEMPORARY CODE - if (utils.settings("SyncInstallRunDone") == "true" and self.checkDBVersion(utils.settings("dbCreatedWithVersion"), utils.window('minDBVersion'))==False and utils.window('minDBVersionCheck') != "true"): + if (utils.settings("SyncInstallRunDone") == "true" and self.checkDBVersion(utils.settings("dbCreatedWithVersion"), WINDOW.getProperty('minDBVersion'))==False and WINDOW.getProperty('minDBVersionCheck') != "true"): self.logMsg("DB version out of date according to check", 0) return_value = xbmcgui.Dialog().yesno("DB Version", "Detected the DB needs to be recreated for\nthis version of Emby for Kodi.\nProceed?") if return_value == 0: self.logMsg("DB version out of date !!! USER IGNORED !!!", 0) xbmcgui.Dialog().ok("Emby for Kodi","Emby for Kodi may not work\ncorrectly until the database is reset.\n") - utils.window('minDBVersionCheck', value="true") + WINDOW.setProperty('minDBVersionCheck', "true") else: utils.reset() @@ -1089,9 +1088,9 @@ class LibrarySync(threading.Thread): startupComplete = True # Set via Kodi Monitor event - if utils.window('OnWakeSync') == "true" and utils.window('Server_online') == "true": - utils.window("OnWakeSync", clear=True) - if utils.window("SyncDatabaseRunning") != "true": + if WINDOW.getProperty("OnWakeSync") == "true" and WINDOW.getProperty('Server_online') == "true": + WINDOW.clearProperty("OnWakeSync") + if WINDOW.getProperty("SyncDatabaseRunning") != "true": self.logMsg("Doing_Db_Sync Post Resume: syncDatabase (Started)", 0) libSync = self.FullLibrarySync() self.logMsg("Doing_Db_Sync Post Resume: syncDatabase (Finished) " + str(libSync), 0) @@ -1119,12 +1118,6 @@ class LibrarySync(threading.Thread): self.removeItems = [] self.removefromDB(listItems) - - if utils.window("kodiProfile_emby") != kodiProfile: - # Profile change happened, terminate this thread - self.logMsg("Kodi profile was: %s and changed to: %s. Terminating Library thread." % (kodiProfile, utils.window("kodiProfile_emby")), 1) - break - if self.KodiMonitor.waitForAbort(1): # Abort was requested while waiting. We should exit break diff --git a/service.py b/service.py index 6b397977..47426aa2 100644 --- a/service.py +++ b/service.py @@ -1,7 +1,5 @@ # -*- coding: utf-8 -*- -################################################################################################# - import os import sys import time @@ -12,15 +10,11 @@ import xbmc import xbmcgui import xbmcvfs -################################################################################################# - _addon = xbmcaddon.Addon(id='plugin.video.emby') addon_path = _addon.getAddonInfo('path').decode('utf-8') base_resource_path = xbmc.translatePath(os.path.join(addon_path, 'resources', 'lib')).decode('utf-8') sys.path.append(base_resource_path) -################################################################################################# - import KodiMonitor import Utils as utils from ClientInformation import ClientInformation @@ -31,8 +25,6 @@ from WebSocketClient import WebSocketThread from LibrarySync import LibrarySync from LibraryMonitor import LibraryMonitor -################################################################################################# - class Service(): KodiMonitor = KodiMonitor.Kodi_Monitor() @@ -52,31 +44,28 @@ class Service(): def __init__(self, *args): addonName = self.addonName - clientInfo = self.clientInfo - logLevel = self.logLevel - - utils.window('getLogLevel', value=str(logLevel)) - utils.window('kodiProfile_emby', value=xbmc.translatePath("special://profile")) + WINDOW = self.WINDOW + WINDOW.setProperty('getLogLevel', str(self.logLevel)) # Initial logging self.logMsg("Starting Monitor", 0) self.logMsg("======== START %s ========" % addonName, 0) - self.logMsg("Platform: %s" % (clientInfo.getPlatform()), 0) + self.logMsg("Platform: %s" % (self.clientInfo.getPlatform()), 0) self.logMsg("KODI Version: %s" % xbmc.getInfoLabel('System.BuildVersion'), 0) - self.logMsg("%s Version: %s" % (addonName, clientInfo.getVersion()), 0) - self.logMsg("Log Level: %s" % logLevel, 0) + self.logMsg("%s Version: %s" % (addonName, self.clientInfo.getVersion()), 0) + self.logMsg("Log Level: %s" % self.logLevel, 1) # Reset window props for profile switch - utils.window('Server_online', clear=True) - utils.window('Server_status', clear=True) - utils.window('startup', clear=True) - utils.window('OnWakeSync', clear=True) - utils.window('minDBVersionCheck', clear=True) + WINDOW.clearProperty('Server_online') + WINDOW.clearProperty('Server_status') + WINDOW.clearProperty('startup') + WINDOW.clearProperty('OnWakeSync') + WINDOW.clearProperty('minDBVersionCheck') # Set min DB version - utils.window('minDBVersion', value="1.1.40") + WINDOW.setProperty('minDBVersion','1.1.40') - embyProperty = utils.window('Emby.nodes.total') + embyProperty = WINDOW.getProperty('Emby.nodes.total') propNames = [ "index","path","title","content", @@ -95,7 +84,7 @@ class Service(): totalNodes = int(embyProperty) for i in range(totalNodes): for prop in propNames: - utils.window('Emby.nodes.%s.%s' % (str(i), prop), clear=True) + WINDOW.clearProperty('Emby.nodes.%s.%s' % (str(i), prop)) def logMsg(self, msg, lvl=1): @@ -103,9 +92,9 @@ class Service(): utils.logMsg("%s %s" % (self.addonName, className), msg, int(lvl)) def ServiceEntryPoint(self): - - kodiProfile = xbmc.translatePath("special://profile") - + + WINDOW = self.WINDOW + # Server auto-detect ConnectionManager().checkServer() @@ -128,7 +117,7 @@ class Service(): # 2. User is set # 3. User has access to the server - if utils.window('Server_online') == "true": + if WINDOW.getProperty('Server_online') == "true": # Emby server is online # Verify if user is set and has access to the server @@ -144,7 +133,7 @@ class Service(): # Update positionticks if player.played_information.get(currentFile) is not None: - player.played_information[currentFile]['currentPosition'] = playTime + player.played_information[currentFile]["currentPosition"] = playTime td = datetime.today() - lastProgressUpdate secDiff = td.seconds @@ -154,12 +143,12 @@ class Service(): player.reportPlayback() lastProgressUpdate = datetime.today() - elif utils.window('commandUpdate') == "true": + elif WINDOW.getProperty('commandUpdate') == "true": # Received a remote control command that # requires updating immediately - utils.window('commandUpdate', clear=True) + WINDOW.clearProperty('commandUpdate') player.reportPlayback() - lastProgressUpdate = da4tetime.today() + lastProgressUpdate = datetime.today() except Exception as e: self.logMsg("Exception in Playback Monitor Service: %s" % e, 1) @@ -202,7 +191,7 @@ class Service(): # Verify access with an API call user.hasAccess() - if utils.window('Server_online') != "true": + if WINDOW.getProperty('Server_online') != "true": # Server went offline break @@ -224,7 +213,7 @@ class Service(): # Alert the user and suppress future warning if self.server_online: self.logMsg("Server is offline.", 1) - utils.window('Server_online', value="false") + WINDOW.setProperty('Server_online', "false") xbmcgui.Dialog().notification("Error connecting", "%s Server is unreachable." % self.addonName, icon="special://home/addons/plugin.video.emby/icon.png", sound=False) self.server_online = False @@ -241,7 +230,7 @@ class Service(): self.server_online = True self.logMsg("Server is online and ready.", 1) - utils.window('Server_online', value="true") + WINDOW.setProperty('Server_online', "true") # Start the User client if self.newUserClient is None: @@ -253,19 +242,11 @@ class Service(): # Abort was requested while waiting. break - - if utils.window("kodiProfile_emby") != kodiProfile: - # Profile change happened, terminate this thread - self.logMsg("Kodi profile was: %s and changed to: %s. Terminating old Emby thread." % (kodiProfile, utils.window("kodiProfile_emby")), 1) - break - if self.KodiMonitor.waitForAbort(1): # Abort was requested while waiting. We should exit break - ##### Emby thread is terminating. ##### - - # If music is enabled and direct stream for music is enabled + # If music is enable and direct stream for music is enabled # We use Kodi pathsubstitution to allow for music to play outside network # The setting needs to be set before Kodi starts. if utils.settings('enableMusicSync') == "true" and utils.settings('directstreammusic') == "true":