From ff3d638dc412a160a592489bf16141f4f186b945 Mon Sep 17 00:00:00 2001 From: benjitobz Date: Tue, 1 Sep 2026 11:00:27 -0400 Subject: [PATCH] Adopt an existing qBittorrent torrent instead of failing the grab Re-grabbing a release whose torrent already sits in qBittorrent made the add call fail with the clients bare Fails response and the grab errored out. When the add is refused, check whether that info-hash already exists in the client and, if so, continue with the existing download so the completed torrent imports normally. Genuine add failures still throw. --- .../Clients/QBittorrent/QBittorrent.cs | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/NzbDrone.Core/Download/Clients/QBittorrent/QBittorrent.cs b/src/NzbDrone.Core/Download/Clients/QBittorrent/QBittorrent.cs index fa2b9151..a92cfa97 100644 --- a/src/NzbDrone.Core/Download/Clients/QBittorrent/QBittorrent.cs +++ b/src/NzbDrone.Core/Download/Clients/QBittorrent/QBittorrent.cs @@ -91,6 +91,24 @@ public bool ShouldPreserveItemAfterImport(DownloadClientItem downloadClientItem) Settings.EbookImportedCategory); } + private bool TorrentExistsInClient(string hash) + { + if (hash.IsNullOrWhiteSpace()) + { + return false; + } + + try + { + return Proxy.GetTorrents(Settings).Any(t => hash.Equals(t.Hash, StringComparison.OrdinalIgnoreCase)); + } + catch (Exception ex) + { + _logger.Debug(ex, "Unable to check whether torrent {0} already exists in qBittorrent", hash); + return false; + } + } + protected override string AddFromMagnetLink(RemoteBook remoteBook, string hash, string magnetLink) { if (!Proxy.GetConfig(Settings).DhtEnabled && !magnetLink.Contains("&tr=")) @@ -113,6 +131,10 @@ protected override string AddFromMagnetLink(RemoteBook remoteBook, string hash, { throw new DownloadClientRejectedReleaseException(remoteBook.Release, "qBittorrent rejected the magnet link due to a conflict", ex); } + catch (DownloadClientException) when (TorrentExistsInClient(hash)) + { + _logger.Info("qBittorrent already has torrent {0}; adopting the existing download instead of failing the grab", hash); + } if ((!addHasSetShareLimits && setShareLimits) || moveToTop || forceStart) { @@ -178,6 +200,10 @@ protected override string AddFromTorrentFile(RemoteBook remoteBook, string hash, { throw new DownloadClientRejectedReleaseException(remoteBook.Release, "qBittorrent rejected the torrent file due to a conflict", ex); } + catch (DownloadClientException) when (TorrentExistsInClient(hash)) + { + _logger.Info("qBittorrent already has torrent {0}; adopting the existing download instead of failing the grab", hash); + } if ((!addHasSetShareLimits && setShareLimits) || moveToTop || forceStart) {