Skip to content

Commit efc4b38

Browse files
committed
fix: v1.9.8 — expired torrent reimport failed for torrent-file additions
Root cause: _handle_expired_reimport only reimported if the torrent had a magnet link stored in the DB. Torrents added via .torrent file or torrent URL (the majority when using Sonarr/Radarr or Jackett torrent_url) were stored with magnet=NULL. On expiry these fell into the else branch and were marked error: "Add magnet again to retry" — no automatic re-import. AllDebrid accepts plain hash magnets (magnet:?xt=urn:btih:<hash>) with identical behaviour to full magnet links. The infohash is always stored in the DB (extracted from the .torrent file or returned by AllDebrid on upload). Fix: if no magnet is stored, synthesize one from the infohash: magnet:?xt=urn:btih:<hash>&dn=<url-encoded-name> Three cases are now handled: 1. magnet stored → use it directly (existing behaviour, unchanged) 2. no magnet, hash stored (SHA-1 40 chars or SHA-256 64 chars) → synthesize magnet:?xt=urn:btih:<hash>&dn=<name>, reimport 3. no magnet, no hash → mark error with clear message (unchanged) The synthesized magnet is only used for the re-upload call; it is not written back to the DB (the original NULL is preserved). 292/292 tests passing
1 parent c298ce1 commit efc4b38

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.9.7
1+
1.9.8

backend/services/manager_v2.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1434,6 +1434,24 @@ async def _apply_provider_update(self, row: Dict, magnet: Dict, normalized: Dict
14341434
# magnet, silently re-upload it so the user does not need to intervene.
14351435
magnet_link = str(row.get("magnet") or "").strip()
14361436
torrent_name = str(row.get("name") or f"torrent {row['id']}")
1437+
1438+
# If no magnet was stored (e.g. added via .torrent file or torrent URL),
1439+
# synthesize a bare magnet from the infohash. AllDebrid accepts
1440+
# magnet:?xt=urn:btih:<hash> identically to full magnet links.
1441+
if not magnet_link:
1442+
stored_hash = str(row.get("hash") or "").strip().lower()
1443+
if stored_hash and len(stored_hash) in (40, 64): # SHA-1 or SHA-256 btih
1444+
import urllib.parse as _up
1445+
magnet_link = (
1446+
f"magnet:?xt=urn:btih:{stored_hash}"
1447+
f"&dn={_up.quote(torrent_name[:120])}"
1448+
)
1449+
logger.info(
1450+
"expired_reimport: no magnet stored for torrent %s — "
1451+
"synthesized from hash %s",
1452+
row["id"], stored_hash[:16],
1453+
)
1454+
14371455
if magnet_link:
14381456
logger.warning(
14391457
"Magnet expired on AllDebrid (torrent %s '%s') — reimporting",

0 commit comments

Comments
 (0)