Basic recoding

This commit is contained in:
croneter 2018-10-07 18:00:46 +02:00
parent 517f41b534
commit b988344c9b
2 changed files with 97 additions and 59 deletions

View file

@ -298,63 +298,84 @@ def main():
LOG.info('Starting PKC %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())
server_select_shown = False
try: try:
plex.init()
# Check plex.tv sign-in status
if not plexapp.ACCOUNT.authToken:
LOG.info('Not signed in to plex.tv yet')
if utils.settings('myplexlogin') == 'true':
plex.authorize_user()
# Main Loop
while not xbmc.abortRequested: while not xbmc.abortRequested:
if plex.init(): # Check whether a PMS server has been set
while not xbmc.abortRequested: selectedServer = plexapp.SERVERMANAGER.selectedServer
if ( if not selectedServer:
not plexapp.ACCOUNT.isOffline and not if not server_select_shown:
plexapp.ACCOUNT.isAuthenticated and server_select_shown = True
(len(plexapp.ACCOUNT.homeUsers) > 1 or plexapp.ACCOUNT.isProtected) LOG.debug('No PMS set yet, presenting dialog')
plex.select_server()
else:
util.MONITOR.waitForAbort(1)
continue
# Ping the PMS until we're sure its online
if not selectedServer.isReachable():
selectedServer.updateReachability(force=True,
allowFallback=True)
continue
while not xbmc.abortRequested:
): if (
result = userselect.start() not plexapp.ACCOUNT.isOffline and not
if not result: plexapp.ACCOUNT.isAuthenticated and
return (len(plexapp.ACCOUNT.homeUsers) > 1 or plexapp.ACCOUNT.isProtected)
elif result == 'signout':
signout()
break
elif result == 'signin':
break
LOG.info('User selected')
try: ):
selectedServer = plexapp.SERVERMANAGER.selectedServer result = userselect.start()
if not result:
return
elif result == 'signout':
signout()
break
elif result == 'signin':
break
LOG.info('User selected')
if not selectedServer: try:
LOG.debug('Waiting for selected server...') selectedServer = plexapp.SERVERMANAGER.selectedServer
for timeout, skip_preferred, skip_owned in ((10, True, False), (10, True, True)):
plex.CallbackEvent(plexapp.APP, 'change:selectedServer', timeout=timeout).wait()
selectedServer = plexapp.SERVERMANAGER.checkSelectedServerSearch(skip_preferred=skip_preferred, skip_owned=skip_owned) if not selectedServer:
if selectedServer: LOG.debug('Waiting for selected server...')
break for timeout, skip_preferred, skip_owned in ((10, True, False), (10, True, True)):
else: plex.CallbackEvent(plexapp.APP, 'change:selectedServer', timeout=timeout).wait()
LOG.debug('Finished waiting for selected server...')
LOG.info('Starting with server: %s', selectedServer) selectedServer = plexapp.SERVERMANAGER.checkSelectedServerSearch(skip_preferred=skip_preferred, skip_owned=skip_owned)
if selectedServer:
break
else:
LOG.debug('Finished waiting for selected server...')
windowutils.HOME = home.HomeWindow.open() LOG.info('Starting with server: %s', selectedServer)
util.CRON.cancelReceiver(windowutils.HOME)
if not windowutils.HOME.closeOption: windowutils.HOME = home.HomeWindow.open()
return util.CRON.cancelReceiver(windowutils.HOME)
closeOption = windowutils.HOME.closeOption if not windowutils.HOME.closeOption:
return
windowutils.shutdownHome() closeOption = windowutils.HOME.closeOption
if closeOption == 'signout': windowutils.shutdownHome()
signout()
break
elif closeOption == 'switch':
plexapp.ACCOUNT.isAuthenticated = False
finally:
windowutils.shutdownHome()
gc.collect(2)
else: if closeOption == 'signout':
break signout()
break
elif closeOption == 'switch':
plexapp.ACCOUNT.isAuthenticated = False
finally:
windowutils.shutdownHome()
gc.collect(2)
except: except:
util.ERROR() util.ERROR()
finally: finally:

View file

@ -275,33 +275,50 @@ class CallbackEvent(plexapp.CompatEvent):
def init(): def init():
LOG.info('Initializing') LOG.info('Initializing')
with CallbackEvent(plexapp.APP, 'init'): with CallbackEvent(plexapp.APP, 'init'):
plexapp.init() plexapp.init()
LOG.info('Waiting for account initialization...') LOG.info('Waiting for account initialization...')
LOG.info('Account initialization done...')
if not plexapp.ACCOUNT.authToken:
from .windows import background
with background.BackgroundContext(function=authorize) as d:
token = d.result
if not token: def authorize_user():
LOG.info('Did not get a Plex token') """
return False Display userselect dialog. Returns True if user has been selected
and a valid token has been retrieved, False otherwise
"""
LOG.info('Displaying userselect dialog')
from .windows import background
with background.BackgroundContext(function=authorize) as d:
token = d.result
if not token:
LOG.info('Did not get a Plex token')
return False
with CallbackEvent(plexapp.APP, 'account:response'):
plexapp.ACCOUNT.validateToken(token)
LOG.info('Waiting for account initialization')
return plexapp.ACCOUNT.isSignedIn
with CallbackEvent(plexapp.APP, 'account:response'):
plexapp.ACCOUNT.validateToken(token) def select_user():
LOG.info('Waiting for account initialization') """
return True """
pass
def select_server():
"""
Displays a window for the user to select a pms.
"""
pass
def authorize(): def authorize():
"""
Shows dialogs to sign in to plex.tv with pin. Returns token or None
"""
from .windows import signin, background from .windows import signin, background
background.setSplash(False) background.setSplash(False)
back = signin.Background.create() back = signin.Background.create()
try: try:
while True: while True:
pinLoginWindow = signin.PinLoginWindow.create() pinLoginWindow = signin.PinLoginWindow.create()