Skip to content

Commit

Permalink
gene
Browse files Browse the repository at this point in the history
  • Loading branch information
ensargx committed Apr 7, 2024
1 parent d65fe21 commit 01fc6c5
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
import json
from upload_video import DownloadVideos, GetRefreshTokenFromCode

REFRESH_TOKEN = None
VIDEOS = None

class MyHandler(server.BaseHTTPRequestHandler):
def do_GET(self):
# send index.html file to client
Expand Down Expand Up @@ -50,7 +47,6 @@ def do_POST(self):
return
try:
refresh_token = GetRefreshTokenFromCode(code)
globals()['REFRESH_TOKEN'] = refresh_token
except Exception as e:
print("Error getting refresh token:", e)
self.send_response(500)
Expand All @@ -59,16 +55,24 @@ def do_POST(self):
self.wfile.write(b'Error getting refresh token: ' + str(e).encode('utf-8'))
return

globals()['VIDEOS'] = videos
print("Downloading videos...")
self.send_response(200)
self.end_headers()
self.wfile.write(b'Videos will be uploaded shortly')
self.server.shutdown()
self.wfile.write(b'Videos downloading...')
# send response to client
self.finish()

try:
DownloadVideos(refresh_token, videos)
except Exception as e:
print("Error downloading videos:", e)

exit(0)


server_address = ('', 8000)
httpd = server.HTTPServer(server_address, MyHandler)
httpd.serve_forever()

DownloadVideos(REFRESH_TOKEN, VIDEOS)


0 comments on commit 01fc6c5

Please sign in to comment.