Pushp0120 commited on
Commit
ea46f56
·
verified ·
1 Parent(s): c3ab029

Create server.py

Browse files
Files changed (1) hide show
  1. server.py +40 -0
server.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from http.server import HTTPServer, BaseHTTPRequestHandler
2
+ import subprocess
3
+ import json
4
+ import os
5
+ import pickle
6
+ import base64
7
+
8
+ # Load token from environment variable
9
+ token_b64 = os.environ.get('YOUTUBE_TOKEN')
10
+ if token_b64:
11
+ token = pickle.loads(base64.b64decode(token_b64))
12
+ with open('/app/token.pickle', 'wb') as f:
13
+ pickle.dump(token, f)
14
+ print("Token loaded successfully!")
15
+
16
+ class Handler(BaseHTTPRequestHandler):
17
+ def do_POST(self):
18
+ length = int(self.headers['Content-Length'])
19
+ body = json.loads(self.rfile.read(length))
20
+
21
+ video_url = body.get('videoUrl', '')
22
+ title = body.get('title', '')
23
+ description = body.get('description', '')
24
+
25
+ print(f"Uploading: {title}")
26
+
27
+ subprocess.Popen([
28
+ 'python', '/app/upload.py',
29
+ video_url, title, description
30
+ ])
31
+
32
+ self.send_response(200)
33
+ self.end_headers()
34
+ self.wfile.write(b'{"status": "upload started"}')
35
+
36
+ def log_message(self, format, *args):
37
+ pass
38
+
39
+ print("ShortBot server running on port 7860...")
40
+ HTTPServer(('0.0.0.0', 7860), Handler).serve_forever()