feat: téléchargement dans sous-dossiers par catégorie

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
dev
2026-05-02 19:16:36 +02:00
parent 978a54a25f
commit f07352bd04
3 changed files with 11 additions and 8 deletions
+6 -5
View File
@@ -107,7 +107,7 @@ class DownloadManager:
# ------------------------------------------------------------------ public
def enqueue(self, url: str, title: str, subtitle: str, year: int | None,
bg: BackgroundTasks) -> str:
category: str, bg: BackgroundTasks) -> str:
dl_id = str(uuid.uuid4())
now = datetime.now().isoformat()
with _db() as conn:
@@ -117,7 +117,7 @@ class DownloadManager:
)
with self._lock:
self._active[dl_id] = {"state": "queued", "progress": 0, "title": title}
bg.add_task(self._run, dl_id, url, title, subtitle, year)
bg.add_task(self._run, dl_id, url, title, subtitle, year, category)
return dl_id
def status(self, dl_id: str) -> dict:
@@ -144,8 +144,9 @@ class DownloadManager:
with self._lock:
self._active.setdefault(dl_id, {}).update(kw)
def _run(self, dl_id: str, url: str, title: str, subtitle: str, year: int | None):
Path(OUTPUT_DIR).mkdir(parents=True, exist_ok=True)
def _run(self, dl_id: str, url: str, title: str, subtitle: str, year: int | None, category: str = ""):
out_dir = f"{OUTPUT_DIR}/{category}" if category else OUTPUT_DIR
Path(out_dir).mkdir(parents=True, exist_ok=True)
self._set(dl_id, state="downloading")
with _db() as conn:
conn.execute("UPDATE downloads SET state='downloading' WHERE id=?", (dl_id,))
@@ -172,7 +173,7 @@ class DownloadManager:
self._set(dl_id, state="processing", progress=100)
ydl_opts = {
"outtmpl": f"{OUTPUT_DIR}/%(title)s.%(ext)s",
"outtmpl": f"{out_dir}/%(title)s.%(ext)s",
"format": "bestvideo[vcodec^=avc1]+bestaudio/bestvideo+bestaudio/best",
"merge_output_format": "mp4",
"progress_hooks": [hook],
+2 -1
View File
@@ -55,13 +55,14 @@ class DownloadRequest(BaseModel):
title: str
subtitle: str = ""
year: int | None = None
category: str = ""
@app.post("/api/download")
async def api_download(req: DownloadRequest, bg: BackgroundTasks):
if not req.url:
raise HTTPException(status_code=400, detail="url required")
dl_id = dm.enqueue(req.url, req.title, req.subtitle, req.year, bg)
dl_id = dm.enqueue(req.url, req.title, req.subtitle, req.year, req.category, bg)
return {"id": dl_id}
+3 -2
View File
@@ -110,9 +110,10 @@ function renderConcerts(data) {
const dl = state.downloadedUrls.has(c.url) ? `<span class="card-downloaded">✓ Téléchargé</span>` : '';
const date = fmtDate(c.upload_date);
const sub = c.subtitle ? `<div class="card-subtitle">${c.subtitle}</div>` : '';
const downloadedClass = state.downloadedUrls.has(c.url) ? 'downloaded' : '';
return `
<div class="card" data-id="${c.id}" tabindex="0" role="button" aria-label="${c.title}">
<div class="card ${downloadedClass}" data-id="${c.id}" tabindex="0" role="button" aria-label="${c.title}">
<div class="card-thumb-wrap">
${thumb}${dur}${dl}
</div>
@@ -270,7 +271,7 @@ $('btn-download').addEventListener('click', async () => {
const res = await fetch('/api/download', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ url: c.url, title: c.title, subtitle: c.subtitle || '', year }),
body: JSON.stringify({ url: c.url, title: c.title, subtitle: c.subtitle || '', year, category: state.category }),
});
const { id } = await res.json();
trackDownload(id, c.title, c.url);