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:
+6
-5
@@ -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],
|
||||
|
||||
Reference in New Issue
Block a user