import json import os import shlex import subprocess import sys from datetime import datetime from typing import List from fastapi import FastAPI, File, UploadFile from fastapi.responses import HTMLResponse app = FastAPI() try: domain = os.environ["DOMAIN"] except KeyError: sys.exit("Environment variable 'DOMAIN' is missing!") @app.post("/uploadfiles/") async def upload_file(file: UploadFile = File(...)): try: if upload_file.content_type == "video/mp4": os.mkdir("videos") elif upload_file.content_type == "": os.mkdir("videos") elif upload_file.content_type == "": os.mkdir("files") except Exception as e: print(e) # TODO: Send to Discord print(file.filename) file_location = f"Uploads/v/{file.filename}" with open(file_location, "wb+") as file_object: file_object.write(file.file.read()) height, width = find_video_resolution(file_location) screenshot_url = get_first_frame(file_location, file.filename) video_url = f"{domain}v/{file.filename}" html_url = generate_html( video_url, width, height, screenshot_url, file.filename, ) return { "html_url": f"{html_url}", "video_url": f"{video_url}", "width": f"{width}", "height": f"{height}", "screenshot_url": f"{screenshot_url}", "filename": f"{file.filename}", } @app.get("/") async def main(): content = """