from fastapi import FastAPI, HTTPException
from yt_dlp import YoutubeDL
app = FastAPI()
@[Link]("/fetch-video")
async def fetch_video(url: str):
ydl_opts = {'format': 'best'}
with YoutubeDL(ydl_opts) as ydl:
info = ydl.extract_info(url, download=False)
return {
"title": [Link]("title"),
"thumbnail": [Link]("thumbnail"),
"duration": [Link]("duration"),
"formats": [Link]("formats"),
}
@[Link]("/download")
async def download_video(url: str, quality: str):
ydl_opts = {
'format': quality,
'outtmpl': '%(title)s.%(ext)s',
}
with YoutubeDL(ydl_opts) as ydl:
[Link]([url])
return {"message": "Download started"}