fix in download torrents

This commit is contained in:
Mateusz Gruszczyński
2026-05-22 14:04:26 +02:00
parent 6aea0c1ad9
commit 00a3831386
2 changed files with 6 additions and 6 deletions

View File

@@ -706,16 +706,16 @@ def export_torrent_file(profile: dict, torrent_hash: str) -> dict:
c = client_for(profile) c = client_for(profile)
name = str(c.call("d.name", torrent_hash) or torrent_hash).strip() or torrent_hash name = str(c.call("d.name", torrent_hash) or torrent_hash).strip() or torrent_hash
filename = f"{name}.torrent" if not name.lower().endswith(".torrent") else name filename = f"{name}.torrent" if not name.lower().endswith(".torrent") else name
source = _torrent_source_file(c, torrent_hash)
if source:
# Note: Stream the existing .torrent source directly instead of copying it to a temporary staged file first.
return {"path": source, "download_name": filename, "local": False}
raw = _torrent_raw_from_method(c, torrent_hash) raw = _torrent_raw_from_method(c, torrent_hash)
if raw: if raw:
target = LocalPath(download_tmp_dir()) / f"pytorrent-download-{uuid.uuid4().hex}.torrent" target = LocalPath(download_tmp_dir()) / f"pytorrent-download-{uuid.uuid4().hex}.torrent"
target.write_bytes(raw) target.write_bytes(raw)
return {"path": str(target), "download_name": filename, "local": True} return {"path": str(target), "download_name": filename, "local": True}
source = _torrent_source_file(c, torrent_hash)
if not source:
raise RuntimeError("Cannot find torrent source file in rTorrent") raise RuntimeError("Cannot find torrent source file in rTorrent")
staged = _remote_stage_path(c, source, ".torrent")
return {"path": staged, "download_name": filename, "local": False}
def set_file_priorities(profile: dict, torrent_hash: str, files: list[dict]) -> dict: def set_file_priorities(profile: dict, torrent_hash: str, files: list[dict]) -> dict:

File diff suppressed because one or more lines are too long