self.log
This commit is contained in:
parent
8a130fe810
commit
2748d21ff4
1 changed files with 479 additions and 486 deletions
|
@ -81,7 +81,6 @@ class UserClient(threading.Thread):
|
|||
|
||||
def getUserId(self):
|
||||
|
||||
log = self.logMsg
|
||||
window = utils.window
|
||||
settings = utils.settings
|
||||
|
||||
|
@ -94,17 +93,17 @@ class UserClient(threading.Thread):
|
|||
if not s_userId:
|
||||
# Save access token if it's missing from settings
|
||||
settings('userId%s' % username, value=w_userId)
|
||||
log("Returning userId from WINDOW for username: %s UserId: %s"
|
||||
self.logMsg("Returning userId from WINDOW for username: %s UserId: %s"
|
||||
% (username, w_userId), 2)
|
||||
return w_userId
|
||||
# Verify the settings
|
||||
elif s_userId:
|
||||
log("Returning userId from SETTINGS for username: %s userId: %s"
|
||||
self.logMsg("Returning userId from SETTINGS for username: %s userId: %s"
|
||||
% (username, s_userId), 2)
|
||||
return s_userId
|
||||
# No userId found
|
||||
else:
|
||||
log("No userId saved for username: %s." % username, 1)
|
||||
self.logMsg("No userId saved for username: %s." % username, 1)
|
||||
|
||||
def getServer(self, prefix=True):
|
||||
|
||||
|
@ -142,7 +141,6 @@ class UserClient(threading.Thread):
|
|||
|
||||
def getToken(self):
|
||||
|
||||
log = self.logMsg
|
||||
window = utils.window
|
||||
settings = utils.settings
|
||||
|
||||
|
@ -156,17 +154,17 @@ class UserClient(threading.Thread):
|
|||
if not s_token:
|
||||
# Save access token if it's missing from settings
|
||||
settings('accessToken', value=w_token)
|
||||
log("Returning accessToken from WINDOW for username: %s accessToken: %s"
|
||||
self.logMsg("Returning accessToken from WINDOW for username: %s accessToken: %s"
|
||||
% (username, w_token), 2)
|
||||
return w_token
|
||||
# Verify the settings
|
||||
elif s_token:
|
||||
log("Returning accessToken from SETTINGS for username: %s accessToken: %s"
|
||||
self.logMsg("Returning accessToken from SETTINGS for username: %s accessToken: %s"
|
||||
% (username, s_token), 2)
|
||||
window('emby_accessToken%s' % username, value=s_token)
|
||||
return s_token
|
||||
else:
|
||||
log("No token found.", 1)
|
||||
self.logMsg("No token found.", 1)
|
||||
return ""
|
||||
|
||||
def getSSLverify(self):
|
||||
|
@ -229,7 +227,6 @@ class UserClient(threading.Thread):
|
|||
|
||||
def hasAccess(self):
|
||||
# hasAccess is verified in service.py
|
||||
log = self.logMsg
|
||||
window = utils.window
|
||||
|
||||
url = "{server}/emby/Users?format=json"
|
||||
|
@ -237,7 +234,7 @@ class UserClient(threading.Thread):
|
|||
|
||||
if result == False:
|
||||
# Access is restricted, set in downloadutils.py via exception
|
||||
log("Access is restricted.", 1)
|
||||
self.logMsg("Access is restricted.", 1)
|
||||
self.HasAccess = False
|
||||
|
||||
elif window('emby_online') != "true":
|
||||
|
@ -245,7 +242,7 @@ class UserClient(threading.Thread):
|
|||
pass
|
||||
|
||||
elif window('emby_serverStatus') == "restricted":
|
||||
log("Access is granted.", 1)
|
||||
self.logMsg("Access is granted.", 1)
|
||||
self.HasAccess = True
|
||||
window('emby_serverStatus', clear=True)
|
||||
xbmcgui.Dialog().notification("Emby for Kodi", utils.language(33007))
|
||||
|
@ -301,7 +298,6 @@ class UserClient(threading.Thread):
|
|||
|
||||
def authenticate(self):
|
||||
|
||||
log = self.logMsg
|
||||
lang = utils.language
|
||||
window = utils.window
|
||||
settings = utils.settings
|
||||
|
@ -316,12 +312,12 @@ class UserClient(threading.Thread):
|
|||
|
||||
# If there's no settings.xml
|
||||
if not hasSettings:
|
||||
log("No settings.xml found.", 1)
|
||||
self.logMsg("No settings.xml found.", 1)
|
||||
self.auth = False
|
||||
return
|
||||
# If no user information
|
||||
elif not server or not username:
|
||||
log("Missing server information.", 1)
|
||||
self.logMsg("Missing server information.", 1)
|
||||
self.auth = False
|
||||
return
|
||||
# If there's a token, load the user
|
||||
|
@ -331,9 +327,9 @@ class UserClient(threading.Thread):
|
|||
if result == False:
|
||||
pass
|
||||
else:
|
||||
log("Current user: %s" % self.currUser, 1)
|
||||
log("Current userId: %s" % self.currUserId, 1)
|
||||
log("Current accessToken: %s" % self.currToken, 2)
|
||||
self.logMsg("Current user: %s" % self.currUser, 1)
|
||||
self.logMsg("Current userId: %s" % self.currUserId, 1)
|
||||
self.logMsg("Current accessToken: %s" % self.currToken, 2)
|
||||
return
|
||||
|
||||
##### AUTHENTICATE USER #####
|
||||
|
@ -353,7 +349,7 @@ class UserClient(threading.Thread):
|
|||
option=xbmcgui.ALPHANUM_HIDE_INPUT)
|
||||
# If password dialog is cancelled
|
||||
if not password:
|
||||
log("No password entered.", 0)
|
||||
self.logMsg("No password entered.", 0)
|
||||
window('emby_serverStatus', value="Stop")
|
||||
self.auth = False
|
||||
return
|
||||
|
@ -369,16 +365,16 @@ class UserClient(threading.Thread):
|
|||
# Authenticate username and password
|
||||
url = "%s/emby/Users/AuthenticateByName?format=json" % server
|
||||
data = {'username': username, 'password': sha1}
|
||||
log(data, 2)
|
||||
self.logMsg(data, 2)
|
||||
|
||||
result = self.doUtils.downloadUrl(url, postBody=data, type="POST", authenticate=False)
|
||||
|
||||
try:
|
||||
log("Auth response: %s" % result, 1)
|
||||
self.logMsg("Auth response: %s" % result, 1)
|
||||
accessToken = result['AccessToken']
|
||||
|
||||
except (KeyError, TypeError):
|
||||
log("Failed to retrieve the api key.", 1)
|
||||
self.logMsg("Failed to retrieve the api key.", 1)
|
||||
accessToken = None
|
||||
|
||||
if accessToken is not None:
|
||||
|
@ -388,19 +384,19 @@ class UserClient(threading.Thread):
|
|||
userId = result['User']['Id']
|
||||
settings('accessToken', value=accessToken)
|
||||
settings('userId%s' % username, value=userId)
|
||||
log("User Authenticated: %s" % accessToken, 1)
|
||||
self.logMsg("User Authenticated: %s" % accessToken, 1)
|
||||
self.loadCurrUser(authenticated=True)
|
||||
window('emby_serverStatus', clear=True)
|
||||
self.retry = 0
|
||||
else:
|
||||
log("User authentication failed.", 1)
|
||||
self.logMsg("User authentication failed.", 1)
|
||||
settings('accessToken', value="")
|
||||
settings('userId%s' % username, value="")
|
||||
dialog.ok(lang(33001), lang(33009))
|
||||
|
||||
# Give two attempts at entering password
|
||||
if self.retry == 2:
|
||||
log("Too many retries. "
|
||||
self.logMsg("Too many retries. "
|
||||
"You can retry by resetting attempts in the addon settings.", 1)
|
||||
window('emby_serverStatus', value="Stop")
|
||||
dialog.ok(lang(33001), lang(33010))
|
||||
|
@ -410,9 +406,7 @@ class UserClient(threading.Thread):
|
|||
|
||||
def resetClient(self):
|
||||
|
||||
log = self.logMsg
|
||||
|
||||
log("Reset UserClient authentication.", 1)
|
||||
self.logMsg("Reset UserClient authentication.", 1)
|
||||
userId = self.getUserId()
|
||||
|
||||
if self.currToken is not None:
|
||||
|
@ -420,18 +414,17 @@ class UserClient(threading.Thread):
|
|||
utils.settings('accessToken', value="")
|
||||
utils.window('emby_accessToken%s' % userId, clear=True)
|
||||
self.currToken = None
|
||||
log("User token has been removed.", 1)
|
||||
self.logMsg("User token has been removed.", 1)
|
||||
|
||||
self.auth = True
|
||||
self.currUser = None
|
||||
|
||||
def run(self):
|
||||
|
||||
log = self.logMsg
|
||||
window = utils.window
|
||||
|
||||
monitor = xbmc.Monitor()
|
||||
log("----===## Starting UserClient ##===----", 0)
|
||||
self.logMsg("----===## Starting UserClient ##===----", 0)
|
||||
|
||||
while not monitor.abortRequested():
|
||||
|
||||
|
@ -466,8 +459,8 @@ class UserClient(threading.Thread):
|
|||
# The status Stop is for when user cancelled password dialog.
|
||||
if server and username and status != "Stop":
|
||||
# Only if there's information found to login
|
||||
log("Server found: %s" % server, 2)
|
||||
log("Username found: %s" % username, 2)
|
||||
self.logMsg("Server found: %s" % server, 2)
|
||||
self.logMsg("Username found: %s" % username, 2)
|
||||
self.auth = True
|
||||
|
||||
|
||||
|
@ -480,7 +473,7 @@ class UserClient(threading.Thread):
|
|||
break
|
||||
|
||||
self.doUtils.stopSession()
|
||||
log("##===---- UserClient Stopped ----===##", 0)
|
||||
self.logMsg("##===---- UserClient Stopped ----===##", 0)
|
||||
|
||||
def stopClient(self):
|
||||
# When emby for kodi terminates
|
||||
|
|
Loading…
Reference in a new issue