#!/usr/bin/env python import subprocess import socket import sys import getopt import signal from http.server import HTTPServer, BaseHTTPRequestHandler from urllib.parse import urlparse class SimpleHTTPRequestHandler(BaseHTTPRequestHandler): def do_GET(self): mpvpause = "?mpv=pause" mpvurl = "url" i = self.path.index ( "?" ) apirq = self.path[i:] print(apirq) if apirq == mpvpause: cmd = "echo 'cycle pause' | socat - /tmp/mpvsocket" mpvurl = subprocess.Popen(cmd,shell=True,stdout=subprocess.PIPE,stderr=subprocess.STDOUT) self.send_response(200) self.end_headers() self.wfile.write(b'Paused MPV') self.send_header("Content-Type", "text/html") self.end_headers() elif apirq.startswith("?url"): music=apirq.split("=",1)[1] cmdmusic = "echo '{\"command\":[\"loadfile\", \"" + music + "\"]}' | socat - /tmp/mpvsocket" cmd = cmdmusic mpvurl = subprocess.Popen(cmd,shell=True,stdout=subprocess.PIPE,stderr=subprocess.STDOUT) print(music) print(cmdmusic) self.send_response(200) self.end_headers() self.wfile.write(b'Playing String', ) self.send_header("Content-Type", "text/html") self.end_headers() httpd = HTTPServer(('', 8000), SimpleHTTPRequestHandler) httpd.serve_forever()