feat: add YouTube cookies upload via web UI

Adds a Settings panel to upload a cookies.txt file directly from the
browser, persisted in a named Docker volume. yt-dlp uses the file
when present to bypass YouTube bot detection.
This commit is contained in:
Julien Calixte
2026-03-23 19:32:51 +01:00
parent c49ecab33f
commit 57910462e4
5 changed files with 91 additions and 3 deletions

View File

@@ -2,11 +2,12 @@ import os
from contextlib import asynccontextmanager
from pathlib import Path
from fastapi import FastAPI, HTTPException, BackgroundTasks
from fastapi import FastAPI, HTTPException, BackgroundTasks, UploadFile
from fastapi.responses import FileResponse
from pydantic import BaseModel
from app import downloader
from app.config import settings
STATIC_DIR = Path(__file__).parent / "static"
@@ -74,6 +75,25 @@ def _delete_file(path):
pass
@app.post("/admin/cookies")
async def upload_cookies(file: UploadFile):
if not settings.yt_dlp_cookies_file:
raise HTTPException(status_code=500, detail="YT_DLP_COOKIES_FILE not configured")
cookies_path = Path(settings.yt_dlp_cookies_file)
cookies_path.parent.mkdir(parents=True, exist_ok=True)
content = await file.read()
cookies_path.write_bytes(content)
return {"status": "ok", "path": str(cookies_path)}
@app.get("/admin/cookies/status")
async def cookies_status():
if not settings.yt_dlp_cookies_file:
return {"present": False}
path = Path(settings.yt_dlp_cookies_file)
return {"present": path.exists(), "size": path.stat().st_size if path.exists() else 0}
@app.get("/")
async def index():
return FileResponse(STATIC_DIR / "index.html")