Trying to change Plex.tv sign in process
This commit is contained in:
parent
79f95100c5
commit
1f8eb7f2ab
3 changed files with 38 additions and 29 deletions
|
@ -95,7 +95,7 @@ class Main:
|
||||||
xbmc.executebuiltin('Addon.OpenSettings(plugin.video.plexkodiconnect)')
|
xbmc.executebuiltin('Addon.OpenSettings(plugin.video.plexkodiconnect)')
|
||||||
if mode == "switchuser":
|
if mode == "switchuser":
|
||||||
xbmc.log('Requesting user switch')
|
xbmc.log('Requesting user switch')
|
||||||
userclient.UserClient().signUserOut()
|
utils.window('emby_serverStatus', value="401")
|
||||||
elif mode in ("manualsync", "repair"):
|
elif mode in ("manualsync", "repair"):
|
||||||
if utils.window('emby_dbScan') != "true":
|
if utils.window('emby_dbScan') != "true":
|
||||||
import librarysync
|
import librarysync
|
||||||
|
|
|
@ -181,14 +181,21 @@ class PlexAPI():
|
||||||
if 'plex.tv' in url:
|
if 'plex.tv' in url:
|
||||||
url = 'https://plex.tv/api/home/users'
|
url = 'https://plex.tv/api/home/users'
|
||||||
else:
|
else:
|
||||||
url = url + '/clients'
|
url = url + '/library/onDeck'
|
||||||
self.logMsg("CheckConnection called for url %s with a token" % url, 2)
|
|
||||||
|
|
||||||
|
if token:
|
||||||
|
self.logMsg("CheckConnection for %s with a token" % url, 0)
|
||||||
r = self.doUtils.downloadUrl(
|
r = self.doUtils.downloadUrl(
|
||||||
url,
|
url,
|
||||||
authenticate=False,
|
authenticate=False,
|
||||||
headerOptions={'X-Plex-Token': token}
|
headerOptions={'X-Plex-Token': token,
|
||||||
)
|
'Accept': 'application/json'})
|
||||||
|
else:
|
||||||
|
self.logMsg("CheckConnection for %s without a token" % url, 0)
|
||||||
|
r = self.doUtils.downloadUrl(
|
||||||
|
url,
|
||||||
|
authenticate=False,
|
||||||
|
headerOptions={'Accept': 'application/json'})
|
||||||
self.logMsg("Response was: %s" % r, 2)
|
self.logMsg("Response was: %s" % r, 2)
|
||||||
# List of exception returns, when connection failed
|
# List of exception returns, when connection failed
|
||||||
exceptionlist = [
|
exceptionlist = [
|
||||||
|
@ -886,7 +893,6 @@ class PlexAPI():
|
||||||
|
|
||||||
Will return empty strings if failed.
|
Will return empty strings if failed.
|
||||||
"""
|
"""
|
||||||
string = self.__language__
|
|
||||||
plexLogin = self.plexLogin
|
plexLogin = self.plexLogin
|
||||||
plexToken = self.plexToken
|
plexToken = self.plexToken
|
||||||
self.logMsg("Getting user list.", 1)
|
self.logMsg("Getting user list.", 1)
|
||||||
|
|
|
@ -47,16 +47,8 @@ class UserClient(threading.Thread):
|
||||||
self.addonName = clientinfo.ClientInfo().getAddonName()
|
self.addonName = clientinfo.ClientInfo().getAddonName()
|
||||||
self.doUtils = downloadutils.DownloadUtils()
|
self.doUtils = downloadutils.DownloadUtils()
|
||||||
|
|
||||||
self.signoutUser = threading.Event()
|
|
||||||
|
|
||||||
threading.Thread.__init__(self)
|
threading.Thread.__init__(self)
|
||||||
|
|
||||||
def signUserOut(self):
|
|
||||||
self.signoutUser.set()
|
|
||||||
|
|
||||||
def userSignedOut(self):
|
|
||||||
return self.signoutUser.isSet()
|
|
||||||
|
|
||||||
def logMsg(self, msg, lvl=1):
|
def logMsg(self, msg, lvl=1):
|
||||||
|
|
||||||
className = self.__class__.__name__
|
className = self.__class__.__name__
|
||||||
|
@ -283,6 +275,7 @@ class UserClient(threading.Thread):
|
||||||
|
|
||||||
def authenticate(self):
|
def authenticate(self):
|
||||||
# Get /profile/addon_data
|
# Get /profile/addon_data
|
||||||
|
plx = PlexAPI.PlexAPI()
|
||||||
addondir = xbmc.translatePath(self.addon.getAddonInfo('profile')).decode('utf-8')
|
addondir = xbmc.translatePath(self.addon.getAddonInfo('profile')).decode('utf-8')
|
||||||
hasSettings = xbmcvfs.exists("%ssettings.xml" % addondir)
|
hasSettings = xbmcvfs.exists("%ssettings.xml" % addondir)
|
||||||
|
|
||||||
|
@ -315,9 +308,15 @@ class UserClient(threading.Thread):
|
||||||
##### AUTHENTICATE USER #####
|
##### AUTHENTICATE USER #####
|
||||||
|
|
||||||
# Choose Plex user login
|
# Choose Plex user login
|
||||||
username, userId, accessToken = PlexAPI.PlexAPI().ChoosePlexHomeUser()
|
accessToken = ""
|
||||||
|
myplexlogin = utils.settings('myplexlogin')
|
||||||
if accessToken is not "":
|
if myplexlogin == "true":
|
||||||
|
username, userId, accessToken = plx.ChoosePlexHomeUser()
|
||||||
|
else:
|
||||||
|
# Try connecting without credentials
|
||||||
|
pass
|
||||||
|
# Check connection
|
||||||
|
if plx.CheckConnection(server, accessToken) == 200:
|
||||||
self.currUser = username
|
self.currUser = username
|
||||||
xbmcgui.Dialog().notification("Emby server", "Welcome %s!" % username)
|
xbmcgui.Dialog().notification("Emby server", "Welcome %s!" % username)
|
||||||
utils.settings('accessToken', value=accessToken)
|
utils.settings('accessToken', value=accessToken)
|
||||||
|
@ -330,7 +329,18 @@ class UserClient(threading.Thread):
|
||||||
self.logMsg("User authentication failed.", 1)
|
self.logMsg("User authentication failed.", 1)
|
||||||
utils.settings('accessToken', value="")
|
utils.settings('accessToken', value="")
|
||||||
utils.settings('userId%s' % username, value="")
|
utils.settings('userId%s' % username, value="")
|
||||||
self.retry = 0
|
|
||||||
|
# Give 3 attempts at entering password / selecting user
|
||||||
|
if self.retry == 3:
|
||||||
|
self.logMsg("""Too many retries. You can retry by resetting
|
||||||
|
attempts in the addon settings.""", 1)
|
||||||
|
utils.window('emby_serverStatus', value="Stop")
|
||||||
|
xbmcgui.Dialog().ok(
|
||||||
|
heading=self.addonName,
|
||||||
|
line1="Failed to authenticate too many times.",
|
||||||
|
line2="You can retry by resetting attempts in the addon "
|
||||||
|
"settings.")
|
||||||
|
self.retry += 1
|
||||||
self.auth = False
|
self.auth = False
|
||||||
|
|
||||||
def resetClient(self):
|
def resetClient(self):
|
||||||
|
@ -365,13 +375,6 @@ class UserClient(threading.Thread):
|
||||||
utils.window('emby_serverStatus', value="Auth")
|
utils.window('emby_serverStatus', value="Auth")
|
||||||
self.resetClient()
|
self.resetClient()
|
||||||
|
|
||||||
if self.userSignedOut():
|
|
||||||
# Check whether another thread wanted to sign out user
|
|
||||||
self.logMsg("User sign out requested", 0)
|
|
||||||
self.resetClient()
|
|
||||||
# Reset threading event
|
|
||||||
self.signoutUser.clear()
|
|
||||||
|
|
||||||
if self.auth and (self.currUser is None):
|
if self.auth and (self.currUser is None):
|
||||||
# Try to authenticate user
|
# Try to authenticate user
|
||||||
status = utils.window('emby_serverStatus')
|
status = utils.window('emby_serverStatus')
|
||||||
|
|
Loading…
Add table
Reference in a new issue