import os, BaseHTTPServer HOSTNAME = '192.168.0.1' PORT = 31337 path = { "play" : "-p", "stop" : "-s", "pause" : "-u", "next" : "-n", "prev" : "-r", "seek+5s": "-k +5s", "seek-5s": "-k -5s", "seek+1m": "-k +1m", "seek-1m": "-k -1m", "mute" : "-v 0", "vol25%" : "-v 5", "vol50%" : "-v 10", "vol75%" : "-v 15", "vol100%": "-v 20", "shuffle": "-s", "repeat" : "-R" } class MyHandler(BaseHTTPServer.BaseHTTPRequestHandler): def do_GET(s): s.send_response(200) s.send_header("Pragma", "no-cache") s.end_headers() s.wfile.write("cmus webinterface") i=0 keys=path.keys() keys.sort(); for k in keys: if not (i % 3): s.wfile.write("") s.wfile.write("") if not ((i-2) % 3): s.wfile.write("") i+=1 s.wfile.write("
"+k+"
") if path.has_key(s.path[1:]): os.system("cmus-remote "+path[s.path[1:]]) if __name__ == '__main__': server_class = BaseHTTPServer.HTTPServer httpd = server_class((HOSTNAME, PORT), MyHandler) try: httpd.serve_forever() except KeyboardInterrupt: pass httpd.close()