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) {