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
while retry:
retry = False
if not plexapp.ACCOUNT.authToken: if not plexapp.ACCOUNT.authToken:
from .windows import background from .windows import background
with background.BackgroundContext(function=authorize) as d: with background.BackgroundContext(function=authorize) as d:
token = d.result token = d.result
if not token: if not token:
LOG.info('FAILED TO AUTHORIZE') LOG.info('Did not get a Plex token')
return False return False
with CallbackEvent(plexapp.APP, 'account:response'): with CallbackEvent(plexapp.APP, 'account:response'):
plexapp.ACCOUNT.validateToken(token) plexapp.ACCOUNT.validateToken(token)
LOG.info('Waiting for account initialization') 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