mirror of
https://github.com/jellyfin/jellyfin-kodi.git
synced 2024-12-24 17:56:11 +00:00
Reworked the userclient with possibilities
Revoked token was actually broken, handle access schedule better, restart/start properly. This is to stabilize things.
This commit is contained in:
parent
696586e952
commit
11e4a70e25
4 changed files with 51 additions and 21 deletions
|
@ -124,7 +124,6 @@ class DownloadUtils():
|
||||||
self.s.mount("https://", requests.adapters.HTTPAdapter(max_retries=1))
|
self.s.mount("https://", requests.adapters.HTTPAdapter(max_retries=1))
|
||||||
|
|
||||||
self.logMsg("Requests session started on: %s" % self.server)
|
self.logMsg("Requests session started on: %s" % self.server)
|
||||||
self.postCapabilities(self.deviceId)
|
|
||||||
|
|
||||||
def imageUrl(self, id, type, index, width, height):
|
def imageUrl(self, id, type, index, width, height):
|
||||||
# To move to API.py
|
# To move to API.py
|
||||||
|
@ -279,13 +278,14 @@ class DownloadUtils():
|
||||||
# Unauthorized
|
# Unauthorized
|
||||||
status = WINDOW.getProperty("Server_status")
|
status = WINDOW.getProperty("Server_status")
|
||||||
|
|
||||||
if r.headers['X-Application-Error-Code'] == "ParentalControl":
|
if 'x-application-error-code' in r.headers:
|
||||||
# Parental control - access restricted
|
if r.headers['X-Application-Error-Code'] == "ParentalControl":
|
||||||
WINDOW.setProperty("Server_status", "restricted")
|
# Parental control - access restricted
|
||||||
xbmcgui.Dialog().notification("Emby server", "Access restricted.", xbmcgui.NOTIFICATION_ERROR, time=5000)
|
WINDOW.setProperty("Server_status", "restricted")
|
||||||
return False
|
xbmcgui.Dialog().notification("Emby server", "Access restricted.", xbmcgui.NOTIFICATION_ERROR, time=5000)
|
||||||
|
return False
|
||||||
|
|
||||||
elif (status == "401") or (status == "Auth"):
|
if (status == "401") or (status == "Auth"):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
@ -293,6 +293,7 @@ class DownloadUtils():
|
||||||
WINDOW.setProperty("Server_status", "401")
|
WINDOW.setProperty("Server_status", "401")
|
||||||
self.logMsg("HTTP Error: %s" % e, 0)
|
self.logMsg("HTTP Error: %s" % e, 0)
|
||||||
xbmcgui.Dialog().notification("Error connecting", "Unauthorized.", xbmcgui.NOTIFICATION_ERROR)
|
xbmcgui.Dialog().notification("Error connecting", "Unauthorized.", xbmcgui.NOTIFICATION_ERROR)
|
||||||
|
return 401
|
||||||
|
|
||||||
elif (r.status_code == 301) or (r.status_code == 302):
|
elif (r.status_code == 301) or (r.status_code == 302):
|
||||||
# Redirects
|
# Redirects
|
||||||
|
|
|
@ -178,6 +178,9 @@ class UserClient(threading.Thread):
|
||||||
self.logMsg("Access is restricted.")
|
self.logMsg("Access is restricted.")
|
||||||
self.HasAccess = False
|
self.HasAccess = False
|
||||||
return
|
return
|
||||||
|
elif self.WINDOW.getProperty('Server_online') != "true":
|
||||||
|
# Server connection failed
|
||||||
|
return
|
||||||
|
|
||||||
if self.WINDOW.getProperty("Server_status") == "restricted":
|
if self.WINDOW.getProperty("Server_status") == "restricted":
|
||||||
self.logMsg("Access is granted.")
|
self.logMsg("Access is granted.")
|
||||||
|
@ -186,7 +189,7 @@ class UserClient(threading.Thread):
|
||||||
xbmcgui.Dialog().notification("Emby server", "Access is enabled.")
|
xbmcgui.Dialog().notification("Emby server", "Access is enabled.")
|
||||||
return
|
return
|
||||||
|
|
||||||
def loadCurrUser(self):
|
def loadCurrUser(self, authenticated=False):
|
||||||
|
|
||||||
WINDOW = self.WINDOW
|
WINDOW = self.WINDOW
|
||||||
doUtils = self.doUtils
|
doUtils = self.doUtils
|
||||||
|
@ -199,6 +202,17 @@ class UserClient(threading.Thread):
|
||||||
self.ssl = self.getSSLverify()
|
self.ssl = self.getSSLverify()
|
||||||
self.sslcert = self.getSSL()
|
self.sslcert = self.getSSL()
|
||||||
|
|
||||||
|
# Test the validity of current token
|
||||||
|
if authenticated == False:
|
||||||
|
url = "%s/mediabrowser/Users/%s" % (self.currServer, self.currUserId)
|
||||||
|
WINDOW.setProperty("currUser", username)
|
||||||
|
WINDOW.setProperty("accessToken%s" % username, self.currToken)
|
||||||
|
result = doUtils.downloadUrl(url, type="POST")
|
||||||
|
if result == 401:
|
||||||
|
# Token is no longer valid
|
||||||
|
self.resetClient()
|
||||||
|
return False
|
||||||
|
|
||||||
# Set to windows property
|
# Set to windows property
|
||||||
WINDOW.setProperty("currUser", username)
|
WINDOW.setProperty("currUser", username)
|
||||||
WINDOW.setProperty("accessToken%s" % username, self.currToken)
|
WINDOW.setProperty("accessToken%s" % username, self.currToken)
|
||||||
|
@ -212,6 +226,8 @@ class UserClient(threading.Thread):
|
||||||
doUtils.setServer(self.currServer)
|
doUtils.setServer(self.currServer)
|
||||||
doUtils.setToken(self.currToken)
|
doUtils.setToken(self.currToken)
|
||||||
doUtils.setSSL(self.ssl, self.sslcert)
|
doUtils.setSSL(self.ssl, self.sslcert)
|
||||||
|
# parental control - let's verify if access is restricted
|
||||||
|
self.hasAccess()
|
||||||
# Start DownloadUtils session
|
# Start DownloadUtils session
|
||||||
doUtils.startSession()
|
doUtils.startSession()
|
||||||
|
|
||||||
|
@ -239,13 +255,15 @@ class UserClient(threading.Thread):
|
||||||
return
|
return
|
||||||
# If there's a token
|
# If there's a token
|
||||||
if (self.getToken() != ""):
|
if (self.getToken() != ""):
|
||||||
self.loadCurrUser()
|
result = self.loadCurrUser()
|
||||||
self.logMsg("Current user: %s" % self.currUser, 0)
|
|
||||||
self.logMsg("Current userId: %s" % self.currUserId, 0)
|
if result == False:
|
||||||
self.logMsg("Current accessToken: %s" % self.currToken, 0)
|
pass
|
||||||
# parental control - let's verify if access is restricted
|
else:
|
||||||
self.hasAccess()
|
self.logMsg("Current user: %s" % self.currUser, 0)
|
||||||
return
|
self.logMsg("Current userId: %s" % self.currUserId, 0)
|
||||||
|
self.logMsg("Current accessToken: %s" % self.currToken, 0)
|
||||||
|
return
|
||||||
|
|
||||||
users = self.getPublicUsers()
|
users = self.getPublicUsers()
|
||||||
password = ""
|
password = ""
|
||||||
|
@ -292,11 +310,12 @@ class UserClient(threading.Thread):
|
||||||
|
|
||||||
if (result != None and accessToken != None):
|
if (result != None and accessToken != None):
|
||||||
self.currUser = username
|
self.currUser = username
|
||||||
|
xbmcgui.Dialog().notification("Emby server", "Welcome %s!" % self.currUser)
|
||||||
userId = result[u'User'][u'Id']
|
userId = result[u'User'][u'Id']
|
||||||
addon.setSetting("accessToken", accessToken)
|
addon.setSetting("accessToken", accessToken)
|
||||||
addon.setSetting("userId%s" % username, userId)
|
addon.setSetting("userId%s" % username, userId)
|
||||||
self.logMsg("User Authenticated: %s" % accessToken)
|
self.logMsg("User Authenticated: %s" % accessToken)
|
||||||
self.loadCurrUser()
|
self.loadCurrUser(authenticated=True)
|
||||||
self.WINDOW.setProperty("Server_status", "")
|
self.WINDOW.setProperty("Server_status", "")
|
||||||
self.retry = 0
|
self.retry = 0
|
||||||
return
|
return
|
||||||
|
@ -318,17 +337,19 @@ class UserClient(threading.Thread):
|
||||||
|
|
||||||
def resetClient(self):
|
def resetClient(self):
|
||||||
|
|
||||||
|
username = self.getUsername()
|
||||||
|
self.logMsg("Reset UserClient authentication.", 1)
|
||||||
if (self.currToken != None):
|
if (self.currToken != None):
|
||||||
# In case of 401, removed saved token
|
# In case of 401, removed saved token
|
||||||
self.addon.setSetting("accessToken%s" % self.currUser, "")
|
self.addon.setSetting("accessToken", "")
|
||||||
self.WINDOW.setProperty("accessToken%s" % self.currUser, "")
|
self.WINDOW.setProperty("accessToken%s" % username, "")
|
||||||
self.currToken = None
|
self.currToken = None
|
||||||
self.logMsg("User token has been removed.", 1)
|
self.logMsg("User token has been removed.", 1)
|
||||||
|
|
||||||
self.auth = True
|
self.auth = True
|
||||||
self.currUser = None
|
self.currUser = None
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,7 @@ class WebSocketThread(threading.Thread):
|
||||||
|
|
||||||
_shared_state = {}
|
_shared_state = {}
|
||||||
|
|
||||||
|
doUtils = DownloadUtils()
|
||||||
clientInfo = ClientInformation()
|
clientInfo = ClientInformation()
|
||||||
KodiMonitor = KodiMonitor.Kodi_Monitor()
|
KodiMonitor = KodiMonitor.Kodi_Monitor()
|
||||||
addonName = clientInfo.getAddonName()
|
addonName = clientInfo.getAddonName()
|
||||||
|
@ -258,10 +259,14 @@ class WebSocketThread(threading.Thread):
|
||||||
on_close = self.on_close)
|
on_close = self.on_close)
|
||||||
|
|
||||||
self.client.on_open = self.on_open
|
self.client.on_open = self.on_open
|
||||||
|
self.doUtils.postCapabilities(deviceId)
|
||||||
|
|
||||||
while not self.KodiMonitor.abortRequested():
|
while not self.KodiMonitor.abortRequested():
|
||||||
|
|
||||||
self.client.run_forever()
|
if WINDOW.getProperty("Server_online") == "true":
|
||||||
|
# Server came back online, repost capabilities
|
||||||
|
self.doUtils.postCapabilities(deviceId)
|
||||||
|
self.client.run_forever()
|
||||||
|
|
||||||
if (self.keepRunning):
|
if (self.keepRunning):
|
||||||
# Server is not online
|
# Server is not online
|
||||||
|
|
|
@ -143,7 +143,6 @@ class Service():
|
||||||
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
|
||||||
#WebSocketThread().processPendingActions()
|
|
||||||
else:
|
else:
|
||||||
|
|
||||||
if self.warn_auth:
|
if self.warn_auth:
|
||||||
|
@ -155,6 +154,10 @@ class Service():
|
||||||
WINDOW.setProperty("Emby_Service_Timestamp", str(int(time.time())))
|
WINDOW.setProperty("Emby_Service_Timestamp", str(int(time.time())))
|
||||||
user.hasAccess()
|
user.hasAccess()
|
||||||
|
|
||||||
|
if WINDOW.getProperty('Server_online') != "true":
|
||||||
|
# Server went offline
|
||||||
|
break
|
||||||
|
|
||||||
if self.KodiMonitor.waitForAbort(5):
|
if self.KodiMonitor.waitForAbort(5):
|
||||||
# Abort was requested while waiting. We should exit
|
# Abort was requested while waiting. We should exit
|
||||||
break
|
break
|
||||||
|
|
Loading…
Reference in a new issue