From 1807ccfc48440216513c4023ac2b88e15d6860c4 Mon Sep 17 00:00:00 2001 From: Bogdan Date: Sun, 30 Apr 2023 07:09:11 +0300 Subject: [PATCH] Build download requests from indexer implementation (cherry picked from commit a0b08f6c6f106d92cdb12fbb959dd2605c22fe6a) --- .../Blackhole/TorrentBlackholeFixture.cs | 16 ++++---- .../Blackhole/UsenetBlackholeFixture.cs | 4 +- .../DelugeTests/DelugeFixture.cs | 4 +- .../DownloadClientFixtureBase.cs | 12 ++++++ .../TorrentDownloadStationFixture.cs | 8 ++-- .../UsenetDownloadStationFixture.cs | 8 ++-- .../TorrentFreeboxDownloadFixture.cs | 12 +++--- .../HadoukenTests/HadoukenFixture.cs | 6 +-- .../NzbVortexTests/NzbVortexFixture.cs | 4 +- .../NzbgetTests/NzbgetFixture.cs | 4 +- .../PneumaticProviderFixture.cs | 18 +++++++-- .../QBittorrentTests/QBittorrentFixture.cs | 16 ++++---- .../RTorrentTests/RTorrentFixture.cs | 2 +- .../SabnzbdTests/SabnzbdFixture.cs | 6 +-- .../TransmissionTests/TransmissionFixture.cs | 12 +++--- .../UTorrentTests/UTorrentFixture.cs | 8 ++-- .../VuzeTests/VuzeFixture.cs | 12 +++--- .../Download/DownloadServiceFixture.cs | 38 +++++++++---------- .../Download/Clients/Pneumatic/Pneumatic.cs | 2 +- .../Download/DownloadClientBase.cs | 2 +- src/NzbDrone.Core/Download/DownloadService.cs | 6 ++- src/NzbDrone.Core/Download/IDownloadClient.cs | 2 +- .../Download/TorrentClientBase.cs | 14 ++++--- .../Download/UsenetClientBase.cs | 4 +- src/NzbDrone.Core/Indexers/HttpIndexerBase.cs | 5 +++ src/NzbDrone.Core/Indexers/IIndexer.cs | 2 + src/NzbDrone.Core/Indexers/IndexerBase.cs | 2 + 27 files changed, 134 insertions(+), 95 deletions(-) diff --git a/src/NzbDrone.Core.Test/Download/DownloadClientTests/Blackhole/TorrentBlackholeFixture.cs b/src/NzbDrone.Core.Test/Download/DownloadClientTests/Blackhole/TorrentBlackholeFixture.cs index 018309d5f..585561230 100644 --- a/src/NzbDrone.Core.Test/Download/DownloadClientTests/Blackhole/TorrentBlackholeFixture.cs +++ b/src/NzbDrone.Core.Test/Download/DownloadClientTests/Blackhole/TorrentBlackholeFixture.cs @@ -148,7 +148,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.Blackhole { var remoteMovie = CreateRemoteMovie(); - Subject.Download(remoteMovie); + Subject.Download(remoteMovie, CreateIndexer()); Mocker.GetMock().Verify(c => c.Get(It.Is(v => v.Url.FullUri == _downloadUrl)), Times.Once()); Mocker.GetMock().Verify(c => c.OpenWriteStream(_filePath), Times.Once()); @@ -164,7 +164,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.Blackhole var remoteMovie = CreateRemoteMovie(); remoteMovie.Release.DownloadUrl = null; - Subject.Download(remoteMovie); + Subject.Download(remoteMovie, CreateIndexer()); Mocker.GetMock().Verify(c => c.Get(It.Is(v => v.Url.FullUri == _downloadUrl)), Times.Never()); Mocker.GetMock().Verify(c => c.OpenWriteStream(_filePath), Times.Never()); @@ -183,7 +183,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.Blackhole var remoteMovie = CreateRemoteMovie(); remoteMovie.Release.DownloadUrl = null; - Subject.Download(remoteMovie); + Subject.Download(remoteMovie, CreateIndexer()); Mocker.GetMock().Verify(c => c.Get(It.Is(v => v.Url.FullUri == _downloadUrl)), Times.Never()); Mocker.GetMock().Verify(c => c.OpenWriteStream(_filePath), Times.Never()); @@ -197,7 +197,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.Blackhole var remoteMovie = CreateRemoteMovie(); remoteMovie.Release.DownloadUrl = null; - Assert.Throws(() => Subject.Download(remoteMovie)); + Assert.Throws(() => Subject.Download(remoteMovie, CreateIndexer())); Mocker.GetMock().Verify(c => c.Get(It.Is(v => v.Url.FullUri == _downloadUrl)), Times.Never()); Mocker.GetMock().Verify(c => c.OpenWriteStream(_filePath), Times.Never()); @@ -212,7 +212,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.Blackhole var remoteMovie = CreateRemoteMovie(); - Subject.Download(remoteMovie); + Subject.Download(remoteMovie, CreateIndexer()); Mocker.GetMock().Verify(c => c.Get(It.Is(v => v.Url.FullUri == _downloadUrl)), Times.Once()); Mocker.GetMock().Verify(c => c.OpenWriteStream(_filePath), Times.Once()); @@ -229,7 +229,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.Blackhole var remoteMovie = CreateRemoteMovie(); remoteMovie.Release.Title = illegalTitle; - Subject.Download(remoteMovie); + Subject.Download(remoteMovie, CreateIndexer()); Mocker.GetMock().Verify(c => c.Get(It.Is(v => v.Url.FullUri == _downloadUrl)), Times.Once()); Mocker.GetMock().Verify(c => c.OpenWriteStream(expectedFilename), Times.Once()); @@ -242,7 +242,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.Blackhole var remoteMovie = CreateRemoteMovie(); remoteMovie.Release.DownloadUrl = null; - Assert.Throws(() => Subject.Download(remoteMovie)); + Assert.Throws(() => Subject.Download(remoteMovie, CreateIndexer())); } [Test] @@ -316,7 +316,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.Blackhole { var remoteMovie = CreateRemoteMovie(); - Subject.Download(remoteMovie).Should().BeNull(); + Subject.Download(remoteMovie, CreateIndexer()).Should().BeNull(); } } } diff --git a/src/NzbDrone.Core.Test/Download/DownloadClientTests/Blackhole/UsenetBlackholeFixture.cs b/src/NzbDrone.Core.Test/Download/DownloadClientTests/Blackhole/UsenetBlackholeFixture.cs index 7f12a30d6..3b34022d5 100644 --- a/src/NzbDrone.Core.Test/Download/DownloadClientTests/Blackhole/UsenetBlackholeFixture.cs +++ b/src/NzbDrone.Core.Test/Download/DownloadClientTests/Blackhole/UsenetBlackholeFixture.cs @@ -119,7 +119,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.Blackhole { var remoteMovie = CreateRemoteMovie(); - Subject.Download(remoteMovie); + Subject.Download(remoteMovie, CreateIndexer()); Mocker.GetMock().Verify(c => c.Get(It.Is(v => v.Url.FullUri == _downloadUrl)), Times.Once()); Mocker.GetMock().Verify(c => c.OpenWriteStream(_filePath), Times.Once()); @@ -135,7 +135,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.Blackhole var remoteMovie = CreateRemoteMovie(); remoteMovie.Release.Title = illegalTitle; - Subject.Download(remoteMovie); + Subject.Download(remoteMovie, CreateIndexer()); Mocker.GetMock().Verify(c => c.Get(It.Is(v => v.Url.FullUri == _downloadUrl)), Times.Once()); Mocker.GetMock().Verify(c => c.OpenWriteStream(expectedFilename), Times.Once()); diff --git a/src/NzbDrone.Core.Test/Download/DownloadClientTests/DelugeTests/DelugeFixture.cs b/src/NzbDrone.Core.Test/Download/DownloadClientTests/DelugeTests/DelugeFixture.cs index b971db30e..1bf50d37b 100644 --- a/src/NzbDrone.Core.Test/Download/DownloadClientTests/DelugeTests/DelugeFixture.cs +++ b/src/NzbDrone.Core.Test/Download/DownloadClientTests/DelugeTests/DelugeFixture.cs @@ -206,7 +206,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DelugeTests var remoteMovie = CreateRemoteMovie(); - var id = Subject.Download(remoteMovie); + var id = Subject.Download(remoteMovie, CreateIndexer()); id.Should().NotBeNullOrEmpty(); } @@ -219,7 +219,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DelugeTests var remoteMovie = CreateRemoteMovie(); remoteMovie.Release.DownloadUrl = magnetUrl; - var id = Subject.Download(remoteMovie); + var id = Subject.Download(remoteMovie, CreateIndexer()); id.Should().Be(expectedHash); } diff --git a/src/NzbDrone.Core.Test/Download/DownloadClientTests/DownloadClientFixtureBase.cs b/src/NzbDrone.Core.Test/Download/DownloadClientTests/DownloadClientFixtureBase.cs index 4d51d52e2..1518227a1 100644 --- a/src/NzbDrone.Core.Test/Download/DownloadClientTests/DownloadClientFixtureBase.cs +++ b/src/NzbDrone.Core.Test/Download/DownloadClientTests/DownloadClientFixtureBase.cs @@ -1,17 +1,20 @@ using System; using FluentAssertions; using Moq; +using NLog; using NUnit.Framework; using NzbDrone.Common.Disk; using NzbDrone.Common.Http; using NzbDrone.Core.Configuration; using NzbDrone.Core.Download; +using NzbDrone.Core.Indexers; using NzbDrone.Core.IndexerSearch.Definitions; using NzbDrone.Core.Movies; using NzbDrone.Core.Parser; using NzbDrone.Core.Parser.Model; using NzbDrone.Core.RemotePathMappings; using NzbDrone.Core.Test.Framework; +using NzbDrone.Core.Test.IndexerTests; namespace NzbDrone.Core.Test.Download.DownloadClientTests { @@ -56,6 +59,15 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests return remoteMovie; } + protected virtual IIndexer CreateIndexer() + { + return new TestIndexer(Mocker.Resolve(), + Mocker.Resolve(), + Mocker.Resolve(), + Mocker.Resolve(), + Mocker.Resolve()); + } + protected void VerifyIdentifiable(DownloadClientItem downloadClientItem) { downloadClientItem.DownloadClientInfo.Protocol.Should().Be(Subject.Protocol); diff --git a/src/NzbDrone.Core.Test/Download/DownloadClientTests/DownloadStationTests/TorrentDownloadStationFixture.cs b/src/NzbDrone.Core.Test/Download/DownloadClientTests/DownloadStationTests/TorrentDownloadStationFixture.cs index 4f0e7cd66..feca091df 100644 --- a/src/NzbDrone.Core.Test/Download/DownloadClientTests/DownloadStationTests/TorrentDownloadStationFixture.cs +++ b/src/NzbDrone.Core.Test/Download/DownloadClientTests/DownloadStationTests/TorrentDownloadStationFixture.cs @@ -393,7 +393,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests var remoteEpisode = CreateRemoteMovie(); - var id = Subject.Download(remoteEpisode); + var id = Subject.Download(remoteEpisode, CreateIndexer()); id.Should().NotBeNullOrEmpty(); @@ -410,7 +410,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests var remoteEpisode = CreateRemoteMovie(); - var id = Subject.Download(remoteEpisode); + var id = Subject.Download(remoteEpisode, CreateIndexer()); id.Should().NotBeNullOrEmpty(); @@ -426,7 +426,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests var remoteEpisode = CreateRemoteMovie(); - var id = Subject.Download(remoteEpisode); + var id = Subject.Download(remoteEpisode, CreateIndexer()); id.Should().NotBeNullOrEmpty(); @@ -505,7 +505,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests .Setup(s => s.GetSerialNumber(_settings)) .Throws(new ApplicationException("Some unknown exception, HttpException or DownloadClientException")); - Assert.Throws(Is.InstanceOf(), () => Subject.Download(remoteEpisode)); + Assert.Throws(Is.InstanceOf(), () => Subject.Download(remoteEpisode, CreateIndexer())); Mocker.GetMock() .Verify(v => v.AddTaskFromUrl(It.IsAny(), null, _settings), Times.Never()); diff --git a/src/NzbDrone.Core.Test/Download/DownloadClientTests/DownloadStationTests/UsenetDownloadStationFixture.cs b/src/NzbDrone.Core.Test/Download/DownloadClientTests/DownloadStationTests/UsenetDownloadStationFixture.cs index 9abfd1e2d..8354c7c6c 100644 --- a/src/NzbDrone.Core.Test/Download/DownloadClientTests/DownloadStationTests/UsenetDownloadStationFixture.cs +++ b/src/NzbDrone.Core.Test/Download/DownloadClientTests/DownloadStationTests/UsenetDownloadStationFixture.cs @@ -275,7 +275,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests var remoteEpisode = CreateRemoteMovie(); - var id = Subject.Download(remoteEpisode); + var id = Subject.Download(remoteEpisode, CreateIndexer()); id.Should().NotBeNullOrEmpty(); @@ -292,7 +292,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests var remoteEpisode = CreateRemoteMovie(); - var id = Subject.Download(remoteEpisode); + var id = Subject.Download(remoteEpisode, CreateIndexer()); id.Should().NotBeNullOrEmpty(); @@ -308,7 +308,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests var remoteEpisode = CreateRemoteMovie(); - var id = Subject.Download(remoteEpisode); + var id = Subject.Download(remoteEpisode, CreateIndexer()); id.Should().NotBeNullOrEmpty(); @@ -387,7 +387,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests .Setup(s => s.GetSerialNumber(_settings)) .Throws(new ApplicationException("Some unknown exception, HttpException or DownloadClientException")); - Assert.Throws(Is.InstanceOf(), () => Subject.Download(remoteEpisode)); + Assert.Throws(Is.InstanceOf(), () => Subject.Download(remoteEpisode, CreateIndexer())); Mocker.GetMock() .Verify(v => v.AddTaskFromUrl(It.IsAny(), null, _settings), Times.Never()); diff --git a/src/NzbDrone.Core.Test/Download/DownloadClientTests/FreeboxDownloadTests/TorrentFreeboxDownloadFixture.cs b/src/NzbDrone.Core.Test/Download/DownloadClientTests/FreeboxDownloadTests/TorrentFreeboxDownloadFixture.cs index d7e5d1212..3596bda7f 100644 --- a/src/NzbDrone.Core.Test/Download/DownloadClientTests/FreeboxDownloadTests/TorrentFreeboxDownloadFixture.cs +++ b/src/NzbDrone.Core.Test/Download/DownloadClientTests/FreeboxDownloadTests/TorrentFreeboxDownloadFixture.cs @@ -154,7 +154,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.FreeboxDownloadTests var remoteMovie = CreateRemoteMovie(); - Subject.Download(remoteMovie); + Subject.Download(remoteMovie, CreateIndexer()); Mocker.GetMock() .Verify(v => v.AddTaskFromUrl(It.IsAny(), _encodedDestinationDirectory, It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny()), Times.Once()); @@ -169,7 +169,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.FreeboxDownloadTests var remoteMovie = CreateRemoteMovie(); - Subject.Download(remoteMovie); + Subject.Download(remoteMovie, CreateIndexer()); Mocker.GetMock() .Verify(v => v.AddTaskFromUrl(It.IsAny(), _encodedDefaultDestinationAndCategory, It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny()), Times.Once()); @@ -183,7 +183,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.FreeboxDownloadTests var remoteMovie = CreateRemoteMovie(); - Subject.Download(remoteMovie); + Subject.Download(remoteMovie, CreateIndexer()); Mocker.GetMock() .Verify(v => v.AddTaskFromUrl(It.IsAny(), _encodedDefaultDestination, It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny()), Times.Once()); @@ -200,7 +200,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.FreeboxDownloadTests var remoteMovie = CreateRemoteMovie(); - Subject.Download(remoteMovie); + Subject.Download(remoteMovie, CreateIndexer()); Mocker.GetMock() .Verify(v => v.AddTaskFromUrl(It.IsAny(), It.IsAny(), toBePausedFlag, It.IsAny(), It.IsAny(), It.IsAny()), Times.Once()); @@ -226,7 +226,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.FreeboxDownloadTests remoteMovie.Movie.MovieMetadata.Value.PhysicalRelease = DateTime.UtcNow.AddDays(-ageDay); - Subject.Download(remoteMovie); + Subject.Download(remoteMovie, CreateIndexer()); Mocker.GetMock() .Verify(v => v.AddTaskFromUrl(It.IsAny(), It.IsAny(), It.IsAny(), toBeQueuedFirstFlag, It.IsAny(), It.IsAny()), Times.Once()); @@ -244,7 +244,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.FreeboxDownloadTests remoteMovie.SeedConfiguration = new TorrentSeedConfiguration(); remoteMovie.SeedConfiguration.Ratio = providerSeedRatio; - Subject.Download(remoteMovie); + Subject.Download(remoteMovie, CreateIndexer()); Mocker.GetMock() .Verify(v => v.AddTaskFromUrl(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), expectedSeedRatio, It.IsAny()), Times.Once()); diff --git a/src/NzbDrone.Core.Test/Download/DownloadClientTests/HadoukenTests/HadoukenFixture.cs b/src/NzbDrone.Core.Test/Download/DownloadClientTests/HadoukenTests/HadoukenFixture.cs index aecc604e3..0199e0e82 100644 --- a/src/NzbDrone.Core.Test/Download/DownloadClientTests/HadoukenTests/HadoukenFixture.cs +++ b/src/NzbDrone.Core.Test/Download/DownloadClientTests/HadoukenTests/HadoukenFixture.cs @@ -202,7 +202,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.HadoukenTests var remoteMovie = CreateRemoteMovie(); - var id = Subject.Download(remoteMovie); + var id = Subject.Download(remoteMovie, CreateIndexer()); id.Should().NotBeNullOrEmpty(); } @@ -286,7 +286,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.HadoukenTests Mocker.GetMock() .Setup(v => v.AddTorrentUri(It.IsAny(), It.IsAny())); - var result = Subject.Download(remoteMovie); + var result = Subject.Download(remoteMovie, CreateIndexer()); Assert.IsFalse(result.Any(c => char.IsLower(c))); } @@ -300,7 +300,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.HadoukenTests .Setup(v => v.AddTorrentFile(It.IsAny(), It.IsAny())) .Returns("hash"); - var result = Subject.Download(remoteMovie); + var result = Subject.Download(remoteMovie, CreateIndexer()); Assert.IsFalse(result.Any(c => char.IsLower(c))); } diff --git a/src/NzbDrone.Core.Test/Download/DownloadClientTests/NzbVortexTests/NzbVortexFixture.cs b/src/NzbDrone.Core.Test/Download/DownloadClientTests/NzbVortexTests/NzbVortexFixture.cs index 535bef92f..4e6213d24 100644 --- a/src/NzbDrone.Core.Test/Download/DownloadClientTests/NzbVortexTests/NzbVortexFixture.cs +++ b/src/NzbDrone.Core.Test/Download/DownloadClientTests/NzbVortexTests/NzbVortexFixture.cs @@ -206,7 +206,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.NzbVortexTests var remoteMovie = CreateRemoteMovie(); - var id = Subject.Download(remoteMovie); + var id = Subject.Download(remoteMovie, CreateIndexer()); id.Should().NotBeNullOrEmpty(); } @@ -218,7 +218,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.NzbVortexTests var remoteMovie = CreateRemoteMovie(); - Assert.Throws(() => Subject.Download(remoteMovie)); + Assert.Throws(() => Subject.Download(remoteMovie, CreateIndexer())); } [Test] diff --git a/src/NzbDrone.Core.Test/Download/DownloadClientTests/NzbgetTests/NzbgetFixture.cs b/src/NzbDrone.Core.Test/Download/DownloadClientTests/NzbgetTests/NzbgetFixture.cs index 8b2d6a777..2f8871825 100644 --- a/src/NzbDrone.Core.Test/Download/DownloadClientTests/NzbgetTests/NzbgetFixture.cs +++ b/src/NzbDrone.Core.Test/Download/DownloadClientTests/NzbgetTests/NzbgetFixture.cs @@ -345,7 +345,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.NzbgetTests var remoteMovie = CreateRemoteMovie(); - var id = Subject.Download(remoteMovie); + var id = Subject.Download(remoteMovie, CreateIndexer()); id.Should().NotBeNullOrEmpty(); } @@ -357,7 +357,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.NzbgetTests var remoteMovie = CreateRemoteMovie(); - Assert.Throws(() => Subject.Download(remoteMovie)); + Assert.Throws(() => Subject.Download(remoteMovie, CreateIndexer())); } [Test] diff --git a/src/NzbDrone.Core.Test/Download/DownloadClientTests/PneumaticProviderFixture.cs b/src/NzbDrone.Core.Test/Download/DownloadClientTests/PneumaticProviderFixture.cs index 82743c431..df3253d16 100644 --- a/src/NzbDrone.Core.Test/Download/DownloadClientTests/PneumaticProviderFixture.cs +++ b/src/NzbDrone.Core.Test/Download/DownloadClientTests/PneumaticProviderFixture.cs @@ -3,12 +3,17 @@ using System.IO; using System.Net; using FizzWare.NBuilder; using Moq; +using NLog; using NUnit.Framework; using NzbDrone.Common.Http; +using NzbDrone.Core.Configuration; using NzbDrone.Core.Download; using NzbDrone.Core.Download.Clients.Pneumatic; +using NzbDrone.Core.Indexers; +using NzbDrone.Core.Parser; using NzbDrone.Core.Parser.Model; using NzbDrone.Core.Test.Framework; +using NzbDrone.Core.Test.IndexerTests; using NzbDrone.Test.Common; namespace NzbDrone.Core.Test.Download.DownloadClientTests @@ -22,6 +27,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests private string _strmFolder; private string _nzbPath; private RemoteMovie _remoteMovie; + private IIndexer _indexer; private DownloadClientItem _downloadClientItem; [SetUp] @@ -39,6 +45,12 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests _remoteMovie.ParsedMovieInfo = new ParsedMovieInfo(); + _indexer = new TestIndexer(Mocker.Resolve(), + Mocker.Resolve(), + Mocker.Resolve(), + Mocker.Resolve(), + Mocker.Resolve()); + _downloadClientItem = Builder .CreateNew().With(d => d.DownloadId = "_Droned.S01E01.Pilot.1080p.WEB-DL-DRONE_0") .Build(); @@ -59,7 +71,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests [Test] public void should_download_file_if_it_doesnt_exist() { - Subject.Download(_remoteMovie); + Subject.Download(_remoteMovie, _indexer); Mocker.GetMock().Verify(c => c.DownloadFile(_nzbUrl, _nzbPath), Times.Once()); } @@ -69,7 +81,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests { WithFailedDownload(); - Assert.Throws(() => Subject.Download(_remoteMovie)); + Assert.Throws(() => Subject.Download(_remoteMovie, _indexer)); } [Test] @@ -85,7 +97,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests var expectedFilename = Path.Combine(_pneumaticFolder, "Saturday Night Live - S38E08 - Jeremy Renner+Maroon 5 [SDTV].nzb"); _remoteMovie.Release.Title = illegalTitle; - Subject.Download(_remoteMovie); + Subject.Download(_remoteMovie, _indexer); Mocker.GetMock().Verify(c => c.DownloadFile(It.IsAny(), expectedFilename), Times.Once()); } diff --git a/src/NzbDrone.Core.Test/Download/DownloadClientTests/QBittorrentTests/QBittorrentFixture.cs b/src/NzbDrone.Core.Test/Download/DownloadClientTests/QBittorrentTests/QBittorrentFixture.cs index b9b8008b2..9f54fa368 100644 --- a/src/NzbDrone.Core.Test/Download/DownloadClientTests/QBittorrentTests/QBittorrentFixture.cs +++ b/src/NzbDrone.Core.Test/Download/DownloadClientTests/QBittorrentTests/QBittorrentFixture.cs @@ -453,7 +453,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.QBittorrentTests var remoteMovie = CreateRemoteMovie(); - var id = Subject.Download(remoteMovie); + var id = Subject.Download(remoteMovie, CreateIndexer()); id.Should().NotBeNullOrEmpty(); } @@ -466,7 +466,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.QBittorrentTests var remoteMovie = CreateRemoteMovie(); remoteMovie.Release.DownloadUrl = magnetUrl; - var id = Subject.Download(remoteMovie); + var id = Subject.Download(remoteMovie, CreateIndexer()); id.Should().Be(expectedHash); } @@ -481,7 +481,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.QBittorrentTests var remoteMovie = CreateRemoteMovie(); remoteMovie.Release.DownloadUrl = "magnet:?xt=urn:btih:ZPBPA2P6ROZPKRHK44D5OW6NHXU5Z6KR"; - Assert.Throws(() => Subject.Download(remoteMovie)); + Assert.Throws(() => Subject.Download(remoteMovie, CreateIndexer())); } [Test] @@ -494,7 +494,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.QBittorrentTests var remoteMovie = CreateRemoteMovie(); remoteMovie.Release.DownloadUrl = "magnet:?xt=urn:btih:ZPBPA2P6ROZPKRHK44D5OW6NHXU5Z6KR&tr=udp://abc"; - Assert.DoesNotThrow(() => Subject.Download(remoteMovie)); + Assert.DoesNotThrow(() => Subject.Download(remoteMovie, CreateIndexer())); Mocker.GetMock() .Verify(s => s.AddTorrentFromUrl(It.IsAny(), It.IsAny(), It.IsAny()), Times.Once()); @@ -508,7 +508,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.QBittorrentTests var remoteMovie = CreateRemoteMovie(); - var id = Subject.Download(remoteMovie); + var id = Subject.Download(remoteMovie, CreateIndexer()); Mocker.GetMock() .Verify(v => v.MoveTorrentToTopInQueue(It.IsAny(), It.IsAny()), Times.Once()); @@ -526,7 +526,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.QBittorrentTests var remoteMovie = CreateRemoteMovie(); - var id = Subject.Download(remoteMovie); + var id = Subject.Download(remoteMovie, CreateIndexer()); id.Should().NotBeNullOrEmpty(); @@ -560,7 +560,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.QBittorrentTests var remoteMovie = CreateRemoteMovie(); - var id = Subject.Download(remoteMovie); + var id = Subject.Download(remoteMovie, CreateIndexer()); id.Should().NotBeNullOrEmpty(); } @@ -573,7 +573,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.QBittorrentTests var remoteMovie = CreateRemoteMovie(); - var id = Subject.Download(remoteMovie); + var id = Subject.Download(remoteMovie, CreateIndexer()); id.Should().NotBeNullOrEmpty(); } diff --git a/src/NzbDrone.Core.Test/Download/DownloadClientTests/RTorrentTests/RTorrentFixture.cs b/src/NzbDrone.Core.Test/Download/DownloadClientTests/RTorrentTests/RTorrentFixture.cs index af08fa8b8..f63cd5c40 100644 --- a/src/NzbDrone.Core.Test/Download/DownloadClientTests/RTorrentTests/RTorrentFixture.cs +++ b/src/NzbDrone.Core.Test/Download/DownloadClientTests/RTorrentTests/RTorrentFixture.cs @@ -117,7 +117,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.RTorrentTests var remoteEpisode = CreateRemoteMovie(); - var id = Subject.Download(remoteEpisode); + var id = Subject.Download(remoteEpisode, CreateIndexer()); id.Should().NotBeNullOrEmpty(); } diff --git a/src/NzbDrone.Core.Test/Download/DownloadClientTests/SabnzbdTests/SabnzbdFixture.cs b/src/NzbDrone.Core.Test/Download/DownloadClientTests/SabnzbdTests/SabnzbdFixture.cs index c9ae1e25b..7f4351caf 100644 --- a/src/NzbDrone.Core.Test/Download/DownloadClientTests/SabnzbdTests/SabnzbdFixture.cs +++ b/src/NzbDrone.Core.Test/Download/DownloadClientTests/SabnzbdTests/SabnzbdFixture.cs @@ -306,7 +306,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.SabnzbdTests var remoteMovie = CreateRemoteMovie(); remoteMovie.Release.Title = title; - var id = Subject.Download(remoteMovie); + var id = Subject.Download(remoteMovie, CreateIndexer()); Mocker.GetMock() .Verify(v => v.DownloadNzb(It.IsAny(), filename, It.IsAny(), It.IsAny(), It.IsAny()), Times.Once()); @@ -319,7 +319,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.SabnzbdTests var remoteMovie = CreateRemoteMovie(); - var id = Subject.Download(remoteMovie); + var id = Subject.Download(remoteMovie, CreateIndexer()); id.Should().NotBeNullOrEmpty(); } @@ -366,7 +366,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.SabnzbdTests .Build() .ToList();*/ - Subject.Download(remoteMovie); + Subject.Download(remoteMovie, CreateIndexer()); Mocker.GetMock() .Verify(v => v.DownloadNzb(It.IsAny(), It.IsAny(), It.IsAny(), (int)SabnzbdPriority.High, It.IsAny()), Times.Once()); diff --git a/src/NzbDrone.Core.Test/Download/DownloadClientTests/TransmissionTests/TransmissionFixture.cs b/src/NzbDrone.Core.Test/Download/DownloadClientTests/TransmissionTests/TransmissionFixture.cs index 4d3c55c6f..35b888d02 100644 --- a/src/NzbDrone.Core.Test/Download/DownloadClientTests/TransmissionTests/TransmissionFixture.cs +++ b/src/NzbDrone.Core.Test/Download/DownloadClientTests/TransmissionTests/TransmissionFixture.cs @@ -61,7 +61,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.TransmissionTests var remoteMovie = CreateRemoteMovie(); - var id = Subject.Download(remoteMovie); + var id = Subject.Download(remoteMovie, CreateIndexer()); id.Should().NotBeNullOrEmpty(); } @@ -74,7 +74,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.TransmissionTests var remoteMovie = CreateRemoteMovie(); - var id = Subject.Download(remoteMovie); + var id = Subject.Download(remoteMovie, CreateIndexer()); id.Should().NotBeNullOrEmpty(); @@ -90,7 +90,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.TransmissionTests var remoteMovie = CreateRemoteMovie(); - var id = Subject.Download(remoteMovie); + var id = Subject.Download(remoteMovie, CreateIndexer()); id.Should().NotBeNullOrEmpty(); @@ -108,7 +108,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.TransmissionTests var remoteMovie = CreateRemoteMovie(); - var id = Subject.Download(remoteMovie); + var id = Subject.Download(remoteMovie, CreateIndexer()); id.Should().NotBeNullOrEmpty(); @@ -123,7 +123,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.TransmissionTests var remoteMovie = CreateRemoteMovie(); - var id = Subject.Download(remoteMovie); + var id = Subject.Download(remoteMovie, CreateIndexer()); id.Should().NotBeNullOrEmpty(); @@ -139,7 +139,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.TransmissionTests var remoteMovie = CreateRemoteMovie(); remoteMovie.Release.DownloadUrl = magnetUrl; - var id = Subject.Download(remoteMovie); + var id = Subject.Download(remoteMovie, CreateIndexer()); id.Should().Be(expectedHash); } diff --git a/src/NzbDrone.Core.Test/Download/DownloadClientTests/UTorrentTests/UTorrentFixture.cs b/src/NzbDrone.Core.Test/Download/DownloadClientTests/UTorrentTests/UTorrentFixture.cs index 762dddeaf..d724bf90b 100644 --- a/src/NzbDrone.Core.Test/Download/DownloadClientTests/UTorrentTests/UTorrentFixture.cs +++ b/src/NzbDrone.Core.Test/Download/DownloadClientTests/UTorrentTests/UTorrentFixture.cs @@ -234,7 +234,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.UTorrentTests var remoteMovie = CreateRemoteMovie(); - var id = Subject.Download(remoteMovie); + var id = Subject.Download(remoteMovie, CreateIndexer()); id.Should().NotBeNullOrEmpty(); } @@ -259,7 +259,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.UTorrentTests var remoteMovie = CreateRemoteMovie(); remoteMovie.Release.DownloadUrl = magnetUrl; - var id = Subject.Download(remoteMovie); + var id = Subject.Download(remoteMovie, CreateIndexer()); id.Should().Be(expectedHash); } @@ -357,7 +357,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.UTorrentTests var remoteMovie = CreateRemoteMovie(); - var id = Subject.Download(remoteMovie); + var id = Subject.Download(remoteMovie, CreateIndexer()); id.Should().NotBeNullOrEmpty(); } @@ -370,7 +370,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.UTorrentTests var remoteMovie = CreateRemoteMovie(); - var id = Subject.Download(remoteMovie); + var id = Subject.Download(remoteMovie, CreateIndexer()); id.Should().NotBeNullOrEmpty(); } diff --git a/src/NzbDrone.Core.Test/Download/DownloadClientTests/VuzeTests/VuzeFixture.cs b/src/NzbDrone.Core.Test/Download/DownloadClientTests/VuzeTests/VuzeFixture.cs index 61d00a194..d6ea954be 100644 --- a/src/NzbDrone.Core.Test/Download/DownloadClientTests/VuzeTests/VuzeFixture.cs +++ b/src/NzbDrone.Core.Test/Download/DownloadClientTests/VuzeTests/VuzeFixture.cs @@ -69,7 +69,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.VuzeTests var remoteMovie = CreateRemoteMovie(); - var id = Subject.Download(remoteMovie); + var id = Subject.Download(remoteMovie, CreateIndexer()); id.Should().NotBeNullOrEmpty(); } @@ -82,7 +82,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.VuzeTests var remoteMovie = CreateRemoteMovie(); - var id = Subject.Download(remoteMovie); + var id = Subject.Download(remoteMovie, CreateIndexer()); id.Should().NotBeNullOrEmpty(); @@ -98,7 +98,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.VuzeTests var remoteMovie = CreateRemoteMovie(); - var id = Subject.Download(remoteMovie); + var id = Subject.Download(remoteMovie, CreateIndexer()); id.Should().NotBeNullOrEmpty(); @@ -116,7 +116,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.VuzeTests var remoteMovie = CreateRemoteMovie(); - var id = Subject.Download(remoteMovie); + var id = Subject.Download(remoteMovie, CreateIndexer()); id.Should().NotBeNullOrEmpty(); @@ -131,7 +131,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.VuzeTests var remoteMovie = CreateRemoteMovie(); - var id = Subject.Download(remoteMovie); + var id = Subject.Download(remoteMovie, CreateIndexer()); id.Should().NotBeNullOrEmpty(); @@ -147,7 +147,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.VuzeTests var remoteMovie = CreateRemoteMovie(); remoteMovie.Release.DownloadUrl = magnetUrl; - var id = Subject.Download(remoteMovie); + var id = Subject.Download(remoteMovie, CreateIndexer()); id.Should().Be(expectedHash); } diff --git a/src/NzbDrone.Core.Test/Download/DownloadServiceFixture.cs b/src/NzbDrone.Core.Test/Download/DownloadServiceFixture.cs index a5fa54512..5fc2728b8 100644 --- a/src/NzbDrone.Core.Test/Download/DownloadServiceFixture.cs +++ b/src/NzbDrone.Core.Test/Download/DownloadServiceFixture.cs @@ -73,7 +73,7 @@ namespace NzbDrone.Core.Test.Download public void Download_report_should_publish_on_grab_event() { var mock = WithUsenetClient(); - mock.Setup(s => s.Download(It.IsAny())); + mock.Setup(s => s.Download(It.IsAny(), It.IsAny())); Subject.DownloadReport(_parseResult); @@ -84,18 +84,18 @@ namespace NzbDrone.Core.Test.Download public void Download_report_should_grab_using_client() { var mock = WithUsenetClient(); - mock.Setup(s => s.Download(It.IsAny())); + mock.Setup(s => s.Download(It.IsAny(), It.IsAny())); Subject.DownloadReport(_parseResult); - mock.Verify(s => s.Download(It.IsAny()), Times.Once()); + mock.Verify(s => s.Download(It.IsAny(), It.IsAny()), Times.Once()); } [Test] public void Download_report_should_not_publish_on_failed_grab_event() { var mock = WithUsenetClient(); - mock.Setup(s => s.Download(It.IsAny())) + mock.Setup(s => s.Download(It.IsAny(), It.IsAny())) .Throws(new WebException()); Assert.Throws(() => Subject.DownloadReport(_parseResult)); @@ -107,8 +107,8 @@ namespace NzbDrone.Core.Test.Download public void Download_report_should_trigger_indexer_backoff_on_indexer_error() { var mock = WithUsenetClient(); - mock.Setup(s => s.Download(It.IsAny())) - .Callback(v => + mock.Setup(s => s.Download(It.IsAny(), It.IsAny())) + .Callback((v, indexer) => { throw new ReleaseDownloadException(v.Release, "Error", new WebException()); }); @@ -127,8 +127,8 @@ namespace NzbDrone.Core.Test.Download response.Headers["Retry-After"] = "300"; var mock = WithUsenetClient(); - mock.Setup(s => s.Download(It.IsAny())) - .Callback(v => + mock.Setup(s => s.Download(It.IsAny(), It.IsAny())) + .Callback((v, indexer) => { throw new ReleaseDownloadException(v.Release, "Error", new TooManyRequestsException(request, response)); }); @@ -147,8 +147,8 @@ namespace NzbDrone.Core.Test.Download response.Headers["Retry-After"] = DateTime.UtcNow.AddSeconds(300).ToString("r"); var mock = WithUsenetClient(); - mock.Setup(s => s.Download(It.IsAny())) - .Callback(v => + mock.Setup(s => s.Download(It.IsAny(), It.IsAny())) + .Callback((v, indexer) => { throw new ReleaseDownloadException(v.Release, "Error", new TooManyRequestsException(request, response)); }); @@ -164,7 +164,7 @@ namespace NzbDrone.Core.Test.Download public void Download_report_should_not_trigger_indexer_backoff_on_downloadclient_error() { var mock = WithUsenetClient(); - mock.Setup(s => s.Download(It.IsAny())) + mock.Setup(s => s.Download(It.IsAny(), It.IsAny())) .Throws(new DownloadClientException("Some Error")); Assert.Throws(() => Subject.DownloadReport(_parseResult)); @@ -177,8 +177,8 @@ namespace NzbDrone.Core.Test.Download public void Download_report_should_not_trigger_indexer_backoff_on_indexer_404_error() { var mock = WithUsenetClient(); - mock.Setup(s => s.Download(It.IsAny())) - .Callback(v => + mock.Setup(s => s.Download(It.IsAny(), It.IsAny())) + .Callback((v, indexer) => { throw new ReleaseUnavailableException(v.Release, "Error", new WebException()); }); @@ -194,7 +194,7 @@ namespace NzbDrone.Core.Test.Download { Assert.Throws(() => Subject.DownloadReport(_parseResult)); - Mocker.GetMock().Verify(c => c.Download(It.IsAny()), Times.Never()); + Mocker.GetMock().Verify(c => c.Download(It.IsAny(), It.IsAny()), Times.Never()); VerifyEventNotPublished(); } @@ -217,7 +217,7 @@ namespace NzbDrone.Core.Test.Download Subject.DownloadReport(_parseResult); Mocker.GetMock().Verify(c => c.GetBlockedProviders(), Times.Never()); - mockUsenet.Verify(c => c.Download(It.IsAny()), Times.Once()); + mockUsenet.Verify(c => c.Download(It.IsAny(), It.IsAny()), Times.Once()); VerifyEventPublished(); } @@ -229,8 +229,8 @@ namespace NzbDrone.Core.Test.Download Subject.DownloadReport(_parseResult); - mockTorrent.Verify(c => c.Download(It.IsAny()), Times.Never()); - mockUsenet.Verify(c => c.Download(It.IsAny()), Times.Once()); + mockTorrent.Verify(c => c.Download(It.IsAny(), It.IsAny()), Times.Never()); + mockUsenet.Verify(c => c.Download(It.IsAny(), It.IsAny()), Times.Once()); } [Test] @@ -243,8 +243,8 @@ namespace NzbDrone.Core.Test.Download Subject.DownloadReport(_parseResult); - mockTorrent.Verify(c => c.Download(It.IsAny()), Times.Once()); - mockUsenet.Verify(c => c.Download(It.IsAny()), Times.Never()); + mockTorrent.Verify(c => c.Download(It.IsAny(), It.IsAny()), Times.Once()); + mockUsenet.Verify(c => c.Download(It.IsAny(), It.IsAny()), Times.Never()); } } } diff --git a/src/NzbDrone.Core/Download/Clients/Pneumatic/Pneumatic.cs b/src/NzbDrone.Core/Download/Clients/Pneumatic/Pneumatic.cs index 547f084d0..091b4fc8c 100644 --- a/src/NzbDrone.Core/Download/Clients/Pneumatic/Pneumatic.cs +++ b/src/NzbDrone.Core/Download/Clients/Pneumatic/Pneumatic.cs @@ -33,7 +33,7 @@ namespace NzbDrone.Core.Download.Clients.Pneumatic public override DownloadProtocol Protocol => DownloadProtocol.Usenet; - public override string Download(RemoteMovie remoteMovie) + public override string Download(RemoteMovie remoteMovie, IIndexer indexer) { var url = remoteMovie.Release.DownloadUrl; var title = remoteMovie.Release.Title; diff --git a/src/NzbDrone.Core/Download/DownloadClientBase.cs b/src/NzbDrone.Core/Download/DownloadClientBase.cs index 4819aef33..a0f2ab3db 100644 --- a/src/NzbDrone.Core/Download/DownloadClientBase.cs +++ b/src/NzbDrone.Core/Download/DownloadClientBase.cs @@ -62,7 +62,7 @@ namespace NzbDrone.Core.Download get; } - public abstract string Download(RemoteMovie remoteMovie); + public abstract string Download(RemoteMovie remoteMovie, IIndexer indexer); public abstract IEnumerable GetItems(); public virtual DownloadClientItem GetImportItem(DownloadClientItem item, DownloadClientItem previousImportAttempt) diff --git a/src/NzbDrone.Core/Download/DownloadService.cs b/src/NzbDrone.Core/Download/DownloadService.cs index 8f2dad084..36d61cbb5 100644 --- a/src/NzbDrone.Core/Download/DownloadService.cs +++ b/src/NzbDrone.Core/Download/DownloadService.cs @@ -22,6 +22,7 @@ namespace NzbDrone.Core.Download { private readonly IProvideDownloadClient _downloadClientProvider; private readonly IDownloadClientStatusService _downloadClientStatusService; + private readonly IIndexerFactory _indexerFactory; private readonly IIndexerStatusService _indexerStatusService; private readonly IRateLimitService _rateLimitService; private readonly IEventAggregator _eventAggregator; @@ -30,6 +31,7 @@ namespace NzbDrone.Core.Download public DownloadService(IProvideDownloadClient downloadClientProvider, IDownloadClientStatusService downloadClientStatusService, + IIndexerFactory indexerFactory, IIndexerStatusService indexerStatusService, IRateLimitService rateLimitService, IEventAggregator eventAggregator, @@ -38,6 +40,7 @@ namespace NzbDrone.Core.Download { _downloadClientProvider = downloadClientProvider; _downloadClientStatusService = downloadClientStatusService; + _indexerFactory = indexerFactory; _indexerStatusService = indexerStatusService; _rateLimitService = rateLimitService; _eventAggregator = eventAggregator; @@ -59,6 +62,7 @@ namespace NzbDrone.Core.Download // Get the seed configuration for this release. remoteMovie.SeedConfiguration = _seedConfigProvider.GetSeedConfiguration(remoteMovie); + var indexer = _indexerFactory.GetInstance(_indexerFactory.Get(remoteMovie.Release.IndexerId)); // Limit grabs to 2 per second. if (remoteMovie.Release.DownloadUrl.IsNotNullOrWhiteSpace() && !remoteMovie.Release.DownloadUrl.StartsWith("magnet:")) @@ -70,7 +74,7 @@ namespace NzbDrone.Core.Download string downloadClientId; try { - downloadClientId = downloadClient.Download(remoteMovie); + downloadClientId = downloadClient.Download(remoteMovie, indexer); _downloadClientStatusService.RecordSuccess(downloadClient.Definition.Id); _indexerStatusService.RecordSuccess(remoteMovie.Release.IndexerId); } diff --git a/src/NzbDrone.Core/Download/IDownloadClient.cs b/src/NzbDrone.Core/Download/IDownloadClient.cs index bb29aa961..747ba73de 100644 --- a/src/NzbDrone.Core/Download/IDownloadClient.cs +++ b/src/NzbDrone.Core/Download/IDownloadClient.cs @@ -8,7 +8,7 @@ namespace NzbDrone.Core.Download public interface IDownloadClient : IProvider { DownloadProtocol Protocol { get; } - string Download(RemoteMovie remoteMovie); + string Download(RemoteMovie remoteMovie, IIndexer indexer); IEnumerable GetItems(); DownloadClientItem GetImportItem(DownloadClientItem item, DownloadClientItem previousImportAttempt); void RemoveItem(DownloadClientItem item, bool deleteData); diff --git a/src/NzbDrone.Core/Download/TorrentClientBase.cs b/src/NzbDrone.Core/Download/TorrentClientBase.cs index c043f6f6e..e79a8b190 100644 --- a/src/NzbDrone.Core/Download/TorrentClientBase.cs +++ b/src/NzbDrone.Core/Download/TorrentClientBase.cs @@ -42,7 +42,7 @@ namespace NzbDrone.Core.Download protected abstract string AddFromMagnetLink(RemoteMovie remoteMovie, string hash, string magnetLink); protected abstract string AddFromTorrentFile(RemoteMovie remoteMovie, string hash, string filename, byte[] fileContent); - public override string Download(RemoteMovie remoteMovie) + public override string Download(RemoteMovie remoteMovie, IIndexer indexer) { var torrentInfo = remoteMovie.Release as TorrentInfo; @@ -69,7 +69,7 @@ namespace NzbDrone.Core.Download { try { - return DownloadFromWebUrl(remoteMovie, torrentUrl); + return DownloadFromWebUrl(remoteMovie, indexer, torrentUrl); } catch (Exception ex) { @@ -115,20 +115,20 @@ namespace NzbDrone.Core.Download if (torrentUrl.IsNotNullOrWhiteSpace()) { - return DownloadFromWebUrl(remoteMovie, torrentUrl); + return DownloadFromWebUrl(remoteMovie, indexer, torrentUrl); } } return null; } - private string DownloadFromWebUrl(RemoteMovie remoteMovie, string torrentUrl) + private string DownloadFromWebUrl(RemoteMovie remoteMovie, IIndexer indexer, string torrentUrl) { byte[] torrentFile = null; try { - var request = new HttpRequest(torrentUrl); + var request = indexer.GetDownloadRequest(torrentUrl); request.RateLimitKey = remoteMovie?.Release?.IndexerId.ToString(); request.Headers.Accept = "application/x-bittorrent"; request.AllowAutoRedirect = false; @@ -150,7 +150,9 @@ namespace NzbDrone.Core.Download return DownloadFromMagnetUrl(remoteMovie, locationHeader); } - return DownloadFromWebUrl(remoteMovie, locationHeader); + request.Url += new HttpUri(locationHeader); + + return DownloadFromWebUrl(remoteMovie, indexer, request.Url.ToString()); } throw new WebException("Remote website tried to redirect without providing a location."); diff --git a/src/NzbDrone.Core/Download/UsenetClientBase.cs b/src/NzbDrone.Core/Download/UsenetClientBase.cs index 307ba75f3..f46938dd8 100644 --- a/src/NzbDrone.Core/Download/UsenetClientBase.cs +++ b/src/NzbDrone.Core/Download/UsenetClientBase.cs @@ -35,7 +35,7 @@ namespace NzbDrone.Core.Download protected abstract string AddFromNzbFile(RemoteMovie remoteMovie, string filename, byte[] fileContents); - public override string Download(RemoteMovie remoteMovie) + public override string Download(RemoteMovie remoteMovie, IIndexer indexer) { var url = remoteMovie.Release.DownloadUrl; var filename = FileNameBuilder.CleanFileName(remoteMovie.Release.Title) + ".nzb"; @@ -44,7 +44,7 @@ namespace NzbDrone.Core.Download try { - var request = new HttpRequest(url); + var request = indexer.GetDownloadRequest(url); request.RateLimitKey = remoteMovie?.Release?.IndexerId.ToString(); nzbData = _httpClient.Get(request).ResponseData; diff --git a/src/NzbDrone.Core/Indexers/HttpIndexerBase.cs b/src/NzbDrone.Core/Indexers/HttpIndexerBase.cs index 0799140f9..531daeb9d 100644 --- a/src/NzbDrone.Core/Indexers/HttpIndexerBase.cs +++ b/src/NzbDrone.Core/Indexers/HttpIndexerBase.cs @@ -85,6 +85,11 @@ namespace NzbDrone.Core.Indexers return requests; } + public override HttpRequest GetDownloadRequest(string link) + { + return new HttpRequest(link); + } + protected virtual IList FetchReleases(Func pageableRequestChainSelector, bool isRecent = false) { var releases = new List(); diff --git a/src/NzbDrone.Core/Indexers/IIndexer.cs b/src/NzbDrone.Core/Indexers/IIndexer.cs index 2e3200162..71ed6e92d 100644 --- a/src/NzbDrone.Core/Indexers/IIndexer.cs +++ b/src/NzbDrone.Core/Indexers/IIndexer.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using NzbDrone.Common.Http; using NzbDrone.Core.IndexerSearch.Definitions; using NzbDrone.Core.Parser.Model; using NzbDrone.Core.ThingiProvider; @@ -13,5 +14,6 @@ namespace NzbDrone.Core.Indexers IList FetchRecent(); IList Fetch(MovieSearchCriteria searchCriteria); + HttpRequest GetDownloadRequest(string link); } } diff --git a/src/NzbDrone.Core/Indexers/IndexerBase.cs b/src/NzbDrone.Core/Indexers/IndexerBase.cs index cd5c9088b..7707b1d70 100644 --- a/src/NzbDrone.Core/Indexers/IndexerBase.cs +++ b/src/NzbDrone.Core/Indexers/IndexerBase.cs @@ -5,6 +5,7 @@ using System.Text.RegularExpressions; using FluentValidation.Results; using NLog; using NzbDrone.Common.Extensions; +using NzbDrone.Common.Http; using NzbDrone.Core.Configuration; using NzbDrone.Core.IndexerSearch.Definitions; using NzbDrone.Core.Languages; @@ -72,6 +73,7 @@ namespace NzbDrone.Core.Indexers public abstract IList FetchRecent(); public abstract IList Fetch(MovieSearchCriteria searchCriteria); + public abstract HttpRequest GetDownloadRequest(string link); protected virtual IList CleanupReleases(IEnumerable releases) {