forked from inteoryx/twitter-video-dl
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtwitter-video-dl-server.py
42 lines (33 loc) · 1.34 KB
/
twitter-video-dl-server.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
35
36
37
38
39
40
41
42
from http.server import BaseHTTPRequestHandler, HTTPServer
from urllib.parse import parse_qs, urlparse
import src.twitter_video_dl.twitter_video_dl as tvdl
DCEBUG_MODE = False
class RequestHandler(BaseHTTPRequestHandler):
def do_GET(self):
query = urlparse(self.path).query
params = parse_qs(query)
url = params.get("url", [""])[0]
fileName = params.get("fileName", [""])[0]
if url:
fileName = fileName.replace(" ", "_").replace(" ", "_").replace("/", "-")
tvdl.download_video_for_sc(url, fileName)
self.send_response(200)
self.send_header("Content-type", "text/html")
self.end_headers()
self.wfile.write(b"URL received")
else:
self.send_response(200)
self.send_header("Content-type", "text/html")
self.end_headers()
self.wfile.write(b"No URL received")
def log_message(self, format, *args):
if DCEBUG_MODE:
# Display log only when debug mode is True.
super().log_message(format, *args)
def run(server_class=HTTPServer, handler_class=RequestHandler, port=3000):
server_address = ("", port)
httpd = server_class(server_address, handler_class)
print(f"Starting server on port {port}")
httpd.serve_forever()
if __name__ == "__main__":
run()