Trying to change Plex.tv sign in process

This commit is contained in:
tomkat83 2016-01-13 14:56:44 +01:00
parent 79f95100c5
commit 1f8eb7f2ab
3 changed files with 38 additions and 29 deletions

View file

@ -95,7 +95,7 @@ class Main:
xbmc.executebuiltin('Addon.OpenSettings(plugin.video.plexkodiconnect)')
if mode == "switchuser":
xbmc.log('Requesting user switch')
userclient.UserClient().signUserOut()
utils.window('emby_serverStatus', value="401")
elif mode in ("manualsync", "repair"):
if utils.window('emby_dbScan') != "true":
import librarysync

View file

@ -181,14 +181,21 @@ class PlexAPI():
if 'plex.tv' in url:
url = 'https://plex.tv/api/home/users'
else:
url = url + '/clients'
self.logMsg("CheckConnection called for url %s with a token" % url, 2)
r = self.doUtils.downloadUrl(
url,
authenticate=False,
headerOptions={'X-Plex-Token': token}
)
url = url + '/library/onDeck'
if token:
self.logMsg("CheckConnection for %s with a token" % url, 0)
r = self.doUtils.downloadUrl(
url,
authenticate=False,
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)
# List of exception returns, when connection failed
exceptionlist = [
@ -886,7 +893,6 @@ class PlexAPI():
Will return empty strings if failed.
"""
string = self.__language__
plexLogin = self.plexLogin
plexToken = self.plexToken
self.logMsg("Getting user list.", 1)

View file

@ -47,16 +47,8 @@ class UserClient(threading.Thread):
self.addonName = clientinfo.ClientInfo().getAddonName()
self.doUtils = downloadutils.DownloadUtils()
self.signoutUser = threading.Event()
threading.Thread.__init__(self)
def signUserOut(self):
self.signoutUser.set()
def userSignedOut(self):
return self.signoutUser.isSet()
def logMsg(self, msg, lvl=1):
className = self.__class__.__name__
@ -283,6 +275,7 @@ class UserClient(threading.Thread):
def authenticate(self):
# Get /profile/addon_data
plx = PlexAPI.PlexAPI()
addondir = xbmc.translatePath(self.addon.getAddonInfo('profile')).decode('utf-8')
hasSettings = xbmcvfs.exists("%ssettings.xml" % addondir)
@ -315,9 +308,15 @@ class UserClient(threading.Thread):
##### AUTHENTICATE USER #####
# Choose Plex user login
username, userId, accessToken = PlexAPI.PlexAPI().ChoosePlexHomeUser()
if accessToken is not "":
accessToken = ""
myplexlogin = utils.settings('myplexlogin')
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
xbmcgui.Dialog().notification("Emby server", "Welcome %s!" % username)
utils.settings('accessToken', value=accessToken)
@ -330,7 +329,18 @@ class UserClient(threading.Thread):
self.logMsg("User authentication failed.", 1)
utils.settings('accessToken', 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
def resetClient(self):
@ -365,13 +375,6 @@ class UserClient(threading.Thread):
utils.window('emby_serverStatus', value="Auth")
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):
# Try to authenticate user
status = utils.window('emby_serverStatus')