Spaces:
Build error
Build error
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=["*"], | |
) | |
def index(): | |
return {"message": "Hello, World!"} | |
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 | |
} |