"""Video URL parsing routes.""" from fastapi import APIRouter, HTTPException from app.schemas import ParseRequest, ParseResponse, FormatInfo from app.services.downloader import parse_video_url router = APIRouter(prefix="/api", tags=["parse"]) @router.post("/parse", response_model=ParseResponse) async def parse_url(req: ParseRequest): try: info = parse_video_url(req.url) return ParseResponse( title=info["title"], thumbnail=info["thumbnail"], duration=info["duration"], formats=[FormatInfo(**f) for f in info["formats"]], url=info["url"], ) except Exception as e: raise HTTPException(status_code=400, detail=f"Failed to parse URL: {str(e)}")