-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
50 lines (40 loc) · 1.47 KB
/
server.py
File metadata and controls
50 lines (40 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
from http.server import BaseHTTPRequestHandler, HTTPServer
import time
from urllib.parse import urlencode
from urllib.request import Request, urlopen
import codecs
from subprocess import call
from subprocess import Popen
import mpv
main = codecs.open("main.html", 'r', 'utf-8').read()
hostName = "0.0.0.0"
hostPort = 8888
player = mpv.MPV(ytdl=True)
def ytLink(number):
yt = ['https://www.youtube.com/watch?v=xxG2UWhvXJI', 'https://youtu.be/LO2RPDZkY88', 'https://youtu.be/jbt6UWc1ZKo', 'https://youtu.be/WC5FdFlUcl0']
intNum = int(number[1])
return(yt[intNum])
class MyServer(BaseHTTPRequestHandler):
def do_GET(self):
self.send_response(200)
self.send_header("Content-type", "text/html")
self.end_headers()
self.wfile.write(bytes(main, "utf-8"))
def do_POST(self):
choice = ytLink(self.path)
print(choice)
# p = Popen(['mpv', choice])
player.play(choice)
self.send_response(200)
self.send_header("Content-type", "text/html")
self.end_headers()
self.wfile.write(bytes("<p>This is a POST REQUEST.</p>", "utf-8"))
self.wfile.write(bytes("<p>You accessed path: %s</p>" % self.path, "utf-8"))
myServer = HTTPServer((hostName, hostPort), MyServer)
print(time.asctime(), "Server Starts - %s:%s" % (hostName, hostPort))
try:
myServer.serve_forever()
except KeyboardInterrupt:
pass
myServer.server_close()
print(time.asctime(), "Server Stops - %s:%s" % (hostName, hostPort))