Enable non-ASCI PMS server name and username
This commit is contained in:
parent
75a2fac4cc
commit
c6503f8a8e
5 changed files with 92 additions and 86 deletions
|
@ -79,7 +79,6 @@ class PlexAPI():
|
||||||
self.deviceName = client.getDeviceName()
|
self.deviceName = client.getDeviceName()
|
||||||
self.plexversion = client.getVersion()
|
self.plexversion = client.getVersion()
|
||||||
self.platform = client.getPlatform()
|
self.platform = client.getPlatform()
|
||||||
self.user = utils.window('plex_username')
|
|
||||||
self.userId = utils.window('emby_currUser')
|
self.userId = utils.window('emby_currUser')
|
||||||
self.token = utils.window('emby_accessToken%s' % self.userId)
|
self.token = utils.window('emby_accessToken%s' % self.userId)
|
||||||
self.server = utils.window('emby_server%s' % self.userId)
|
self.server = utils.window('emby_server%s' % self.userId)
|
||||||
|
@ -95,13 +94,15 @@ class PlexAPI():
|
||||||
'plexid': utils.settings('plexid'),
|
'plexid': utils.settings('plexid'),
|
||||||
'myplexlogin': utils.settings('myplexlogin')
|
'myplexlogin': utils.settings('myplexlogin')
|
||||||
|
|
||||||
|
plexLogin is unicode or empty unicode string u''
|
||||||
|
|
||||||
Returns empty strings '' for a setting if not found.
|
Returns empty strings '' for a setting if not found.
|
||||||
|
|
||||||
myplexlogin is 'true' if user opted to log into plex.tv (the default)
|
myplexlogin is 'true' if user opted to log into plex.tv (the default)
|
||||||
plexhome is 'true' if plex home is used (the default)
|
plexhome is 'true' if plex home is used (the default)
|
||||||
"""
|
"""
|
||||||
return {
|
return {
|
||||||
'plexLogin': utils.settings('plexLogin'),
|
'plexLogin': utils.settings('plexLogin').decode('utf-8'),
|
||||||
'plexToken': utils.settings('plexToken'),
|
'plexToken': utils.settings('plexToken'),
|
||||||
'plexhome': utils.settings('plexhome'),
|
'plexhome': utils.settings('plexhome'),
|
||||||
'plexid': utils.settings('plexid'),
|
'plexid': utils.settings('plexid'),
|
||||||
|
@ -127,32 +128,31 @@ class PlexAPI():
|
||||||
retrievedPlexLogin = ''
|
retrievedPlexLogin = ''
|
||||||
plexLogin = 'dummy'
|
plexLogin = 'dummy'
|
||||||
authtoken = ''
|
authtoken = ''
|
||||||
|
dialog = xbmcgui.Dialog()
|
||||||
while retrievedPlexLogin == '' and plexLogin != '':
|
while retrievedPlexLogin == '' and plexLogin != '':
|
||||||
dialog = xbmcgui.Dialog()
|
|
||||||
# Enter plex.tv username. Or nothing to cancel.
|
# Enter plex.tv username. Or nothing to cancel.
|
||||||
plexLogin = dialog.input(
|
plexLogin = dialog.input(
|
||||||
self.addonName + string(39300),
|
self.addonName.encode('utf-8') + string(39300).encode('utf-8'),
|
||||||
type=xbmcgui.INPUT_ALPHANUM,
|
type=xbmcgui.INPUT_ALPHANUM,
|
||||||
)
|
)
|
||||||
if plexLogin != "":
|
if plexLogin != "":
|
||||||
dialog = xbmcgui.Dialog()
|
|
||||||
# Enter password for plex.tv user
|
# Enter password for plex.tv user
|
||||||
plexPassword = dialog.input(
|
plexPassword = dialog.input(
|
||||||
string(39301) + plexLogin,
|
string(39301).encode('utf-8') + plexLogin.encode('utf-8'),
|
||||||
type=xbmcgui.INPUT_ALPHANUM,
|
type=xbmcgui.INPUT_ALPHANUM,
|
||||||
option=xbmcgui.ALPHANUM_HIDE_INPUT
|
option=xbmcgui.ALPHANUM_HIDE_INPUT
|
||||||
)
|
)
|
||||||
retrievedPlexLogin, authtoken = self.MyPlexSignIn(
|
retrievedPlexLogin, authtoken = self.MyPlexSignIn(
|
||||||
plexLogin,
|
plexLogin,
|
||||||
plexPassword,
|
plexPassword,
|
||||||
{'X-Plex-Client-Identifier': self.clientId}
|
{'X-Plex-Client-Identifier': self.clientId})
|
||||||
)
|
|
||||||
self.logMsg("plex.tv username and token: %s, %s"
|
self.logMsg("plex.tv username and token: %s, %s"
|
||||||
% (plexLogin, authtoken), 1)
|
% (plexLogin, authtoken), 1)
|
||||||
if plexLogin == '':
|
if plexLogin == '':
|
||||||
dialog = xbmcgui.Dialog()
|
|
||||||
# Could not sign in user
|
# Could not sign in user
|
||||||
dialog.ok(self.addonName, string(39302) + plexLogin)
|
dialog.ok(self.addonName,
|
||||||
|
string(39302).encode('utf-8')
|
||||||
|
+ plexLogin.encode('utf-8'))
|
||||||
# Write to Kodi settings file
|
# Write to Kodi settings file
|
||||||
utils.settings('plexLogin', value=retrievedPlexLogin)
|
utils.settings('plexLogin', value=retrievedPlexLogin)
|
||||||
utils.settings('plexToken', value=authtoken)
|
utils.settings('plexToken', value=authtoken)
|
||||||
|
@ -177,12 +177,12 @@ class PlexAPI():
|
||||||
dialog = xbmcgui.Dialog()
|
dialog = xbmcgui.Dialog()
|
||||||
if not code:
|
if not code:
|
||||||
# Problems trying to contact plex.tv. Try again later
|
# Problems trying to contact plex.tv. Try again later
|
||||||
dialog.ok(self.addonName, string(39303))
|
dialog.ok(self.addonName, string(39303).encode('utf-8'))
|
||||||
return False
|
return False
|
||||||
# Go to https://plex.tv/pin and enter the code:
|
# Go to https://plex.tv/pin and enter the code:
|
||||||
answer = dialog.yesno(self.addonName,
|
answer = dialog.yesno(self.addonName,
|
||||||
string(39304) + "\n\n",
|
(string(39304) + "\n\n").encode('utf-8'),
|
||||||
code)
|
code.encode('utf-8'))
|
||||||
if not answer:
|
if not answer:
|
||||||
return False
|
return False
|
||||||
count = 0
|
count = 0
|
||||||
|
@ -196,7 +196,7 @@ class PlexAPI():
|
||||||
count += 1
|
count += 1
|
||||||
if not xml:
|
if not xml:
|
||||||
# Could not sign in to plex.tv Try again later
|
# Could not sign in to plex.tv Try again later
|
||||||
dialog.ok(self.addonName, string(39305))
|
dialog.ok(self.addonName, string(39305).encode('utf-8'))
|
||||||
return False
|
return False
|
||||||
# Parse xml
|
# Parse xml
|
||||||
userid = xml.attrib.get('id')
|
userid = xml.attrib.get('id')
|
||||||
|
@ -259,11 +259,11 @@ class PlexAPI():
|
||||||
try:
|
try:
|
||||||
code = xml.find('code').text
|
code = xml.find('code').text
|
||||||
identifier = xml.find('id').text
|
identifier = xml.find('id').text
|
||||||
|
self.logMsg('Successfully retrieved code and id from plex.tv', 1)
|
||||||
|
return code, identifier
|
||||||
except:
|
except:
|
||||||
self.logMsg("Error, no PIN from plex.tv provided", -1)
|
self.logMsg("Error, no PIN from plex.tv provided", -1)
|
||||||
self.logMsg("plex.tv/pin: Code is: %s" % code, 2)
|
return None, None
|
||||||
self.logMsg("plex.tv/pin: Identifier is: %s" % identifier, 2)
|
|
||||||
return code, identifier
|
|
||||||
|
|
||||||
def TalkToPlexServer(self, url, talkType="GET", verify=True, token=None):
|
def TalkToPlexServer(self, url, talkType="GET", verify=True, token=None):
|
||||||
"""
|
"""
|
||||||
|
@ -814,7 +814,6 @@ class PlexAPI():
|
||||||
'X-Plex-Version': self.plexversion,
|
'X-Plex-Version': self.plexversion,
|
||||||
'X-Plex-Client-Identifier': self.clientId,
|
'X-Plex-Client-Identifier': self.clientId,
|
||||||
'X-Plex-Provides': 'player',
|
'X-Plex-Provides': 'player',
|
||||||
'X-Plex-Username': self.user,
|
|
||||||
'X-Plex-Client-Capabilities': 'protocols=shoutcast,http-video;videoDecoders=h264{profile:high&resolution:1080&level:51};audioDecoders=mp3,aac,dts{bitrate:800000&channels:8},ac3{bitrate:800000&channels:8}',
|
'X-Plex-Client-Capabilities': 'protocols=shoutcast,http-video;videoDecoders=h264{profile:high&resolution:1080&level:51};audioDecoders=mp3,aac,dts{bitrate:800000&channels:8},ac3{bitrate:800000&channels:8}',
|
||||||
'X-Plex-Client-Profile-Extra': 'add-transcode-target-audio-codec(type=videoProfile&context=streaming&protocol=*&audioCodec=dca,ac3)',
|
'X-Plex-Client-Profile-Extra': 'add-transcode-target-audio-codec(type=videoProfile&context=streaming&protocol=*&audioCodec=dca,ac3)',
|
||||||
}
|
}
|
||||||
|
@ -1042,6 +1041,8 @@ class PlexAPI():
|
||||||
self.logMsg("No URL for user avatar.", 1)
|
self.logMsg("No URL for user avatar.", 1)
|
||||||
return False
|
return False
|
||||||
for user in users:
|
for user in users:
|
||||||
|
self.logMsg('type user: %s, type username: %s'
|
||||||
|
% (type(user['title']), type(username)))
|
||||||
if username in user['title']:
|
if username in user['title']:
|
||||||
url = user['thumb']
|
url = user['thumb']
|
||||||
self.logMsg("Avatar url for user %s is: %s" % (username, url), 1)
|
self.logMsg("Avatar url for user %s is: %s" % (username, url), 1)
|
||||||
|
@ -1060,6 +1061,7 @@ class PlexAPI():
|
||||||
Will return empty strings if failed.
|
Will return empty strings if failed.
|
||||||
"""
|
"""
|
||||||
string = self.__language__
|
string = self.__language__
|
||||||
|
dialog = xbmcgui.Dialog()
|
||||||
|
|
||||||
plexLogin = utils.settings('plexLogin')
|
plexLogin = utils.settings('plexLogin')
|
||||||
plexToken = utils.settings('plexToken')
|
plexToken = utils.settings('plexToken')
|
||||||
|
@ -1074,19 +1076,21 @@ class PlexAPI():
|
||||||
return ('', '', '')
|
return ('', '', '')
|
||||||
|
|
||||||
userlist = []
|
userlist = []
|
||||||
|
userlistCoded = []
|
||||||
for user in users:
|
for user in users:
|
||||||
username = user['title']
|
username = user['title']
|
||||||
userlist.append(username)
|
userlist.append(username)
|
||||||
|
userlistCoded.append(username.encode('utf-8'))
|
||||||
usernumber = len(userlist)
|
usernumber = len(userlist)
|
||||||
usertoken = ''
|
usertoken = ''
|
||||||
# Plex home not in use: only 1 user returned
|
# Plex home not in use: only 1 user returned
|
||||||
trials = 0
|
trials = 0
|
||||||
while trials < 3:
|
while trials < 3:
|
||||||
if usernumber > 1:
|
if usernumber > 1:
|
||||||
dialog = xbmcgui.Dialog()
|
|
||||||
# Select user
|
# Select user
|
||||||
user_select = dialog.select(self.addonName + string(39306),
|
user_select = dialog.select(
|
||||||
userlist)
|
(self.addonName + string(39306)).encode('utf-8'),
|
||||||
|
userlistCoded)
|
||||||
if user_select == -1:
|
if user_select == -1:
|
||||||
self.logMsg("No user selected.", 1)
|
self.logMsg("No user selected.", 1)
|
||||||
xbmc.executebuiltin('Addon.OpenSettings(%s)'
|
xbmc.executebuiltin('Addon.OpenSettings(%s)'
|
||||||
|
@ -1101,11 +1105,10 @@ class PlexAPI():
|
||||||
user = users[user_select]
|
user = users[user_select]
|
||||||
# Ask for PIN, if protected:
|
# Ask for PIN, if protected:
|
||||||
if user['protected'] == '1':
|
if user['protected'] == '1':
|
||||||
dialog = xbmcgui.Dialog()
|
|
||||||
# Please enter pin for user
|
# Please enter pin for user
|
||||||
self.logMsg('Asking for users PIN', 1)
|
self.logMsg('Asking for users PIN', 1)
|
||||||
pin = dialog.input(
|
pin = dialog.input(
|
||||||
string(39307) + selected_user,
|
(string(39307) + selected_user).encode('utf-8'),
|
||||||
type=xbmcgui.INPUT_NUMERIC,
|
type=xbmcgui.INPUT_NUMERIC,
|
||||||
option=xbmcgui.ALPHANUM_HIDE_INPUT)
|
option=xbmcgui.ALPHANUM_HIDE_INPUT)
|
||||||
# User chose to cancel
|
# User chose to cancel
|
||||||
|
@ -1122,12 +1125,11 @@ class PlexAPI():
|
||||||
)
|
)
|
||||||
# Couldn't get user auth
|
# Couldn't get user auth
|
||||||
if not username:
|
if not username:
|
||||||
dialog = xbmcgui.Dialog()
|
|
||||||
# Could not login user, please try again
|
# Could not login user, please try again
|
||||||
if not dialog.yesno(
|
if not dialog.yesno(
|
||||||
self.addonName,
|
self.addonName,
|
||||||
string(39308) + selected_user,
|
(string(39308) + selected_user).encode('utf-8'),
|
||||||
string(39309)
|
string(39309).encode('utf-8')
|
||||||
):
|
):
|
||||||
# User chose to cancel
|
# User chose to cancel
|
||||||
break
|
break
|
||||||
|
@ -1188,7 +1190,7 @@ class PlexAPI():
|
||||||
self.logMsg("username: %s, token: xxxx. "
|
self.logMsg("username: %s, token: xxxx. "
|
||||||
"Saving to window and file settings" % username, 0)
|
"Saving to window and file settings" % username, 0)
|
||||||
utils.window('emby_currUser', value=userId)
|
utils.window('emby_currUser', value=userId)
|
||||||
utils.settings('userId%s' % username, value=userId)
|
utils.settings('userId', value=userId)
|
||||||
utils.settings('username', value=username)
|
utils.settings('username', value=username)
|
||||||
utils.window('emby_accessToken%s' % userId, value=token)
|
utils.window('emby_accessToken%s' % userId, value=token)
|
||||||
return (username, token)
|
return (username, token)
|
||||||
|
@ -1411,7 +1413,6 @@ class API():
|
||||||
self.part = 0
|
self.part = 0
|
||||||
self.clientinfo = clientinfo.ClientInfo()
|
self.clientinfo = clientinfo.ClientInfo()
|
||||||
self.clientId = self.clientinfo.getDeviceId()
|
self.clientId = self.clientinfo.getDeviceId()
|
||||||
self.user = utils.window('plex_username')
|
|
||||||
self.userId = utils.window('emby_currUser')
|
self.userId = utils.window('emby_currUser')
|
||||||
self.server = utils.window('emby_server%s' % self.userId)
|
self.server = utils.window('emby_server%s' % self.userId)
|
||||||
self.token = utils.window('emby_accessToken%s' % self.userId)
|
self.token = utils.window('emby_accessToken%s' % self.userId)
|
||||||
|
|
|
@ -20,10 +20,6 @@ import PlexAPI
|
||||||
class InitialSetup():
|
class InitialSetup():
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
|
||||||
self.addon = xbmcaddon.Addon()
|
|
||||||
self.__language__ = self.addon.getLocalizedString
|
|
||||||
|
|
||||||
self.clientInfo = clientinfo.ClientInfo()
|
self.clientInfo = clientinfo.ClientInfo()
|
||||||
self.addonId = self.clientInfo.getAddonId()
|
self.addonId = self.clientInfo.getAddonId()
|
||||||
self.doUtils = downloadutils.DownloadUtils()
|
self.doUtils = downloadutils.DownloadUtils()
|
||||||
|
@ -36,7 +32,7 @@ class InitialSetup():
|
||||||
Check server, user, direct paths, music, direct stream if not direct
|
Check server, user, direct paths, music, direct stream if not direct
|
||||||
path.
|
path.
|
||||||
"""
|
"""
|
||||||
string = self.__language__
|
string = xbmcaddon.Addon().getLocalizedString
|
||||||
# SERVER INFO #####
|
# SERVER INFO #####
|
||||||
self.logMsg("Initial setup called.", 0)
|
self.logMsg("Initial setup called.", 0)
|
||||||
server = self.userClient.getServer()
|
server = self.userClient.getServer()
|
||||||
|
@ -63,7 +59,7 @@ class InitialSetup():
|
||||||
# Could not login, please try again
|
# Could not login, please try again
|
||||||
dialog.ok(
|
dialog.ok(
|
||||||
self.addonName,
|
self.addonName,
|
||||||
string(39009)
|
string(39009).encode('utf-8')
|
||||||
)
|
)
|
||||||
result = self.plx.PlexTvSignInWithPin()
|
result = self.plx.PlexTvSignInWithPin()
|
||||||
if result:
|
if result:
|
||||||
|
@ -74,7 +70,7 @@ class InitialSetup():
|
||||||
# Problems connecting to plex.tv. Network or internet issue?
|
# Problems connecting to plex.tv. Network or internet issue?
|
||||||
dialog.ok(
|
dialog.ok(
|
||||||
self.addonName,
|
self.addonName,
|
||||||
string(39010)
|
string(39010).encode('utf-8')
|
||||||
)
|
)
|
||||||
# If a Plex server IP has already been set, return.
|
# If a Plex server IP has already been set, return.
|
||||||
if server and forcePlexTV is False:
|
if server and forcePlexTV is False:
|
||||||
|
@ -110,18 +106,18 @@ class InitialSetup():
|
||||||
if len(serverlist) == 0:
|
if len(serverlist) == 0:
|
||||||
dialog.ok(
|
dialog.ok(
|
||||||
self.addonName,
|
self.addonName,
|
||||||
string(39011)
|
string(39011).encode('utf-8')
|
||||||
)
|
)
|
||||||
break
|
break
|
||||||
for server in serverlist:
|
for server in serverlist:
|
||||||
if server['local'] == '1':
|
if server['local'] == '1':
|
||||||
# server is in the same network as client. Add "local"
|
# server is in the same network as client. Add "local"
|
||||||
dialoglist.append(str(server['name']) + string(39022))
|
dialoglist.append(
|
||||||
|
server['name'].encode('utf-8')
|
||||||
|
+ string(39022).encode('utf-8'))
|
||||||
else:
|
else:
|
||||||
dialoglist.append(str(server['name']))
|
dialoglist.append(server['name'].encode('utf-8'))
|
||||||
resp = dialog.select(
|
resp = dialog.select(string(39012).encode('utf-8'), dialoglist)
|
||||||
string(39012),
|
|
||||||
dialoglist)
|
|
||||||
server = serverlist[resp]
|
server = serverlist[resp]
|
||||||
activeServer = server['machineIdentifier']
|
activeServer = server['machineIdentifier']
|
||||||
url = server['scheme'] + '://' + server['ip'] + ':' + \
|
url = server['scheme'] + '://' + server['ip'] + ':' + \
|
||||||
|
@ -141,8 +137,9 @@ class InitialSetup():
|
||||||
# Not yet authorized for Plex server
|
# Not yet authorized for Plex server
|
||||||
# Please sign in to plex.tv
|
# Please sign in to plex.tv
|
||||||
dialog.ok(self.addonName,
|
dialog.ok(self.addonName,
|
||||||
string(39013) + str(server['name']),
|
string(39013).encode('utf-8')
|
||||||
string(39014))
|
+ server['name'].encode('utf-8'),
|
||||||
|
string(39014).encode('utf-8'))
|
||||||
result = self.plx.PlexTvSignInWithPin()
|
result = self.plx.PlexTvSignInWithPin()
|
||||||
if result:
|
if result:
|
||||||
plexLogin = result['username']
|
plexLogin = result['username']
|
||||||
|
@ -154,7 +151,8 @@ class InitialSetup():
|
||||||
# Problems connecting
|
# Problems connecting
|
||||||
elif chk >= 400 or chk is False:
|
elif chk >= 400 or chk is False:
|
||||||
# Problems connecting to server. Pick another server?
|
# Problems connecting to server. Pick another server?
|
||||||
resp = dialog.yesno(self.addonName, string(39015))
|
resp = dialog.yesno(self.addonName,
|
||||||
|
string(39015).encode('utf-8'))
|
||||||
# Exit while loop if user chooses No
|
# Exit while loop if user chooses No
|
||||||
if not resp:
|
if not resp:
|
||||||
break
|
break
|
||||||
|
@ -166,7 +164,7 @@ class InitialSetup():
|
||||||
# Enter Kodi settings instead
|
# Enter Kodi settings instead
|
||||||
if dialog.yesno(
|
if dialog.yesno(
|
||||||
heading=self.addonName,
|
heading=self.addonName,
|
||||||
line1=string(39016)):
|
line1=string(39016).encode('utf-8')):
|
||||||
self.logMsg("User opted to disable Plex music library.", 1)
|
self.logMsg("User opted to disable Plex music library.", 1)
|
||||||
utils.settings('enableMusic', value="false")
|
utils.settings('enableMusic', value="false")
|
||||||
xbmc.executebuiltin('Addon.OpenSettings(%s)' % self.addonId)
|
xbmc.executebuiltin('Addon.OpenSettings(%s)' % self.addonId)
|
||||||
|
@ -202,12 +200,12 @@ class InitialSetup():
|
||||||
|
|
||||||
if dialog.yesno(
|
if dialog.yesno(
|
||||||
heading=self.addonName,
|
heading=self.addonName,
|
||||||
line1=string(39016)):
|
line1=string(39016).encode('utf-8')):
|
||||||
self.logMsg("User opted to disable Plex music library.", 1)
|
self.logMsg("User opted to disable Plex music library.", 1)
|
||||||
utils.settings('enableMusic', value="false")
|
utils.settings('enableMusic', value="false")
|
||||||
|
|
||||||
if dialog.yesno(
|
if dialog.yesno(
|
||||||
heading=self.addonName,
|
heading=self.addonName,
|
||||||
line1=string(39017)):
|
line1=string(39017).encode('utf-8')):
|
||||||
xbmc.executebuiltin(
|
xbmc.executebuiltin(
|
||||||
'Addon.OpenSettings(plugin.video.plexkodiconnect)')
|
'Addon.OpenSettings(plugin.video.plexkodiconnect)')
|
||||||
|
|
|
@ -54,12 +54,15 @@ class UserClient(threading.Thread):
|
||||||
self.AdditionalUser = additionalUsers.split(',')
|
self.AdditionalUser = additionalUsers.split(',')
|
||||||
|
|
||||||
def getUsername(self):
|
def getUsername(self):
|
||||||
|
"""
|
||||||
|
Returns username as unicode
|
||||||
|
"""
|
||||||
|
|
||||||
username = utils.settings('username')
|
username = utils.settings('username').decode('utf-8')
|
||||||
|
|
||||||
if not username:
|
if not username:
|
||||||
self.logMsg("No username saved, trying to get Plex username", 0)
|
self.logMsg("No username saved, trying to get Plex username", 0)
|
||||||
username = utils.settings('plexLogin')
|
username = utils.settings('plexLogin').decode('utf-8')
|
||||||
if not username:
|
if not username:
|
||||||
self.logMsg("Also no Plex username found", 0)
|
self.logMsg("Also no Plex username found", 0)
|
||||||
return ""
|
return ""
|
||||||
|
@ -84,33 +87,31 @@ class UserClient(threading.Thread):
|
||||||
if username is None:
|
if username is None:
|
||||||
username = self.getUsername()
|
username = self.getUsername()
|
||||||
w_userId = window('emby_currUser')
|
w_userId = window('emby_currUser')
|
||||||
s_userId = settings('userId%s' % username)
|
s_userId = settings('userId')
|
||||||
|
|
||||||
# Verify the window property
|
# Verify the window property
|
||||||
if w_userId:
|
if w_userId:
|
||||||
if not s_userId:
|
if not s_userId:
|
||||||
# Save access token if it's missing from settings
|
# Save access token if it's missing from settings
|
||||||
settings('userId%s' % username, value=w_userId)
|
settings('userId', value=w_userId)
|
||||||
log("Returning userId from WINDOW for username: %s UserId: %s"
|
log("Returning userId %s from WINDOW for username %s"
|
||||||
% (username, w_userId), 1)
|
% (w_userId, username), 0)
|
||||||
return w_userId
|
return w_userId
|
||||||
# Verify the settings
|
# Verify the settings
|
||||||
elif s_userId:
|
elif s_userId:
|
||||||
log("Returning userId from SETTINGS for username: %s userId: %s"
|
log("Returning userId %s from SETTINGS for username %s"
|
||||||
% (username, s_userId), 1)
|
% (w_userId, username), 0)
|
||||||
return s_userId
|
return s_userId
|
||||||
# No userId found
|
# No userId found
|
||||||
else:
|
log("No userId saved. Trying to get Plex to use instead", 0)
|
||||||
log("No userId saved for username: %s. Trying to get Plex ID"
|
plexId = settings('plexid')
|
||||||
% username, 0)
|
if not plexId:
|
||||||
plexId = settings('plexid')
|
log('Also no Plex ID found in settings', 0)
|
||||||
if not plexId:
|
return ''
|
||||||
log('Also no Plex ID found in settings', 0)
|
log('Using Plex ID %s as userid for username %s'
|
||||||
return ''
|
% (plexId, username), 0)
|
||||||
log('Using Plex ID %s as userid for username: %s'
|
settings('userId', value=plexId)
|
||||||
% (plexId, username))
|
return plexId
|
||||||
settings('userId%s' % username, value=plexId)
|
|
||||||
return plexId
|
|
||||||
|
|
||||||
def getServer(self, prefix=True):
|
def getServer(self, prefix=True):
|
||||||
|
|
||||||
|
@ -157,14 +158,14 @@ class UserClient(threading.Thread):
|
||||||
if not s_token:
|
if not s_token:
|
||||||
# Save access token if it's missing from settings
|
# Save access token if it's missing from settings
|
||||||
settings('accessToken', value=w_token)
|
settings('accessToken', value=w_token)
|
||||||
log("Returning accessToken from WINDOW for username: %s accessToken: %s"
|
log("Returning accessToken from WINDOW for username: %s "
|
||||||
% (username, w_token), 2)
|
"accessToken: xxxx" % username, 2)
|
||||||
return w_token
|
return w_token
|
||||||
# Verify the settings
|
# Verify the settings
|
||||||
elif s_token:
|
elif s_token:
|
||||||
log("Returning accessToken from SETTINGS for username: %s accessToken: %s"
|
log("Returning accessToken from SETTINGS for username: %s "
|
||||||
% (username, s_token), 2)
|
"accessToken: xxxx" % username, 2)
|
||||||
window('emby_accessToken%s' % username, value=s_token)
|
window('emby_accessToken%s' % userId, value=s_token)
|
||||||
return s_token
|
return s_token
|
||||||
else:
|
else:
|
||||||
log("No token found.", 1)
|
log("No token found.", 1)
|
||||||
|
@ -244,7 +245,9 @@ class UserClient(threading.Thread):
|
||||||
log("Access is granted.", 1)
|
log("Access is granted.", 1)
|
||||||
self.HasAccess = True
|
self.HasAccess = True
|
||||||
window('emby_serverStatus', clear=True)
|
window('emby_serverStatus', clear=True)
|
||||||
xbmcgui.Dialog().notification(self.addonName, utils.language(33007))
|
xbmcgui.Dialog().notification(
|
||||||
|
self.addonName,
|
||||||
|
utils.language(33007).encode('utf-8'))
|
||||||
|
|
||||||
def loadCurrUser(self, authenticated=False):
|
def loadCurrUser(self, authenticated=False):
|
||||||
self.logMsg('Loading current user', 0)
|
self.logMsg('Loading current user', 0)
|
||||||
|
@ -284,7 +287,6 @@ class UserClient(threading.Thread):
|
||||||
window('plex_username', value=username)
|
window('plex_username', value=username)
|
||||||
window('emby_accessToken%s' % userId, value=self.currToken)
|
window('emby_accessToken%s' % userId, value=self.currToken)
|
||||||
window('emby_server%s' % userId, value=self.currServer)
|
window('emby_server%s' % userId, value=self.currServer)
|
||||||
window('emby_server_%s' % userId, value=self.getServer(prefix=False))
|
|
||||||
window('plex_machineIdentifier', value=self.machineIdentifier)
|
window('plex_machineIdentifier', value=self.machineIdentifier)
|
||||||
|
|
||||||
window('emby_serverStatus', clear=True)
|
window('emby_serverStatus', clear=True)
|
||||||
|
@ -359,9 +361,8 @@ class UserClient(threading.Thread):
|
||||||
# Check connection
|
# Check connection
|
||||||
if plx.CheckConnection(server, accessToken) == 200:
|
if plx.CheckConnection(server, accessToken) == 200:
|
||||||
self.currUser = username
|
self.currUser = username
|
||||||
dialog = xbmcgui.Dialog()
|
|
||||||
settings('accessToken', value=accessToken)
|
settings('accessToken', value=accessToken)
|
||||||
settings('userId%s' % username, value=userId)
|
settings('userId', value=userId)
|
||||||
log("User authenticated with an access token", 1)
|
log("User authenticated with an access token", 1)
|
||||||
if self.loadCurrUser(authenticated=True) is False:
|
if self.loadCurrUser(authenticated=True) is False:
|
||||||
# Something went really wrong, return and try again
|
# Something went really wrong, return and try again
|
||||||
|
@ -372,7 +373,7 @@ class UserClient(threading.Thread):
|
||||||
if username:
|
if username:
|
||||||
dialog.notification(
|
dialog.notification(
|
||||||
heading=self.addonName,
|
heading=self.addonName,
|
||||||
message="Welcome %s" % username.decode('utf-8'),
|
message=("Welcome " + username).encode('utf-8'),
|
||||||
icon="special://home/addons/plugin.video.plexkodiconnect/icon.png")
|
icon="special://home/addons/plugin.video.plexkodiconnect/icon.png")
|
||||||
else:
|
else:
|
||||||
dialog.notification(
|
dialog.notification(
|
||||||
|
@ -384,13 +385,14 @@ class UserClient(threading.Thread):
|
||||||
else:
|
else:
|
||||||
self.logMsg("Error: user authentication failed.", -1)
|
self.logMsg("Error: user authentication failed.", -1)
|
||||||
settings('accessToken', value="")
|
settings('accessToken', value="")
|
||||||
settings('userId%s' % username, value="")
|
settings('userId', value="")
|
||||||
|
|
||||||
# Give attempts at entering password / selecting user
|
# Give attempts at entering password / selecting user
|
||||||
if self.retry >= 5:
|
if self.retry >= 5:
|
||||||
log("Too many retries.", 1)
|
log("Too many retries.", 1)
|
||||||
window('emby_serverStatus', value="Stop")
|
window('emby_serverStatus', value="Stop")
|
||||||
dialog.ok(lang(33001), lang(39023))
|
dialog.ok(lang(33001).encode('utf-8'),
|
||||||
|
lang(39023).encode('utf-8'))
|
||||||
xbmc.executebuiltin(
|
xbmc.executebuiltin(
|
||||||
'Addon.OpenSettings(plugin.video.plexkodiconnect)')
|
'Addon.OpenSettings(plugin.video.plexkodiconnect)')
|
||||||
|
|
||||||
|
|
|
@ -210,10 +210,15 @@ def window(property, value=None, clear=False, windowid=10000):
|
||||||
# Takes unicode or string by default!
|
# Takes unicode or string by default!
|
||||||
WINDOW.setProperty(property, value)
|
WINDOW.setProperty(property, value)
|
||||||
else: #getproperty returns string so convert to unicode
|
else: #getproperty returns string so convert to unicode
|
||||||
return unicode(WINDOW.getProperty(property))
|
return WINDOW.getProperty(property)
|
||||||
|
|
||||||
def settings(setting, value=None):
|
def settings(setting, value=None):
|
||||||
# Get or add addon setting
|
"""
|
||||||
|
Get or add addon setting.
|
||||||
|
|
||||||
|
Settings needs to be string
|
||||||
|
Value can either be unicode or string
|
||||||
|
"""
|
||||||
addon = xbmcaddon.Addon(id='plugin.video.plexkodiconnect')
|
addon = xbmcaddon.Addon(id='plugin.video.plexkodiconnect')
|
||||||
|
|
||||||
if value is not None:
|
if value is not None:
|
||||||
|
|
10
service.py
10
service.py
|
@ -172,8 +172,8 @@ class Service():
|
||||||
xbmcgui.Dialog().notification(
|
xbmcgui.Dialog().notification(
|
||||||
heading=self.addonName,
|
heading=self.addonName,
|
||||||
message=("%s %s"
|
message=("%s %s"
|
||||||
% (lang(33000),
|
% (lang(33000).encode('utf-8'),
|
||||||
user.currUser.decode('utf-8'))),
|
user.currUser.encode('utf-8'))),
|
||||||
icon="special://home/addons/plugin.video.plexkodiconnect/icon.png",
|
icon="special://home/addons/plugin.video.plexkodiconnect/icon.png",
|
||||||
time=2000,
|
time=2000,
|
||||||
sound=False)
|
sound=False)
|
||||||
|
@ -226,8 +226,8 @@ class Service():
|
||||||
window('emby_online', value="false")
|
window('emby_online', value="false")
|
||||||
|
|
||||||
xbmcgui.Dialog().notification(
|
xbmcgui.Dialog().notification(
|
||||||
heading=lang(33001),
|
heading=lang(33001).encode('utf-8'),
|
||||||
message="%s %s" % (self.addonName, lang(33002)),
|
message="%s %s" % (self.addonName, lang(33002).encode('utf-8')),
|
||||||
icon="special://home/addons/plugin.video."
|
icon="special://home/addons/plugin.video."
|
||||||
"plexkodiconnect/icon.png",
|
"plexkodiconnect/icon.png",
|
||||||
sound=False)
|
sound=False)
|
||||||
|
@ -245,7 +245,7 @@ class Service():
|
||||||
# Alert the user that server is online.
|
# Alert the user that server is online.
|
||||||
xbmcgui.Dialog().notification(
|
xbmcgui.Dialog().notification(
|
||||||
heading=self.addonName,
|
heading=self.addonName,
|
||||||
message=lang(33003),
|
message=lang(33003).encode('utf-8'),
|
||||||
icon="special://home/addons/plugin.video."
|
icon="special://home/addons/plugin.video."
|
||||||
"plexkodiconnect/icon.png",
|
"plexkodiconnect/icon.png",
|
||||||
time=2000,
|
time=2000,
|
||||||
|
|
Loading…
Reference in a new issue