feat(server): route URL/playlist /fetch to download jobs
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -61,3 +61,38 @@ def perform_fetch(chosen, hits: list, quality: str, root: str) -> dict:
|
||||
if not ok:
|
||||
raise RuntimeError("Failed to add artist to Lidarr.")
|
||||
return {"path": None, "lidarr_album_id": None}
|
||||
|
||||
|
||||
def url_started_message(kind: str, title: str = "") -> str:
|
||||
if kind == "playlist":
|
||||
return (f"Fetching playlist '{title}'. Downloading tracks now."
|
||||
if title else "Fetching playlist. Downloading tracks now.")
|
||||
return f"Fetching '{title}'. Downloading now." if title else "Fetching track. Downloading now."
|
||||
|
||||
|
||||
def playlist_done_message(result: dict) -> str:
|
||||
ok, total = result.get("ok", 0), result.get("total", 0)
|
||||
failed = total - ok
|
||||
return f"Downloaded {ok}/{total} tracks" + (f" ({failed} failed)." if failed else ".")
|
||||
|
||||
|
||||
def url_done_message(result: dict) -> str:
|
||||
title = result.get("title", "")
|
||||
return f"Downloaded '{title}'." if title else "Download complete."
|
||||
|
||||
|
||||
def perform_url_fetch(url: str, quality: str, root: str) -> dict:
|
||||
"""Download a URL (playlist -> batch, else single). Raises if nothing
|
||||
downloaded so the job is marked failed."""
|
||||
if mf.is_playlist_url(url):
|
||||
ok, total, title = mf.download_playlist(url, root, quality, False)
|
||||
if ok == 0:
|
||||
raise RuntimeError(f"No tracks downloaded from playlist '{title}'." if title
|
||||
else "No tracks downloaded from playlist.")
|
||||
return {"kind": "playlist", "title": title, "ok": ok, "total": total,
|
||||
"path": None, "lidarr_album_id": None}
|
||||
info = mf.download_single(url, root, quality, False)
|
||||
if not info.get("ok"):
|
||||
raise RuntimeError("Download failed.")
|
||||
return {"kind": "track", "title": info["title"], "artist": info["artist"],
|
||||
"ok": 1, "total": 1, "path": None, "lidarr_album_id": None}
|
||||
|
||||
Reference in New Issue
Block a user