示例#1
0
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)
示例#2
0
def webinterface(clients, udpport_sync, moviefolder, killqueue):
	inpipe_path = "/tmp/fromwebapp"
	outpipe_path = "/tmp/towebapp"
	lockfile_path = "/tmp/locked"
	runningfile_path = "/tmp/running"
	
	if os.path.exists(lockfile_path):
		os.remove(lockfile_path)
	
	if not os.path.exists(runningfile_path):
		open(runningfile_path, "a")
	
	if not os.path.exists(inpipe_path):
		os.mkfifo(inpipe_path)
	
	if not os.path.exists(outpipe_path):
		os.mkfifo(outpipe_path)
		
	syncre = re.compile(r'^sync:(.*)$')
	playre = re.compile(r'^play:(.*)$')
	statre = re.compile(r'^stat:(.*)$')
	stopre = re.compile(r'^stop:(.*)$')
	bootre = re.compile(r'^boot:(.*)$')
	while True:
		command = getmessage(inpipe_path)
		if command == '':
			putmessage(outpipe_path, "")
		elif playre.match(command):
			client, moviename = playre.match(command).group(1).split(",")
			controller.play_single(moviefolder + "/Single/" + moviename + ".mp4", clients[client])
			putmessage(outpipe_path, json.dumps({x : clients[x][1] for x in clients.keys()}))
			
		elif syncre.match(command):
			moviename = syncre.match(command).group(1)
			killqueue.put("kill")
			controller.startSyncThread(moviefolder + "/Sync/" + moviename, clients, udpport_sync, killqueue)
			putmessage(outpipe_path, json.dumps({x : clients[x][1] for x in clients.keys()}))
		elif statre.match(command): # here for fun, not used yet
			piname = statre.match(command).group(1)
			if piname == all:
				statstring = ""
				clientrecord = []
				for client in clients.keys():
					clientrecord.append("/".join([client, clients[client][1]]))
		elif stopre.match(command):
			client = stopre.match(command).group(1)
			clients[client][1] = controller.message_to_pi(clients[client], 'shutdown')
			putmessage(outpipe_path, json.dumps({x : clients[x][1] for x in clients.keys()}))
		elif bootre.match(command):
			client = bootre.match(command).group(1)
			clients[client][1] = controller.message_to_pi(clients[client], 'reboot')
			putmessage(outpipe_path, json.dumps({x : clients[x][1] for x in clients.keys()}))
		elif command == "updateall":
			for client in clients.keys():
				clients[client][1] = controller.message_to_pi(clients[client], 'update')
			putmessage(outpipe_path, json.dumps({x : clients[x][1] for x in clients.keys()}))
		elif command == "quit":
			for client in clients.keys():
				clients[client][1] = controller.message_to_pi(clients[client], 'shutdown')
			putmessage(outpipe_path, json.dumps({x : clients[x][1] for x in clients.keys()}))
		elif command == "status":
			putmessage(outpipe_path, json.dumps({x : clients[x][1] for x in clients.keys()}))
		elif command == "quit_c":
			putmessage(outpipe_path, json.dumps({"shutdown":True}))
			while os.path.exists(lockfile_path) :
				time.sleep(0.1)
			if os.path.exists(runningfile_path) :
				os.remove(runningfile_path)
				
			# os.remove(runningfile_path)
			player.shutdown()
		else:
			# print(command)
			putmessage(outpipe_path, json.dumps({x : clients[x][1] for x in clients.keys()}))
			pass