chipling-api / app.py
Maouu's picture
Update app.py
2515173 verified
raw
history blame
745 Bytes
from pytubefix import YouTube
from pytubefix.cli import on_progress
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
app = FastAPI()
app.add_middleware(
CORSMiddleware,
allow_origins=["*"], # Adjust as needed
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
@app.get("/")
def index():
return {"message": "Hello, World!"}
@app.get("/api/video/{id}")
def video_id(id: str):
url = f"https://www.youtube.com/watch?v={id}"
yt = YouTube(url, on_progress_callback=on_progress)
ys = yt.streams.get_highest_resolution()
return {
"title": yt.title,
"url": ys.url,
"thumbnail": yt.thumbnail_url,
"description": yt.description
}