Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/NzbDrone.Core/Download/Clients/QBittorrent/QBittorrent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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="))
Expand All @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down