From f07352bd04ebc04ddad98195fd8071b8766447a7 Mon Sep 17 00:00:00 2001 From: dev Date: Sat, 2 May 2026 19:16:36 +0200 Subject: [PATCH] =?UTF-8?q?feat:=20t=C3=A9l=C3=A9chargement=20dans=20sous-?= =?UTF-8?q?dossiers=20par=20cat=C3=A9gorie?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Sonnet 4.6 --- downloader.py | 11 ++++++----- main.py | 3 ++- static/app.js | 5 +++-- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/downloader.py b/downloader.py index ba6e9a1..621aa33 100644 --- a/downloader.py +++ b/downloader.py @@ -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], diff --git a/main.py b/main.py index f2a8c34..2dc2b0f 100644 --- a/main.py +++ b/main.py @@ -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} diff --git a/static/app.js b/static/app.js index 6097209..0024138 100644 --- a/static/app.js +++ b/static/app.js @@ -110,9 +110,10 @@ function renderConcerts(data) { const dl = state.downloadedUrls.has(c.url) ? `✓ Téléchargé` : ''; const date = fmtDate(c.upload_date); const sub = c.subtitle ? `
${c.subtitle}
` : ''; + const downloadedClass = state.downloadedUrls.has(c.url) ? 'downloaded' : ''; return ` -
+
${thumb}${dur}${dl}
@@ -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);