mirror of
https://github.com/jellyfin/jellyfin-kodi.git
synced 2024-12-26 02:36:10 +00:00
Fix profile switch v2
Make sure the threads are terminated correctly. This time, verify the profile before anything else.
This commit is contained in:
parent
e0343891af
commit
a39784cb81
2 changed files with 61 additions and 36 deletions
|
@ -1034,10 +1034,11 @@ class LibrarySync(threading.Thread):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
clientInfo = ClientInformation()
|
|
||||||
self.logMsg("--- Starting Library Sync Thread ---", 0)
|
|
||||||
WINDOW = xbmcgui.Window(10000)
|
|
||||||
startupComplete = False
|
startupComplete = False
|
||||||
|
kodiProfile = xbmc.translatePath("special://profile")
|
||||||
|
|
||||||
|
self.logMsg("--- Starting Library Sync Thread ---", 0)
|
||||||
|
|
||||||
while not self.KodiMonitor.abortRequested():
|
while not self.KodiMonitor.abortRequested():
|
||||||
|
|
||||||
|
@ -1055,22 +1056,22 @@ class LibrarySync(threading.Thread):
|
||||||
# Only get in here for a while, can be removed later
|
# Only get in here for a while, can be removed later
|
||||||
if utils.settings("dbCreatedWithVersion")=="" and utils.settings("SyncInstallRunDone") == "true":
|
if utils.settings("dbCreatedWithVersion")=="" and utils.settings("SyncInstallRunDone") == "true":
|
||||||
self.logMsg("Unknown DB version", 0)
|
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 " + WINDOW.getProperty('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 " + utils.window('minDBVersion') + "?")
|
||||||
if return_value == 0:
|
if return_value == 0:
|
||||||
utils.settings("dbCreatedWithVersion","0.0.0")
|
utils.settings("dbCreatedWithVersion","0.0.0")
|
||||||
self.logMsg("DB version out of date according to user", 0)
|
self.logMsg("DB version out of date according to user", 0)
|
||||||
else:
|
else:
|
||||||
utils.settings("dbCreatedWithVersion",WINDOW.getProperty('minDBVersion'))
|
utils.settings("dbCreatedWithVersion", utils.window('minDBVersion'))
|
||||||
self.logMsg("DB version okay according to user", 0)
|
self.logMsg("DB version okay according to user", 0)
|
||||||
# END TEMPORARY CODE
|
# END TEMPORARY CODE
|
||||||
|
|
||||||
if (utils.settings("SyncInstallRunDone") == "true" and self.checkDBVersion(utils.settings("dbCreatedWithVersion"), WINDOW.getProperty('minDBVersion'))==False and WINDOW.getProperty('minDBVersionCheck') != "true"):
|
if (utils.settings("SyncInstallRunDone") == "true" and self.checkDBVersion(utils.settings("dbCreatedWithVersion"), utils.window('minDBVersion'))==False and utils.window('minDBVersionCheck') != "true"):
|
||||||
self.logMsg("DB version out of date according to check", 0)
|
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?")
|
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:
|
if return_value == 0:
|
||||||
self.logMsg("DB version out of date !!! USER IGNORED !!!", 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")
|
xbmcgui.Dialog().ok("Emby for Kodi","Emby for Kodi may not work\ncorrectly until the database is reset.\n")
|
||||||
WINDOW.setProperty('minDBVersionCheck', "true")
|
utils.window('minDBVersionCheck', value="true")
|
||||||
else:
|
else:
|
||||||
utils.reset()
|
utils.reset()
|
||||||
|
|
||||||
|
@ -1088,9 +1089,9 @@ class LibrarySync(threading.Thread):
|
||||||
startupComplete = True
|
startupComplete = True
|
||||||
|
|
||||||
# Set via Kodi Monitor event
|
# Set via Kodi Monitor event
|
||||||
if WINDOW.getProperty("OnWakeSync") == "true" and WINDOW.getProperty('Server_online') == "true":
|
if utils.window('OnWakeSync') == "true" and utils.window('Server_online') == "true":
|
||||||
WINDOW.clearProperty("OnWakeSync")
|
utils.window("OnWakeSync", clear=True)
|
||||||
if WINDOW.getProperty("SyncDatabaseRunning") != "true":
|
if utils.window("SyncDatabaseRunning") != "true":
|
||||||
self.logMsg("Doing_Db_Sync Post Resume: syncDatabase (Started)", 0)
|
self.logMsg("Doing_Db_Sync Post Resume: syncDatabase (Started)", 0)
|
||||||
libSync = self.FullLibrarySync()
|
libSync = self.FullLibrarySync()
|
||||||
self.logMsg("Doing_Db_Sync Post Resume: syncDatabase (Finished) " + str(libSync), 0)
|
self.logMsg("Doing_Db_Sync Post Resume: syncDatabase (Finished) " + str(libSync), 0)
|
||||||
|
@ -1118,6 +1119,12 @@ class LibrarySync(threading.Thread):
|
||||||
self.removeItems = []
|
self.removeItems = []
|
||||||
self.removefromDB(listItems)
|
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):
|
if self.KodiMonitor.waitForAbort(1):
|
||||||
# Abort was requested while waiting. We should exit
|
# Abort was requested while waiting. We should exit
|
||||||
break
|
break
|
||||||
|
|
66
service.py
66
service.py
|
@ -1,5 +1,7 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
#################################################################################################
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
|
@ -10,11 +12,15 @@ import xbmc
|
||||||
import xbmcgui
|
import xbmcgui
|
||||||
import xbmcvfs
|
import xbmcvfs
|
||||||
|
|
||||||
|
#################################################################################################
|
||||||
|
|
||||||
_addon = xbmcaddon.Addon(id='plugin.video.emby')
|
_addon = xbmcaddon.Addon(id='plugin.video.emby')
|
||||||
addon_path = _addon.getAddonInfo('path').decode('utf-8')
|
addon_path = _addon.getAddonInfo('path').decode('utf-8')
|
||||||
base_resource_path = xbmc.translatePath(os.path.join(addon_path, 'resources', 'lib')).decode('utf-8')
|
base_resource_path = xbmc.translatePath(os.path.join(addon_path, 'resources', 'lib')).decode('utf-8')
|
||||||
sys.path.append(base_resource_path)
|
sys.path.append(base_resource_path)
|
||||||
|
|
||||||
|
#################################################################################################
|
||||||
|
|
||||||
import KodiMonitor
|
import KodiMonitor
|
||||||
import Utils as utils
|
import Utils as utils
|
||||||
from ClientInformation import ClientInformation
|
from ClientInformation import ClientInformation
|
||||||
|
@ -25,6 +31,8 @@ from WebSocketClient import WebSocketThread
|
||||||
from LibrarySync import LibrarySync
|
from LibrarySync import LibrarySync
|
||||||
from LibraryMonitor import LibraryMonitor
|
from LibraryMonitor import LibraryMonitor
|
||||||
|
|
||||||
|
#################################################################################################
|
||||||
|
|
||||||
class Service():
|
class Service():
|
||||||
|
|
||||||
KodiMonitor = KodiMonitor.Kodi_Monitor()
|
KodiMonitor = KodiMonitor.Kodi_Monitor()
|
||||||
|
@ -44,28 +52,31 @@ class Service():
|
||||||
def __init__(self, *args):
|
def __init__(self, *args):
|
||||||
|
|
||||||
addonName = self.addonName
|
addonName = self.addonName
|
||||||
WINDOW = self.WINDOW
|
clientInfo = self.clientInfo
|
||||||
WINDOW.setProperty('getLogLevel', str(self.logLevel))
|
logLevel = self.logLevel
|
||||||
|
|
||||||
|
utils.window('getLogLevel', value=str(logLevel))
|
||||||
|
utils.window('kodiProfile_emby', value=xbmc.translatePath("special://profile"))
|
||||||
|
|
||||||
# Initial logging
|
# Initial logging
|
||||||
self.logMsg("Starting Monitor", 0)
|
self.logMsg("Starting Monitor", 0)
|
||||||
self.logMsg("======== START %s ========" % addonName, 0)
|
self.logMsg("======== START %s ========" % addonName, 0)
|
||||||
self.logMsg("Platform: %s" % (self.clientInfo.getPlatform()), 0)
|
self.logMsg("Platform: %s" % (clientInfo.getPlatform()), 0)
|
||||||
self.logMsg("KODI Version: %s" % xbmc.getInfoLabel('System.BuildVersion'), 0)
|
self.logMsg("KODI Version: %s" % xbmc.getInfoLabel('System.BuildVersion'), 0)
|
||||||
self.logMsg("%s Version: %s" % (addonName, self.clientInfo.getVersion()), 0)
|
self.logMsg("%s Version: %s" % (addonName, clientInfo.getVersion()), 0)
|
||||||
self.logMsg("Log Level: %s" % self.logLevel, 1)
|
self.logMsg("Log Level: %s" % logLevel, 0)
|
||||||
|
|
||||||
# Reset window props for profile switch
|
# Reset window props for profile switch
|
||||||
WINDOW.clearProperty('Server_online')
|
utils.window('Server_online', clear=True)
|
||||||
WINDOW.clearProperty('Server_status')
|
utils.window('Server_status', clear=True)
|
||||||
WINDOW.clearProperty('startup')
|
utils.window('startup', clear=True)
|
||||||
WINDOW.clearProperty('OnWakeSync')
|
utils.window('OnWakeSync', clear=True)
|
||||||
WINDOW.clearProperty('minDBVersionCheck')
|
utils.window('minDBVersionCheck', clear=True)
|
||||||
|
|
||||||
# Set min DB version
|
# Set min DB version
|
||||||
WINDOW.setProperty('minDBVersion','1.1.40')
|
utils.window('minDBVersion', value="1.1.40")
|
||||||
|
|
||||||
embyProperty = WINDOW.getProperty('Emby.nodes.total')
|
embyProperty = utils.window('Emby.nodes.total')
|
||||||
propNames = [
|
propNames = [
|
||||||
|
|
||||||
"index","path","title","content",
|
"index","path","title","content",
|
||||||
|
@ -84,7 +95,7 @@ class Service():
|
||||||
totalNodes = int(embyProperty)
|
totalNodes = int(embyProperty)
|
||||||
for i in range(totalNodes):
|
for i in range(totalNodes):
|
||||||
for prop in propNames:
|
for prop in propNames:
|
||||||
WINDOW.clearProperty('Emby.nodes.%s.%s' % (str(i), prop))
|
utils.window('Emby.nodes.%s.%s' % (str(i), prop), clear=True)
|
||||||
|
|
||||||
def logMsg(self, msg, lvl=1):
|
def logMsg(self, msg, lvl=1):
|
||||||
|
|
||||||
|
@ -93,7 +104,7 @@ class Service():
|
||||||
|
|
||||||
def ServiceEntryPoint(self):
|
def ServiceEntryPoint(self):
|
||||||
|
|
||||||
WINDOW = self.WINDOW
|
kodiProfile = xbmc.translatePath("special://profile")
|
||||||
|
|
||||||
# Server auto-detect
|
# Server auto-detect
|
||||||
ConnectionManager().checkServer()
|
ConnectionManager().checkServer()
|
||||||
|
@ -117,7 +128,12 @@ class Service():
|
||||||
# 2. User is set
|
# 2. User is set
|
||||||
# 3. User has access to the server
|
# 3. User has access to the server
|
||||||
|
|
||||||
if WINDOW.getProperty('Server_online') == "true":
|
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 utils.window('Server_online') == "true":
|
||||||
|
|
||||||
# Emby server is online
|
# Emby server is online
|
||||||
# Verify if user is set and has access to the server
|
# Verify if user is set and has access to the server
|
||||||
|
@ -133,7 +149,7 @@ class Service():
|
||||||
|
|
||||||
# Update positionticks
|
# Update positionticks
|
||||||
if player.played_information.get(currentFile) is not None:
|
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
|
td = datetime.today() - lastProgressUpdate
|
||||||
secDiff = td.seconds
|
secDiff = td.seconds
|
||||||
|
@ -143,12 +159,12 @@ class Service():
|
||||||
player.reportPlayback()
|
player.reportPlayback()
|
||||||
lastProgressUpdate = datetime.today()
|
lastProgressUpdate = datetime.today()
|
||||||
|
|
||||||
elif WINDOW.getProperty('commandUpdate') == "true":
|
elif utils.window('commandUpdate') == "true":
|
||||||
# Received a remote control command that
|
# Received a remote control command that
|
||||||
# requires updating immediately
|
# requires updating immediately
|
||||||
WINDOW.clearProperty('commandUpdate')
|
utils.window('commandUpdate', clear=True)
|
||||||
player.reportPlayback()
|
player.reportPlayback()
|
||||||
lastProgressUpdate = datetime.today()
|
lastProgressUpdate = da4tetime.today()
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.logMsg("Exception in Playback Monitor Service: %s" % e, 1)
|
self.logMsg("Exception in Playback Monitor Service: %s" % e, 1)
|
||||||
|
@ -191,7 +207,7 @@ class Service():
|
||||||
# Verify access with an API call
|
# Verify access with an API call
|
||||||
user.hasAccess()
|
user.hasAccess()
|
||||||
|
|
||||||
if WINDOW.getProperty('Server_online') != "true":
|
if utils.window('Server_online') != "true":
|
||||||
# Server went offline
|
# Server went offline
|
||||||
break
|
break
|
||||||
|
|
||||||
|
@ -213,7 +229,7 @@ class Service():
|
||||||
# Alert the user and suppress future warning
|
# Alert the user and suppress future warning
|
||||||
if self.server_online:
|
if self.server_online:
|
||||||
self.logMsg("Server is offline.", 1)
|
self.logMsg("Server is offline.", 1)
|
||||||
WINDOW.setProperty('Server_online', "false")
|
utils.window('Server_online', value="false")
|
||||||
xbmcgui.Dialog().notification("Error connecting", "%s Server is unreachable." % self.addonName, icon="special://home/addons/plugin.video.emby/icon.png", sound=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
|
self.server_online = False
|
||||||
|
|
||||||
|
@ -230,7 +246,7 @@ class Service():
|
||||||
|
|
||||||
self.server_online = True
|
self.server_online = True
|
||||||
self.logMsg("Server is online and ready.", 1)
|
self.logMsg("Server is online and ready.", 1)
|
||||||
WINDOW.setProperty('Server_online', "true")
|
utils.window('Server_online', value="true")
|
||||||
|
|
||||||
# Start the User client
|
# Start the User client
|
||||||
if self.newUserClient is None:
|
if self.newUserClient is None:
|
||||||
|
@ -246,7 +262,9 @@ class Service():
|
||||||
# Abort was requested while waiting. We should exit
|
# Abort was requested while waiting. We should exit
|
||||||
break
|
break
|
||||||
|
|
||||||
# If music is enable and direct stream for music is enabled
|
##### Emby thread is terminating. #####
|
||||||
|
|
||||||
|
# If music is enabled and direct stream for music is enabled
|
||||||
# We use Kodi pathsubstitution to allow for music to play outside network
|
# We use Kodi pathsubstitution to allow for music to play outside network
|
||||||
# The setting needs to be set before Kodi starts.
|
# The setting needs to be set before Kodi starts.
|
||||||
if utils.settings('enableMusicSync') == "true" and utils.settings('directstreammusic') == "true":
|
if utils.settings('enableMusicSync') == "true" and utils.settings('directstreammusic') == "true":
|
||||||
|
@ -272,5 +290,5 @@ class Service():
|
||||||
|
|
||||||
self.logMsg("======== STOP %s ========" % self.addonName, 0)
|
self.logMsg("======== STOP %s ========" % self.addonName, 0)
|
||||||
|
|
||||||
#start the service
|
# Start the service
|
||||||
Service().ServiceEntryPoint()
|
Service().ServiceEntryPoint()
|
Loading…
Reference in a new issue