Support Parental control - access schedule
I had to reorganize the service.py loop a bit for this to work. Logically the top level inside the while loop should be if the user is authenticated.
This commit is contained in:
parent
a3b500061a
commit
354f0905f6
3 changed files with 83 additions and 48 deletions
|
@ -265,8 +265,16 @@ class DownloadUtils():
|
||||||
if r.status_code == 401:
|
if r.status_code == 401:
|
||||||
# Unauthorized
|
# Unauthorized
|
||||||
status = WINDOW.getProperty("Server_status")
|
status = WINDOW.getProperty("Server_status")
|
||||||
if (status == "401") or (status == "Auth"):
|
|
||||||
|
if r.headers['X-Application-Error-Code'] == "ParentalControl":
|
||||||
|
# Parental control - access restricted
|
||||||
|
WINDOW.setProperty("Server_status", "restricted")
|
||||||
|
xbmcgui.Dialog().notification("Emby server", "Access restricted.", xbmcgui.NOTIFICATION_ERROR)
|
||||||
|
return False
|
||||||
|
|
||||||
|
elif (status == "401") or (status == "Auth"):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# Tell UserClient token has been revoked.
|
# Tell UserClient token has been revoked.
|
||||||
WINDOW.setProperty("Server_status", "401")
|
WINDOW.setProperty("Server_status", "401")
|
||||||
|
|
|
@ -40,6 +40,7 @@ class UserClient(threading.Thread):
|
||||||
currUserId = None
|
currUserId = None
|
||||||
currServer = None
|
currServer = None
|
||||||
currToken = None
|
currToken = None
|
||||||
|
HasAccess = True
|
||||||
AdditionalUser = []
|
AdditionalUser = []
|
||||||
|
|
||||||
def __init__(self, *args):
|
def __init__(self, *args):
|
||||||
|
@ -167,6 +168,24 @@ class UserClient(threading.Thread):
|
||||||
|
|
||||||
return users
|
return users
|
||||||
|
|
||||||
|
def hasAccess(self):
|
||||||
|
|
||||||
|
url = "{server}/mediabrowser/Users"
|
||||||
|
result = self.doUtils.downloadUrl(url)
|
||||||
|
|
||||||
|
if result is False:
|
||||||
|
# Access is restricted
|
||||||
|
self.logMsg("Access is restricted.")
|
||||||
|
self.HasAccess = False
|
||||||
|
return
|
||||||
|
|
||||||
|
if self.WINDOW.getProperty("Server_status") == "restricted":
|
||||||
|
self.logMsg("Access is granted.")
|
||||||
|
self.HasAccess = True
|
||||||
|
self.WINDOW.setProperty("Server_status", "")
|
||||||
|
xbmcgui.Dialog().notification("Emby server", "Access is enabled.")
|
||||||
|
return
|
||||||
|
|
||||||
def loadCurrUser(self):
|
def loadCurrUser(self):
|
||||||
|
|
||||||
WINDOW = self.WINDOW
|
WINDOW = self.WINDOW
|
||||||
|
@ -224,6 +243,8 @@ class UserClient(threading.Thread):
|
||||||
self.logMsg("Current user: %s" % self.currUser, 0)
|
self.logMsg("Current user: %s" % self.currUser, 0)
|
||||||
self.logMsg("Current userId: %s" % self.currUserId, 0)
|
self.logMsg("Current userId: %s" % self.currUserId, 0)
|
||||||
self.logMsg("Current accessToken: %s" % self.currToken, 0)
|
self.logMsg("Current accessToken: %s" % self.currToken, 0)
|
||||||
|
# parental control - let's verify if access is restricted
|
||||||
|
self.hasAccess()
|
||||||
return
|
return
|
||||||
|
|
||||||
users = self.getPublicUsers()
|
users = self.getPublicUsers()
|
||||||
|
@ -320,7 +341,12 @@ class UserClient(threading.Thread):
|
||||||
|
|
||||||
if (self.WINDOW.getProperty("Server_status") != ""):
|
if (self.WINDOW.getProperty("Server_status") != ""):
|
||||||
status = self.WINDOW.getProperty("Server_status")
|
status = self.WINDOW.getProperty("Server_status")
|
||||||
if status == "401":
|
|
||||||
|
if status == "restricted":
|
||||||
|
# Parental control is restricting access
|
||||||
|
self.HasAccess = False
|
||||||
|
|
||||||
|
elif status == "401":
|
||||||
self.WINDOW.setProperty("Server_status", "Auth")
|
self.WINDOW.setProperty("Server_status", "Auth")
|
||||||
# Revoked token
|
# Revoked token
|
||||||
self.resetClient()
|
self.resetClient()
|
||||||
|
|
21
service.py
21
service.py
|
@ -88,6 +88,14 @@ class Service():
|
||||||
|
|
||||||
if WINDOW.getProperty('Server_online') == "true":
|
if WINDOW.getProperty('Server_online') == "true":
|
||||||
# Server is online
|
# Server is online
|
||||||
|
if (user.currUser != None) and (user.HasAccess == True):
|
||||||
|
self.warn_auth = True
|
||||||
|
|
||||||
|
# Correctly launch the websocket, if user manually launches the add-on
|
||||||
|
if (self.newWebSocketThread == None):
|
||||||
|
self.newWebSocketThread = "Started"
|
||||||
|
ws.start()
|
||||||
|
|
||||||
if xbmc.Player().isPlaying():
|
if xbmc.Player().isPlaying():
|
||||||
try:
|
try:
|
||||||
playTime = xbmc.Player().getTime()
|
playTime = xbmc.Player().getTime()
|
||||||
|
@ -120,16 +128,8 @@ class Service():
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
self.logMsg("Exception in Playback Monitor Service: %s" % e)
|
self.logMsg("Exception in Playback Monitor Service: %s" % e)
|
||||||
pass
|
pass
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# background worker for database sync
|
|
||||||
if (user.currUser != None):
|
|
||||||
self.warn_auth = True
|
|
||||||
|
|
||||||
# Correctly launch the websocket, if user manually launches the add-on
|
|
||||||
if (self.newWebSocketThread == None):
|
|
||||||
self.newWebSocketThread = "Started"
|
|
||||||
ws.start()
|
|
||||||
|
|
||||||
#full sync
|
#full sync
|
||||||
if (startupComplete == False):
|
if (startupComplete == False):
|
||||||
self.logMsg("Doing_Db_Sync: syncDatabase (Started)")
|
self.logMsg("Doing_Db_Sync: syncDatabase (Started)")
|
||||||
|
@ -143,11 +143,12 @@ class Service():
|
||||||
# Abort was requested while waiting. We should exit
|
# Abort was requested while waiting. We should exit
|
||||||
break
|
break
|
||||||
#WebSocketThread().processPendingActions()
|
#WebSocketThread().processPendingActions()
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
user.hasAccess()
|
||||||
if self.warn_auth:
|
if self.warn_auth:
|
||||||
self.logMsg("Not authenticated yet.", 1)
|
self.logMsg("Not authenticated yet.", 1)
|
||||||
self.warn_auth = False
|
self.warn_auth = False
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# Wait until server becomes online or shut down is requested
|
# Wait until server becomes online or shut down is requested
|
||||||
while not self.KodiMonitor.abortRequested():
|
while not self.KodiMonitor.abortRequested():
|
||||||
|
|
Loading…
Reference in a new issue