feat: inspect public video sources with yt-dlp
This commit is contained in:
+16
@@ -1,4 +1,9 @@
|
||||
from fastapi import FastAPI
|
||||
from fastapi import HTTPException
|
||||
from starlette.concurrency import run_in_threadpool
|
||||
|
||||
from app.inspection import InspectionError, UnsafeUrlError, inspect_url
|
||||
from app.models import InspectionRequest, InspectionResponse
|
||||
|
||||
app = FastAPI(
|
||||
title="Media Ingest",
|
||||
@@ -16,3 +21,14 @@ def root() -> dict[str, str]:
|
||||
def health() -> dict[str, str]:
|
||||
"""Report whether the application process can serve requests."""
|
||||
return {"status": "healthy"}
|
||||
|
||||
|
||||
@app.post("/api/inspect", response_model=InspectionResponse, tags=["inspection"])
|
||||
async def inspect_source(request: InspectionRequest) -> dict[str, object]:
|
||||
"""Inspect a public video URL without downloading media."""
|
||||
try:
|
||||
return await run_in_threadpool(inspect_url, request.url)
|
||||
except UnsafeUrlError as error:
|
||||
raise HTTPException(status_code=400, detail=str(error)) from error
|
||||
except InspectionError as error:
|
||||
raise HTTPException(status_code=422, detail=str(error)) from error
|
||||
|
||||
Reference in New Issue
Block a user