def authorize(): from windows import signin, background background.setSplash(False) back = signin.Background.create() pre = signin.PreSignInWindow.open() try: if not pre.doSignin: return None finally: del pre try: while True: pinLoginWindow = signin.PinLoginWindow.create() try: pl = myplex.PinLogin() except requests.ConnectionError: util.ERROR() util.messageDialog( util.T(32427, 'Failed'), util.T(32449, 'Sign-in failed. Cound not connect to plex.tv')) return pinLoginWindow.setPin(pl.pin) try: pl.startTokenPolling() while not pl.finished(): if pinLoginWindow.abort: util.DEBUG_LOG('SIGN IN: Pin login aborted') pl.abort() return None xbmc.sleep(100) else: if not pl.expired(): if pl.authenticationToken: pinLoginWindow.setLinking() return pl.authenticationToken else: return None finally: pinLoginWindow.doClose() del pinLoginWindow if pl.expired(): util.DEBUG_LOG('SIGN IN: Pin expired') expiredWindow = signin.ExpiredWindow.open() try: if not expiredWindow.refresh: util.DEBUG_LOG('SIGN IN: Pin refresh aborted') return None finally: del expiredWindow finally: back.doClose() del back
def requirePlexPass(): 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 _main(): util.DEBUG_LOG('[ STARTED: {0} -------------------------------------------------------------------- ]'.format(util.ADDON.getAddonInfo('version'))) util.DEBUG_LOG('USER-AGENT: {0}'.format(plex.defaultUserAgent())) background.setSplash() try: while not xbmc.abortRequested: if plex.init(): background.setSplash(False) while not xbmc.abortRequested: if ( not plexapp.ACCOUNT.isOffline and not plexapp.ACCOUNT.isAuthenticated and (len(plexapp.ACCOUNT.homeUsers) > 1 or plexapp.ACCOUNT.isProtected) ): result = userselect.start() if not result: return elif result == 'signout': signout() break elif result == 'signin': break util.DEBUG_LOG('Main: User selected') try: done = plex.CallbackEvent(plexapp.APP, 'change:selectedServer', timeout=11) if not plexapp.SERVERMANAGER.selectedServer: util.DEBUG_LOG('Main: Waiting for selected server...') try: background.setBusy() done.wait() finally: background.setBusy(False) util.DEBUG_LOG('Main: STARTING WITH SERVER: {0}'.format(plexapp.SERVERMANAGER.selectedServer)) windowutils.HOME = home.HomeWindow.open() util.CRON.cancelReceiver(windowutils.HOME) if not windowutils.HOME.closeOption: return closeOption = windowutils.HOME.closeOption windowutils.shutdownHome() if closeOption == 'signout': signout() break elif closeOption == 'switch': plexapp.ACCOUNT.isAuthenticated = False finally: windowutils.shutdownHome() BACKGROUND.activate() gc.collect(2) else: break except: util.ERROR() finally: util.DEBUG_LOG('Main: SHUTTING DOWN...') background.setShutdown() player.shutdown() plexapp.APP.preShutdown() util.CRON.stop() backgroundthread.BGThreader.shutdown() plexapp.APP.shutdown() waitForThreads() background.setBusy(False) background.setSplash(False) util.DEBUG_LOG('FINISHED') from windows import kodigui kodigui.MONITOR = None util.shutdown() gc.collect(2)