Streamline some code

This commit is contained in:
croneter 2018-10-06 13:32:18 +02:00
parent 9eba24485e
commit b6dc458b54
3 changed files with 17 additions and 52 deletions

View file

@ -294,7 +294,7 @@ def signout():
def main(): def main():
LOG.info('Starting %s', util.ADDON.getAddonInfo('version')) LOG.info('Starting PKC %s', util.ADDON.getAddonInfo('version'))
LOG.info('User-agent: %s', plex.defaultUserAgent()) LOG.info('User-agent: %s', plex.defaultUserAgent())
try: try:

View file

@ -229,7 +229,7 @@ plexapp.setUserAgent(defaultUserAgent())
class CallbackEvent(plexapp.CompatEvent): class CallbackEvent(plexapp.CompatEvent):
def __init__(self, context, signal, timeout=15, *args, **kwargs): def __init__(self, context, signal, timeout=20, *args, **kwargs):
threading._Event.__init__(self, *args, **kwargs) threading._Event.__init__(self, *args, **kwargs)
self.start = time.time() self.start = time.time()
self.context = context self.context = context
@ -243,9 +243,12 @@ class CallbackEvent(plexapp.CompatEvent):
def __exit__(self, exc_type, exc_value, traceback): def __exit__(self, exc_type, exc_value, traceback):
self.wait() self.wait()
def __repr__(self): def __unicode__(self):
return '<{0}:{1}>'.format(self.__class__.__name__, self.signal) return '<{0}:{1}>'.format(self.__class__.__name__, self.signal)
def __repr__(self):
return self.__unicode__().encode('utf-8')
def set(self, **kwargs): def set(self, **kwargs):
threading._Event.set(self) threading._Event.set(self)
@ -277,54 +280,19 @@ def init():
plexapp.init() plexapp.init()
LOG.info('Waiting for account initialization...') LOG.info('Waiting for account initialization...')
retry = True if not plexapp.ACCOUNT.authToken:
from .windows import background
with background.BackgroundContext(function=authorize) as d:
token = d.result
while retry: if not token:
retry = False LOG.info('Did not get a Plex token')
if not plexapp.ACCOUNT.authToken: return False
from .windows import background
with background.BackgroundContext(function=authorize) as d:
token = d.result
if not token: with CallbackEvent(plexapp.APP, 'account:response'):
LOG.info('FAILED TO AUTHORIZE') plexapp.ACCOUNT.validateToken(token)
return False LOG.info('Waiting for account initialization')
with CallbackEvent(plexapp.APP, 'account:response'):
plexapp.ACCOUNT.validateToken(token)
LOG.info('Waiting for account initialization')
# if not PLEX:
# util.messageDialog('Connection Error', u'Unable to connect to any servers')
# util.DEBUG_LOG('SIGN IN: Failed to connect to any servers')
# return False
# util.DEBUG_LOG('SIGN IN: Connected to server: {0} - {1}'.format(PLEX.friendlyName, PLEX.baseuri))
success = requirePlexPass()
if success == 'RETRY':
retry = True
continue
return success
def requirePlexPass():
return True return True
# if not plexapp.ACCOUNT.hasPlexPass():
# from windows import signin, background
# background.setSplash(False)
# w = signin.SignInPlexPass.open()
# retry = w.retry
# del w
# util.DEBUG_LOG('PlexPass required. Signing out...')
# plexapp.ACCOUNT.signOut()
# plexapp.SERVERMANAGER.clearState()
# if retry:
# return 'RETRY'
# else:
# return False
# return True
def authorize(): def authorize():

View file

@ -138,10 +138,7 @@ class MyPlexAccount(object):
self.hasQueue = bool(data.attrib.get('queueEmail')) self.hasQueue = bool(data.attrib.get('queueEmail'))
# PIN # PIN
if data.attrib.get('pin'): self.pin = data.attrib.get('pin')
self.pin = data.attrib.get('pin')
else:
self.pin = None
self.isProtected = bool(self.pin) self.isProtected = bool(self.pin)
# update the list of users in the home # update the list of users in the home