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)
|
ref = json.loads(source_ref)
|
||||||
username = ref["username"]
|
username = ref["username"]
|
||||||
files = ref["files"]
|
files = ref["files"]
|
||||||
|
wanted = {f["filename"] for f in files}
|
||||||
os.makedirs(dest, exist_ok=True)
|
os.makedirs(dest, exist_ok=True)
|
||||||
|
|
||||||
r = requests.post(
|
r = requests.post(
|
||||||
@@ -117,19 +118,24 @@ class SlskdClient:
|
|||||||
on_progress(0.0)
|
on_progress(0.0)
|
||||||
|
|
||||||
total = len(files)
|
total = len(files)
|
||||||
|
completed = False
|
||||||
for _ in range(_XFER_POLLS):
|
for _ in range(_XFER_POLLS):
|
||||||
time.sleep(_POLL_SECONDS)
|
time.sleep(_POLL_SECONDS)
|
||||||
data = self._get(f"/api/v0/transfers/downloads/{username}")
|
data = self._get(f"/api/v0/transfers/downloads/{username}")
|
||||||
states: list[str] = []
|
states: list[str] = []
|
||||||
for directory in data.get("directories", []) if isinstance(data, dict) else []:
|
for directory in data.get("directories", []) if isinstance(data, dict) else []:
|
||||||
for f in directory.get("files", []):
|
for f in directory.get("files", []):
|
||||||
states.append(str(f.get("state", "")))
|
if f.get("filename") in wanted: # only the files we enqueued
|
||||||
|
states.append(str(f.get("state", "")))
|
||||||
if states:
|
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")):
|
if any(bad in s for s in states for bad in ("Errored", "Rejected", "Cancelled")):
|
||||||
raise RuntimeError("soulseek transfer failed")
|
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:
|
if done >= total:
|
||||||
|
completed = True
|
||||||
break
|
break
|
||||||
|
|
||||||
|
if not completed:
|
||||||
|
raise TimeoutError(f"soulseek download did not complete for {username}")
|
||||||
return {"track_count": total, "path": dest}
|
return {"track_count": total, "path": dest}
|
||||||
|
|||||||
Reference in New Issue
Block a user