Basic recoding
This commit is contained in:
parent
517f41b534
commit
b988344c9b
2 changed files with 97 additions and 59 deletions
|
@ -298,10 +298,34 @@ 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
|
||||||
|
selectedServer = plexapp.SERVERMANAGER.selectedServer
|
||||||
|
if not selectedServer:
|
||||||
|
if not server_select_shown:
|
||||||
|
server_select_shown = True
|
||||||
|
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:
|
while not xbmc.abortRequested:
|
||||||
|
|
||||||
if (
|
if (
|
||||||
not plexapp.ACCOUNT.isOffline and not
|
not plexapp.ACCOUNT.isOffline and not
|
||||||
plexapp.ACCOUNT.isAuthenticated and
|
plexapp.ACCOUNT.isAuthenticated and
|
||||||
|
@ -352,9 +376,6 @@ def main():
|
||||||
finally:
|
finally:
|
||||||
windowutils.shutdownHome()
|
windowutils.shutdownHome()
|
||||||
gc.collect(2)
|
gc.collect(2)
|
||||||
|
|
||||||
else:
|
|
||||||
break
|
|
||||||
except:
|
except:
|
||||||
util.ERROR()
|
util.ERROR()
|
||||||
finally:
|
finally:
|
||||||
|
|
|
@ -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:
|
|
||||||
|
def authorize_user():
|
||||||
|
"""
|
||||||
|
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
|
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('Did not get a Plex token')
|
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')
|
||||||
return True
|
return plexapp.ACCOUNT.isSignedIn
|
||||||
|
|
||||||
|
|
||||||
|
def select_user():
|
||||||
|
"""
|
||||||
|
"""
|
||||||
|
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()
|
||||||
|
|
Loading…
Reference in a new issue