-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_handler.py
34 lines (32 loc) · 994 Bytes
/
get_handler.py
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
from BaseHTTPServer import BaseHTTPRequestHandler
import urlparse
import url_validator
import time
import os
class GetHandler(BaseHTTPRequestHandler):
def do_GET(self):
parsed_path = urlparse.urlparse(self.path)
message = '<html><body><form method="POST"> <input type="text" name="url"/></form><body></html>'
self.send_response(200)
self.end_headers()
self.wfile.write(message)
return
def do_POST(self):
video = None
length = int(self.headers['Content-Length'])
post_data = urlparse.parse_qs(self.rfile.read(length).decode('utf-8'))
for key, value in post_data.iteritems():
if(key=="url" and value[0] and url_validator.validate(value[0])):
video = value[0]
if (video):
self.send_response(200)
self.end_headers()
self.wfile.write("will download "+video)
self.wfile.flush()
job = open("pending.txt","a")
job.write(video + "\n")
job.close()
#download = Popen(['youtube-dl',video], stdout=PIPE)
else:
self.wfile.write("error")
return