code reduce

This commit is contained in:
SpootDev 2016-03-31 14:39:32 -05:00
parent 44d0af0ad8
commit d915c4539e
2 changed files with 567 additions and 584 deletions

View file

@ -316,7 +316,7 @@ class UserClient(threading.Thread):
elif self.getToken():
result = self.loadCurrUser()
if result == False:
if result is False:
pass
else:
self.logMsg("Current user: %s" % self.currUser, 1)
@ -355,11 +355,10 @@ class UserClient(threading.Thread):
sha1 = sha1.hexdigest()
# Authenticate username and password
url = "%s/emby/Users/AuthenticateByName?format=json" % server
data = {'username': username, 'password': sha1}
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:
self.logMsg("Auth response: %s" % result, 1)
@ -373,9 +372,8 @@ class UserClient(threading.Thread):
self.currUser = username
dialog.notification("Emby for Kodi",
"%s %s!" % (lang(33000), self.currUser.decode('utf-8')))
userId = result['User']['Id']
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.loadCurrUser(authenticated=True)
window('emby_serverStatus', clear=True)
@ -399,12 +397,10 @@ class UserClient(threading.Thread):
def resetClient(self):
self.logMsg("Reset UserClient authentication.", 1)
userId = self.getUserId()
if self.currToken is not None:
# In case of 401, removed saved token
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.logMsg("User token has been removed.", 1)

View file

@ -62,26 +62,23 @@ def window(property, value=None, clear=False, windowid=10000):
def settings(setting, value=None):
# Get or add addon setting
addon = xbmcaddon.Addon(id='plugin.video.emby')
if value is not None:
addon.setSetting(setting, value)
xbmcaddon.Addon(id='plugin.video.metaman').setSetting(setting, value)
else:
return addon.getSetting(setting) #returns unicode object
return xbmcaddon.Addon(id='plugin.video.metaman').getSetting(setting) #returns unicode object
def language(stringid):
# Central string retrieval
addon = xbmcaddon.Addon(id='plugin.video.emby')
string = addon.getLocalizedString(stringid) #returns unicode object
string = xbmcaddon.Addon(id='plugin.video.emby').getLocalizedString(stringid) #returns unicode object
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')
elif type == "music":
elif media_type == "music":
dbPath = getKodiMusicDBPath()
elif type == "texture":
elif media_type == "texture":
dbPath = xbmc.translatePath("special://database/Textures13.db").decode('utf-8')
else:
dbPath = getKodiVideoDBPath()
@ -91,7 +88,6 @@ def kodiSQL(type="video"):
def getKodiVideoDBPath():
kodibuild = xbmc.getInfoLabel('System.BuildVersion')[:2]
dbVersion = {
"13": 78, # Gotham
@ -102,12 +98,11 @@ def getKodiVideoDBPath():
dbPath = xbmc.translatePath(
"special://database/MyVideos%s.db"
% dbVersion.get(kodibuild, "")).decode('utf-8')
% dbVersion.get(xbmc.getInfoLabel('System.BuildVersion')[:2], "")).decode('utf-8')
return dbPath
def getKodiMusicDBPath():
kodibuild = xbmc.getInfoLabel('System.BuildVersion')[:2]
dbVersion = {
"13": 46, # Gotham
@ -118,7 +113,7 @@ def getKodiMusicDBPath():
dbPath = xbmc.translatePath(
"special://database/MyMusic%s.db"
% dbVersion.get(kodibuild, "")).decode('utf-8')
% dbVersion.get(xbmc.getInfoLabel('System.BuildVersion')[:2], "")).decode('utf-8')
return dbPath
def getScreensaver():
@ -133,11 +128,7 @@ def getScreensaver():
'setting': "screensaver.mode"
}
}
result = xbmc.executeJSONRPC(json.dumps(query))
result = json.loads(result)
screensaver = result['result']['value']
return screensaver
return json.loads(xbmc.executeJSONRPC(json.dumps(query)))['result']['value']
def setScreensaver(value):
# Toggle the screensaver
@ -152,15 +143,13 @@ def setScreensaver(value):
'value': value
}
}
result = xbmc.executeJSONRPC(json.dumps(query))
logMsg("EMBY", "Toggling screensaver: %s %s" % (value, result), 1)
logMsg("EMBY", "Toggling screensaver: %s %s" % (value, xbmc.executeJSONRPC(json.dumps(query))), 1)
def reset():
dialog = xbmcgui.Dialog()
resp = dialog.yesno("Warning", "Are you sure you want to reset your local Kodi database?")
if resp == 0:
if dialog.yesno("Warning", "Are you sure you want to reset your local Kodi database?") == 0:
return
# first stop any db sync
@ -418,9 +407,7 @@ def passwordsXML():
elif option == 1:
# User selected remove
iterator = root.getiterator('passwords')
for paths in iterator:
for paths in root.getiterator('passwords'):
for path in paths:
if path.find('.//from').text == "smb://%s/" % credentials:
paths.remove(path)