+import os
+import random
+import requests
+import dotenv
+from fastapi import FastAPI
+from fastapi.middleware.cors import CORSMiddleware
+
+dotenv.load_dotenv()
+
+broadcaster_id = os.getenv("BROADCASTER_ID")
+client_id = os.getenv("CLIENT_ID")
+oauth = os.getenv("OAUTH")
+
+if not (broadcaster_id and client_id and oauth):
+ exit(1)
+
+response = requests.get(
+ "https://api.twitch.tv/helix/clips",
+ params={
+ "broadcaster_id": broadcaster_id,
+ "first": 100,
+ },
+ headers={
+ "Authorization": f"Bearer {oauth}",
+ "Client-Id": client_id,
+ }
+)
+
+if response.status_code != 200:
+ exit(1)
+
+data = response.json()["data"]
+for d in data:
+ d["video_mp4"] = \
+ d["thumbnail_url"][:d["thumbnail_url"].find("-preview")] + ".mp4"
+
+app = FastAPI()
+
+origins = ["*"]
+
+app.add_middleware(
+ CORSMiddleware,
+ allow_origins=origins,
+ allow_credentials=True,
+ allow_methods=["*"],
+ allow_headers=["*"],
+)
+
+
+@app.get("/clip")
+async def root():
+ clip = random.choice(data)["video_mp4"]
+ return clip