fix: scope slskd download polling to enqueued files and raise on timeout
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -105,6 +105,7 @@ class SlskdClient:
|
||||
ref = json.loads(source_ref)
|
||||
username = ref["username"]
|
||||
files = ref["files"]
|
||||
wanted = {f["filename"] for f in files}
|
||||
os.makedirs(dest, exist_ok=True)
|
||||
|
||||
r = requests.post(
|
||||
@@ -117,19 +118,24 @@ class SlskdClient:
|
||||
on_progress(0.0)
|
||||
|
||||
total = len(files)
|
||||
completed = False
|
||||
for _ in range(_XFER_POLLS):
|
||||
time.sleep(_POLL_SECONDS)
|
||||
data = self._get(f"/api/v0/transfers/downloads/{username}")
|
||||
states: list[str] = []
|
||||
for directory in data.get("directories", []) if isinstance(data, dict) else []:
|
||||
for f in directory.get("files", []):
|
||||
if f.get("filename") in wanted: # only the files we enqueued
|
||||
states.append(str(f.get("state", "")))
|
||||
if states:
|
||||
done = sum(1 for s in states if "Completed" in s)
|
||||
on_progress(min(1.0, done / max(total, 1)))
|
||||
if any(bad in s for s in states for bad in ("Errored", "Rejected", "Cancelled")):
|
||||
raise RuntimeError("soulseek transfer failed")
|
||||
done = sum(1 for s in states if "Completed" in s)
|
||||
on_progress(min(1.0, done / max(total, 1)))
|
||||
if done >= total:
|
||||
completed = True
|
||||
break
|
||||
|
||||
if not completed:
|
||||
raise TimeoutError(f"soulseek download did not complete for {username}")
|
||||
return {"track_count": total, "path": dest}
|
||||
|
||||
Reference in New Issue
Block a user