mirror of
https://github.com/jellyfin/jellyfin-kodi.git
synced 2024-11-10 04:06:11 +00:00
Added verification from WINDOW
This also include preparations for http/https support.
This commit is contained in:
parent
972d48688c
commit
e4ad9bb3c2
1 changed files with 100 additions and 14 deletions
|
@ -1,12 +1,12 @@
|
||||||
################################################################
|
#######################################################################
|
||||||
# CLIENTINFORMATION: centralized client data
|
# CLIENTINFORMATION: centralized client data
|
||||||
# -------------------------------
|
# -------------------------------
|
||||||
# addonId, addon version, clientId, platform
|
# addonId, addonName, addon version, clientId, platform
|
||||||
################################################################
|
#######################################################################
|
||||||
# USER: centralized Userdata
|
# USER: centralized Userdata
|
||||||
# -------------------------------
|
# -------------------------------
|
||||||
# username, userId, token, server, Loglvl
|
# username, userId, token, server, http prefix, LogLevel
|
||||||
################################################################
|
#######################################################################
|
||||||
|
|
||||||
import xbmc
|
import xbmc
|
||||||
import xbmcaddon
|
import xbmcaddon
|
||||||
|
@ -20,12 +20,40 @@ class ClientInformation():
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
addonId = self.getAddonId()
|
addonId = self.getAddonId()
|
||||||
self.addon = xbmcaddon.Addon(id=addonId)
|
self.addon = xbmcaddon.Addon(id=addonId)
|
||||||
|
self.WINDOW = xbmcgui.Window( 10000 )
|
||||||
|
|
||||||
|
level = User().getLogLevel()
|
||||||
|
self.logLevel = 0
|
||||||
|
|
||||||
|
if (level != None and level != ""):
|
||||||
|
self.logLevel = int(level)
|
||||||
|
|
||||||
|
if (self.logLevel == 2):
|
||||||
|
self.LogCalls = True
|
||||||
|
|
||||||
|
def logMsg(self, msg, level = 1):
|
||||||
|
|
||||||
|
addonName = self.getAddonName()
|
||||||
|
className = self.__class__.__name__
|
||||||
|
|
||||||
|
if (self.logLevel >= level):
|
||||||
|
try:
|
||||||
|
xbmc.log("%s %s -> %s" % (addonName, className, str(msg)))
|
||||||
|
except UnicodeEncodeError:
|
||||||
|
try:
|
||||||
|
xbmc.log("%s %s -> %s" % (addonName, className, str(msg.encode('utf-8'))))
|
||||||
|
except: pass
|
||||||
|
|
||||||
def getAddonId(self):
|
def getAddonId(self):
|
||||||
# To use when declaring xbmcaddon.Addon(id=addonId)
|
# To use when declaring xbmcaddon.Addon(id=addonId)
|
||||||
addonId = "plugin.video.mb3sync"
|
addonId = "plugin.video.mb3sync"
|
||||||
return addonId
|
return addonId
|
||||||
|
|
||||||
|
def getAddonName(self):
|
||||||
|
# Useful for logging
|
||||||
|
addonName = self.addon.getAddonInfo('name').upper()
|
||||||
|
return addonName
|
||||||
|
|
||||||
def getVersion(self):
|
def getVersion(self):
|
||||||
|
|
||||||
version = self.addon.getAddonInfo('version')
|
version = self.addon.getAddonInfo('version')
|
||||||
|
@ -33,7 +61,7 @@ class ClientInformation():
|
||||||
|
|
||||||
def getMachineId(self):
|
def getMachineId(self):
|
||||||
|
|
||||||
WINDOW = xbmcgui.Window( 10000 )
|
WINDOW = self.WINDOW
|
||||||
|
|
||||||
clientId = WINDOW.getProperty("client_id")
|
clientId = WINDOW.getProperty("client_id")
|
||||||
if(clientId != None and clientId != ""):
|
if(clientId != None and clientId != ""):
|
||||||
|
@ -58,13 +86,13 @@ class ClientInformation():
|
||||||
if(len(clientId) == 0):
|
if(len(clientId) == 0):
|
||||||
uuid = uuid4()
|
uuid = uuid4()
|
||||||
clientId = str("%012X" % uuid)
|
clientId = str("%012X" % uuid)
|
||||||
xbmc.log("CLIENT_ID - > Client ID saved to FILE : " + clientId)
|
self.logMsg("ClientId saved to FILE : %s" % clientId)
|
||||||
os.write(fd, clientId)
|
os.write(fd, clientId)
|
||||||
os.fsync(fd)
|
os.fsync(fd)
|
||||||
|
|
||||||
os.close(fd)
|
os.close(fd)
|
||||||
|
|
||||||
xbmc.log("CLIENT_ID - > Client ID saved to WINDOW : " + clientId)
|
self.logMsg("ClientId saved to WINDOW : %s" % clientId)
|
||||||
WINDOW.setProperty("client_id", clientId)
|
WINDOW.setProperty("client_id", clientId)
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
|
@ -95,6 +123,29 @@ class User(ClientInformation):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
addonId = self.getAddonId()
|
addonId = self.getAddonId()
|
||||||
self.addon = xbmcaddon.Addon(id=addonId)
|
self.addon = xbmcaddon.Addon(id=addonId)
|
||||||
|
self.WINDOW = xbmcgui.Window( 10000 )
|
||||||
|
|
||||||
|
level = self.getLogLevel()
|
||||||
|
self.logLevel = 0
|
||||||
|
|
||||||
|
if (level != None and level != ""):
|
||||||
|
self.logLevel = int(level)
|
||||||
|
|
||||||
|
if (self.logLevel == 2):
|
||||||
|
self.LogCalls = True
|
||||||
|
|
||||||
|
def logMsg(self, msg, level = 1):
|
||||||
|
|
||||||
|
addonName = ClientInformation().getAddonName()
|
||||||
|
className = self.__class__.__name__
|
||||||
|
|
||||||
|
if (self.logLevel >= level):
|
||||||
|
try:
|
||||||
|
xbmc.log("%s %s -> %s" % (addonName, className, str(msg)))
|
||||||
|
except UnicodeEncodeError:
|
||||||
|
try:
|
||||||
|
xbmc.log("%s %s -> %s" % (addonName, className, str(msg.encode('utf-8'))))
|
||||||
|
except: pass
|
||||||
|
|
||||||
def getUsername(self):
|
def getUsername(self):
|
||||||
|
|
||||||
|
@ -103,13 +154,40 @@ class User(ClientInformation):
|
||||||
|
|
||||||
def getUserId(self):
|
def getUserId(self):
|
||||||
|
|
||||||
userId = self.addon.getSetting('userId')
|
username = self.getUsername()
|
||||||
return userId
|
w_userId = self.WINDOW.getProperty('userId%s' % username)
|
||||||
|
s_userId = self.addon.getSetting('userId%s' % username)
|
||||||
|
|
||||||
|
# Verify if userId is saved to Window
|
||||||
|
if (w_userId != ""):
|
||||||
|
self.logMsg("Returning saved (WINDOW) UserId for user: %s UserId: %s" % (username, w_userId))
|
||||||
|
return w_userId
|
||||||
|
# Verify if userId is saved in settings
|
||||||
|
elif (s_userId != ""):
|
||||||
|
self.logMsg("Returning saved (SETTINGS) UserId for user: %s UserId: %s" % (username, s_userId))
|
||||||
|
self.WINDOW.setProperty('userId%s' % username, s_userId)
|
||||||
|
return s_userId
|
||||||
|
else:
|
||||||
|
return ""
|
||||||
|
|
||||||
def getToken(self):
|
def getToken(self):
|
||||||
|
|
||||||
token = self.addon.getSetting('token')
|
username = self.getUsername()
|
||||||
return token
|
w_token = self.WINDOW.getProperty('AccessToken%s' % username)
|
||||||
|
s_token = self.addon.getSetting('AccessToken%s' % username)
|
||||||
|
|
||||||
|
# Verify if token is saved to Window
|
||||||
|
if (w_token != ""):
|
||||||
|
self.logMsg("Returning saved (WINDOW) AccessToken for user: %s Token: %s" % (username, w_token))
|
||||||
|
return w_token
|
||||||
|
# Verify if token is saved in settings
|
||||||
|
elif (s_token != ""):
|
||||||
|
self.logMsg("Returning saved (SETTINGS) AccessToken for user: %s Token: %s" % (username, s_token))
|
||||||
|
self.WINDOW.setProperty('AccessToken%s' % username, s_token)
|
||||||
|
return s_token
|
||||||
|
else:
|
||||||
|
self.logMsg("User is not authenticated.")
|
||||||
|
return ""
|
||||||
|
|
||||||
def getServer(self):
|
def getServer(self):
|
||||||
|
|
||||||
|
@ -117,7 +195,15 @@ class User(ClientInformation):
|
||||||
port = self.addon.getSetting('port')
|
port = self.addon.getSetting('port')
|
||||||
return host + ":" + port
|
return host + ":" + port
|
||||||
|
|
||||||
def getLoglvl(self):
|
def getHTTPprefix(self):
|
||||||
|
# For https support
|
||||||
|
prefix = self.addon.getSetting('prefix')
|
||||||
|
if prefix:
|
||||||
|
return "https://"
|
||||||
|
else:
|
||||||
|
return "http://"
|
||||||
|
|
||||||
level = self.addon.getSetting('loglevel')
|
def getLogLevel(self):
|
||||||
|
|
||||||
|
level = self.addon.getSetting('logLevel')
|
||||||
return level
|
return level
|
||||||
|
|
Loading…
Reference in a new issue