示例#1
0
文件: client.py 项目: noonat/omplex
    def do_POST(self):
        ctype, pdict = cgi.parse_header(self.headers.getheader('content-type'))
        if ctype == 'multipart/form-data':
            postvars = cgi.parse_multipart(self.rfile, pdict)
        elif ctype == 'application/x-www-form-urlencoded':
            length = int(self.headers.getheader('content-length'))
            postvars = cgi.parse_qs(self.rfile.read(length), keep_blank_values=1)
        else:
            postvars = {}

        if self.path == "/data/settings/":
            response = {
                "success": True,
                "message": ""
            }
            try:
                myplex_username = postvars.get("myplex_username")[0]
                myplex_password = postvars.get("myplex_password")[0]
                player_name     = postvars.get("player_name")[0]
                audio_output    = postvars.get("audio_output")[0]
            except:
                response.update({
                    "success": False,
                    "message": "Invalid data"
                })

            if response["success"]:
                if not settings.login_myplex(myplex_username, myplex_password):
                    response.update({
                        "success": False,
                        "message": "Invalid MyPlex Credentials"
                    })

            if response["success"]:
                settings.myplex_username = myplex_username
                settings.myplex_password = myplex_password
                settings.player_name     = player_name
                settings.audio_output    = audio_output

            data = json.dumps(response)

            self.send_response(200)
            self.send_header("Content-type", "application/json")
            self.send_header("Content-Length", str(len(data)))
            self.end_headers()
            
            self.wfile.write(data)
示例#2
0
文件: cmdline.py 项目: noonat/omplex
def main():
    logging.basicConfig(level=logging.DEBUG, stream=sys.stdout, format="%(asctime)s [%(levelname)8s] %(message)s")

    settings.load("settings.dat")
    if not settings.myplex_token:
        while True:
            username = raw_input("MyPlex Username: "******"MyPlex Password: "******"Logged in!"
                break
            print "Error logging in..."

    settings.add_listener(update_gdm_settings)
    
    update_gdm_settings()
    gdm.start_all()

    log.info("Started GDM service")

    queue = Queue.Queue()

    while not gdm.discovery_complete:
        time.sleep(1)

    gdm.discover()

    osd.start()

    server = HttpServer(queue, int(settings.http_port))
    server.start()

    timelineManager.start()

    try:
        while True:
            time.sleep(1)
    except KeyboardInterrupt:
        print ""
        log.info("Stopping services...")
    finally:
        playerManager.stop()
        osd.stop()
        server.stop()
        timelineManager.stop()
        gdm.stop_all()