mirror of
https://github.com/jellyfin/jellyfin-kodi.git
synced 2024-11-10 12:16:12 +00:00
code reduce
This commit is contained in:
parent
44d0af0ad8
commit
d915c4539e
2 changed files with 567 additions and 584 deletions
|
@ -316,7 +316,7 @@ class UserClient(threading.Thread):
|
||||||
elif self.getToken():
|
elif self.getToken():
|
||||||
result = self.loadCurrUser()
|
result = self.loadCurrUser()
|
||||||
|
|
||||||
if result == False:
|
if result is False:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
self.logMsg("Current user: %s" % self.currUser, 1)
|
self.logMsg("Current user: %s" % self.currUser, 1)
|
||||||
|
@ -355,11 +355,10 @@ class UserClient(threading.Thread):
|
||||||
sha1 = sha1.hexdigest()
|
sha1 = sha1.hexdigest()
|
||||||
|
|
||||||
# Authenticate username and password
|
# Authenticate username and password
|
||||||
url = "%s/emby/Users/AuthenticateByName?format=json" % server
|
|
||||||
data = {'username': username, 'password': sha1}
|
data = {'username': username, 'password': sha1}
|
||||||
self.logMsg(data, 2)
|
self.logMsg(data, 2)
|
||||||
|
|
||||||
result = self.doUtils.downloadUrl(url, postBody=data, type="POST", authenticate=False)
|
result = self.doUtils.downloadUrl("%s/emby/Users/AuthenticateByName?format=json" % server, postBody=data, type="POST", authenticate=False)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.logMsg("Auth response: %s" % result, 1)
|
self.logMsg("Auth response: %s" % result, 1)
|
||||||
|
@ -373,9 +372,8 @@ class UserClient(threading.Thread):
|
||||||
self.currUser = username
|
self.currUser = username
|
||||||
dialog.notification("Emby for Kodi",
|
dialog.notification("Emby for Kodi",
|
||||||
"%s %s!" % (lang(33000), self.currUser.decode('utf-8')))
|
"%s %s!" % (lang(33000), self.currUser.decode('utf-8')))
|
||||||
userId = result['User']['Id']
|
|
||||||
settings('accessToken', value=accessToken)
|
settings('accessToken', value=accessToken)
|
||||||
settings('userId%s' % username, value=userId)
|
settings('userId%s' % username, value=result['User']['Id'])
|
||||||
self.logMsg("User Authenticated: %s" % accessToken, 1)
|
self.logMsg("User Authenticated: %s" % accessToken, 1)
|
||||||
self.loadCurrUser(authenticated=True)
|
self.loadCurrUser(authenticated=True)
|
||||||
window('emby_serverStatus', clear=True)
|
window('emby_serverStatus', clear=True)
|
||||||
|
@ -399,12 +397,10 @@ class UserClient(threading.Thread):
|
||||||
def resetClient(self):
|
def resetClient(self):
|
||||||
|
|
||||||
self.logMsg("Reset UserClient authentication.", 1)
|
self.logMsg("Reset UserClient authentication.", 1)
|
||||||
userId = self.getUserId()
|
|
||||||
|
|
||||||
if self.currToken is not None:
|
if self.currToken is not None:
|
||||||
# In case of 401, removed saved token
|
# In case of 401, removed saved token
|
||||||
utils.settings('accessToken', value="")
|
utils.settings('accessToken', value="")
|
||||||
utils.window('emby_accessToken%s' % userId, clear=True)
|
utils.window('emby_accessToken%s' % self.getUserId(), clear=True)
|
||||||
self.currToken = None
|
self.currToken = None
|
||||||
self.logMsg("User token has been removed.", 1)
|
self.logMsg("User token has been removed.", 1)
|
||||||
|
|
||||||
|
|
|
@ -62,26 +62,23 @@ def window(property, value=None, clear=False, windowid=10000):
|
||||||
|
|
||||||
def settings(setting, value=None):
|
def settings(setting, value=None):
|
||||||
# Get or add addon setting
|
# Get or add addon setting
|
||||||
addon = xbmcaddon.Addon(id='plugin.video.emby')
|
|
||||||
|
|
||||||
if value is not None:
|
if value is not None:
|
||||||
addon.setSetting(setting, value)
|
xbmcaddon.Addon(id='plugin.video.metaman').setSetting(setting, value)
|
||||||
else:
|
else:
|
||||||
return addon.getSetting(setting) #returns unicode object
|
return xbmcaddon.Addon(id='plugin.video.metaman').getSetting(setting) #returns unicode object
|
||||||
|
|
||||||
def language(stringid):
|
def language(stringid):
|
||||||
# Central string retrieval
|
# Central string retrieval
|
||||||
addon = xbmcaddon.Addon(id='plugin.video.emby')
|
string = xbmcaddon.Addon(id='plugin.video.emby').getLocalizedString(stringid) #returns unicode object
|
||||||
string = addon.getLocalizedString(stringid) #returns unicode object
|
|
||||||
return string
|
return string
|
||||||
|
|
||||||
def kodiSQL(type="video"):
|
def kodiSQL(media_type="video"):
|
||||||
|
|
||||||
if type == "emby":
|
if media_type == "emby":
|
||||||
dbPath = xbmc.translatePath("special://database/emby.db").decode('utf-8')
|
dbPath = xbmc.translatePath("special://database/emby.db").decode('utf-8')
|
||||||
elif type == "music":
|
elif media_type == "music":
|
||||||
dbPath = getKodiMusicDBPath()
|
dbPath = getKodiMusicDBPath()
|
||||||
elif type == "texture":
|
elif media_type == "texture":
|
||||||
dbPath = xbmc.translatePath("special://database/Textures13.db").decode('utf-8')
|
dbPath = xbmc.translatePath("special://database/Textures13.db").decode('utf-8')
|
||||||
else:
|
else:
|
||||||
dbPath = getKodiVideoDBPath()
|
dbPath = getKodiVideoDBPath()
|
||||||
|
@ -91,7 +88,6 @@ def kodiSQL(type="video"):
|
||||||
|
|
||||||
def getKodiVideoDBPath():
|
def getKodiVideoDBPath():
|
||||||
|
|
||||||
kodibuild = xbmc.getInfoLabel('System.BuildVersion')[:2]
|
|
||||||
dbVersion = {
|
dbVersion = {
|
||||||
|
|
||||||
"13": 78, # Gotham
|
"13": 78, # Gotham
|
||||||
|
@ -102,12 +98,11 @@ def getKodiVideoDBPath():
|
||||||
|
|
||||||
dbPath = xbmc.translatePath(
|
dbPath = xbmc.translatePath(
|
||||||
"special://database/MyVideos%s.db"
|
"special://database/MyVideos%s.db"
|
||||||
% dbVersion.get(kodibuild, "")).decode('utf-8')
|
% dbVersion.get(xbmc.getInfoLabel('System.BuildVersion')[:2], "")).decode('utf-8')
|
||||||
return dbPath
|
return dbPath
|
||||||
|
|
||||||
def getKodiMusicDBPath():
|
def getKodiMusicDBPath():
|
||||||
|
|
||||||
kodibuild = xbmc.getInfoLabel('System.BuildVersion')[:2]
|
|
||||||
dbVersion = {
|
dbVersion = {
|
||||||
|
|
||||||
"13": 46, # Gotham
|
"13": 46, # Gotham
|
||||||
|
@ -118,7 +113,7 @@ def getKodiMusicDBPath():
|
||||||
|
|
||||||
dbPath = xbmc.translatePath(
|
dbPath = xbmc.translatePath(
|
||||||
"special://database/MyMusic%s.db"
|
"special://database/MyMusic%s.db"
|
||||||
% dbVersion.get(kodibuild, "")).decode('utf-8')
|
% dbVersion.get(xbmc.getInfoLabel('System.BuildVersion')[:2], "")).decode('utf-8')
|
||||||
return dbPath
|
return dbPath
|
||||||
|
|
||||||
def getScreensaver():
|
def getScreensaver():
|
||||||
|
@ -133,11 +128,7 @@ def getScreensaver():
|
||||||
'setting': "screensaver.mode"
|
'setting': "screensaver.mode"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
result = xbmc.executeJSONRPC(json.dumps(query))
|
return json.loads(xbmc.executeJSONRPC(json.dumps(query)))['result']['value']
|
||||||
result = json.loads(result)
|
|
||||||
screensaver = result['result']['value']
|
|
||||||
|
|
||||||
return screensaver
|
|
||||||
|
|
||||||
def setScreensaver(value):
|
def setScreensaver(value):
|
||||||
# Toggle the screensaver
|
# Toggle the screensaver
|
||||||
|
@ -152,15 +143,13 @@ def setScreensaver(value):
|
||||||
'value': value
|
'value': value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
result = xbmc.executeJSONRPC(json.dumps(query))
|
logMsg("EMBY", "Toggling screensaver: %s %s" % (value, xbmc.executeJSONRPC(json.dumps(query))), 1)
|
||||||
logMsg("EMBY", "Toggling screensaver: %s %s" % (value, result), 1)
|
|
||||||
|
|
||||||
def reset():
|
def reset():
|
||||||
|
|
||||||
dialog = xbmcgui.Dialog()
|
dialog = xbmcgui.Dialog()
|
||||||
|
|
||||||
resp = dialog.yesno("Warning", "Are you sure you want to reset your local Kodi database?")
|
if dialog.yesno("Warning", "Are you sure you want to reset your local Kodi database?") == 0:
|
||||||
if resp == 0:
|
|
||||||
return
|
return
|
||||||
|
|
||||||
# first stop any db sync
|
# first stop any db sync
|
||||||
|
@ -418,9 +407,7 @@ def passwordsXML():
|
||||||
|
|
||||||
elif option == 1:
|
elif option == 1:
|
||||||
# User selected remove
|
# User selected remove
|
||||||
iterator = root.getiterator('passwords')
|
for paths in root.getiterator('passwords'):
|
||||||
|
|
||||||
for paths in iterator:
|
|
||||||
for path in paths:
|
for path in paths:
|
||||||
if path.find('.//from').text == "smb://%s/" % credentials:
|
if path.find('.//from').text == "smb://%s/" % credentials:
|
||||||
paths.remove(path)
|
paths.remove(path)
|
||||||
|
|
Loading…
Reference in a new issue