From bea61edb4e1ed30328120f3088137c7c268abd16 Mon Sep 17 00:00:00 2001 From: Bogdan Date: Mon, 1 May 2023 20:05:52 +0300 Subject: [PATCH] Fix downloading releases without an indexer (cherry picked from commit ca8b26138e3ebd793cc1a5fd51522ce3eda8a2e1) Closes #2426 --- src/NzbDrone.Core/Download/DownloadService.cs | 8 +++++++- src/NzbDrone.Core/Download/TorrentClientBase.cs | 2 +- src/NzbDrone.Core/Download/UsenetClientBase.cs | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/NzbDrone.Core/Download/DownloadService.cs b/src/NzbDrone.Core/Download/DownloadService.cs index 21ad30364..1a22e6266 100644 --- a/src/NzbDrone.Core/Download/DownloadService.cs +++ b/src/NzbDrone.Core/Download/DownloadService.cs @@ -63,7 +63,6 @@ namespace NzbDrone.Core.Download // Get the seed configuration for this release. remoteBook.SeedConfiguration = _seedConfigProvider.GetSeedConfiguration(remoteBook); - var indexer = _indexerFactory.GetInstance(_indexerFactory.Get(remoteBook.Release.IndexerId)); // Limit grabs to 2 per second. if (remoteBook.Release.DownloadUrl.IsNotNullOrWhiteSpace() && !remoteBook.Release.DownloadUrl.StartsWith("magnet:")) @@ -72,6 +71,13 @@ namespace NzbDrone.Core.Download _rateLimitService.WaitAndPulse(url.Host, TimeSpan.FromSeconds(2)); } + IIndexer indexer = null; + + if (remoteBook.Release.IndexerId > 0) + { + indexer = _indexerFactory.GetInstance(_indexerFactory.Get(remoteBook.Release.IndexerId)); + } + string downloadClientId; try { diff --git a/src/NzbDrone.Core/Download/TorrentClientBase.cs b/src/NzbDrone.Core/Download/TorrentClientBase.cs index 77f29cc9f..bf398a898 100644 --- a/src/NzbDrone.Core/Download/TorrentClientBase.cs +++ b/src/NzbDrone.Core/Download/TorrentClientBase.cs @@ -127,7 +127,7 @@ namespace NzbDrone.Core.Download try { - var request = indexer.GetDownloadRequest(torrentUrl); + var request = indexer?.GetDownloadRequest(torrentUrl) ?? new HttpRequest(torrentUrl); request.RateLimitKey = remoteBook?.Release?.IndexerId.ToString(); request.Headers.Accept = "application/x-bittorrent"; request.AllowAutoRedirect = false; diff --git a/src/NzbDrone.Core/Download/UsenetClientBase.cs b/src/NzbDrone.Core/Download/UsenetClientBase.cs index 414fe66d3..8e412b062 100644 --- a/src/NzbDrone.Core/Download/UsenetClientBase.cs +++ b/src/NzbDrone.Core/Download/UsenetClientBase.cs @@ -44,7 +44,7 @@ namespace NzbDrone.Core.Download try { - var request = indexer.GetDownloadRequest(url); + var request = indexer?.GetDownloadRequest(url) ?? new HttpRequest(url); request.RateLimitKey = remoteBook?.Release?.IndexerId.ToString(); nzbData = _httpClient.Get(request).ResponseData;