media-rip/backend/app/routers/formats.py
xpltd efc2ead796 M001: media.rip() v1.0 — complete application
Full-featured self-hosted yt-dlp web frontend:
- Python 3.12+ / FastAPI backend with async SQLite, SSE transport, session isolation
- Vue 3 / TypeScript / Pinia frontend with real-time progress, theme picker
- 3 built-in themes (cyberpunk/dark/light) + drop-in custom theme system
- Admin auth (bcrypt), purge system, cookie upload, file serving
- Docker multi-stage build, GitHub Actions CI/CD
- 179 backend tests, 29 frontend tests (208 total)

Slices: S01 (Foundation), S02 (SSE+Sessions), S03 (Frontend),
        S04 (Admin+Auth), S05 (Themes), S06 (Docker+CI)
2026-03-18 20:00:17 -05:00

36 lines
1 KiB
Python

"""Format extraction API route.
GET /formats?url= — return available download formats for a URL
"""
from __future__ import annotations
import logging
from fastapi import APIRouter, Query, Request
from fastapi.responses import JSONResponse
from app.models.job import FormatInfo
logger = logging.getLogger("mediarip.api.formats")
router = APIRouter(tags=["formats"])
@router.get("/formats", response_model=list[FormatInfo])
async def get_formats(
request: Request,
url: str = Query(..., description="URL to extract formats from"),
) -> list[FormatInfo] | JSONResponse:
"""Extract available formats for a URL via yt-dlp."""
logger.debug("GET /formats url=%s", url)
download_service = request.app.state.download_service
try:
formats = await download_service.get_formats(url)
return formats
except Exception as exc:
logger.error("Format extraction failed for %s: %s", url, exc)
return JSONResponse(
status_code=400,
content={"detail": f"Format extraction failed: {exc}"},
)