Spaces:
Build error
Build error
File size: 745 Bytes
4564216 2515173 9cb3fae 2515173 9cb3fae 2515173 4564216 2515173 9cb3fae 2515173 4564216 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
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
} |