Build download requests from indexer implementation

(cherry picked from commit a0b08f6c6f106d92cdb12fbb959dd2605c22fe6a)
pull/8378/head
Bogdan 2 years ago
parent 138b1e1c9d
commit 84e0f5bfcf

@ -148,7 +148,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.Blackhole
{
var remoteMovie = CreateRemoteMovie();
Subject.Download(remoteMovie);
Subject.Download(remoteMovie, CreateIndexer());
Mocker.GetMock<IHttpClient>().Verify(c => c.Get(It.Is<HttpRequest>(v => v.Url.FullUri == _downloadUrl)), Times.Once());
Mocker.GetMock<IDiskProvider>().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<IHttpClient>().Verify(c => c.Get(It.Is<HttpRequest>(v => v.Url.FullUri == _downloadUrl)), Times.Never());
Mocker.GetMock<IDiskProvider>().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<IHttpClient>().Verify(c => c.Get(It.Is<HttpRequest>(v => v.Url.FullUri == _downloadUrl)), Times.Never());
Mocker.GetMock<IDiskProvider>().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<ReleaseDownloadException>(() => Subject.Download(remoteMovie));
Assert.Throws<ReleaseDownloadException>(() => Subject.Download(remoteMovie, CreateIndexer()));
Mocker.GetMock<IHttpClient>().Verify(c => c.Get(It.Is<HttpRequest>(v => v.Url.FullUri == _downloadUrl)), Times.Never());
Mocker.GetMock<IDiskProvider>().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<IHttpClient>().Verify(c => c.Get(It.Is<HttpRequest>(v => v.Url.FullUri == _downloadUrl)), Times.Once());
Mocker.GetMock<IDiskProvider>().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<IHttpClient>().Verify(c => c.Get(It.Is<HttpRequest>(v => v.Url.FullUri == _downloadUrl)), Times.Once());
Mocker.GetMock<IDiskProvider>().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<ReleaseDownloadException>(() => Subject.Download(remoteMovie));
Assert.Throws<ReleaseDownloadException>(() => 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();
}
}
}

@ -119,7 +119,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.Blackhole
{
var remoteMovie = CreateRemoteMovie();
Subject.Download(remoteMovie);
Subject.Download(remoteMovie, CreateIndexer());
Mocker.GetMock<IHttpClient>().Verify(c => c.Get(It.Is<HttpRequest>(v => v.Url.FullUri == _downloadUrl)), Times.Once());
Mocker.GetMock<IDiskProvider>().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<IHttpClient>().Verify(c => c.Get(It.Is<HttpRequest>(v => v.Url.FullUri == _downloadUrl)), Times.Once());
Mocker.GetMock<IDiskProvider>().Verify(c => c.OpenWriteStream(expectedFilename), Times.Once());

@ -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);
}

@ -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<IHttpClient>(),
Mocker.Resolve<IIndexerStatusService>(),
Mocker.Resolve<IConfigService>(),
Mocker.Resolve<IParsingService>(),
Mocker.Resolve<Logger>());
}
protected void VerifyIdentifiable(DownloadClientItem downloadClientItem)
{
downloadClientItem.DownloadClientInfo.Protocol.Should().Be(Subject.Protocol);

@ -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<Exception>(), () => Subject.Download(remoteEpisode));
Assert.Throws(Is.InstanceOf<Exception>(), () => Subject.Download(remoteEpisode, CreateIndexer()));
Mocker.GetMock<IDownloadStationTaskProxy>()
.Verify(v => v.AddTaskFromUrl(It.IsAny<string>(), null, _settings), Times.Never());

@ -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<Exception>(), () => Subject.Download(remoteEpisode));
Assert.Throws(Is.InstanceOf<Exception>(), () => Subject.Download(remoteEpisode, CreateIndexer()));
Mocker.GetMock<IDownloadStationTaskProxy>()
.Verify(v => v.AddTaskFromUrl(It.IsAny<string>(), null, _settings), Times.Never());

@ -154,7 +154,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.FreeboxDownloadTests
var remoteMovie = CreateRemoteMovie();
Subject.Download(remoteMovie);
Subject.Download(remoteMovie, CreateIndexer());
Mocker.GetMock<IFreeboxDownloadProxy>()
.Verify(v => v.AddTaskFromUrl(It.IsAny<string>(), _encodedDestinationDirectory, It.IsAny<bool>(), It.IsAny<bool>(), It.IsAny<double?>(), It.IsAny<FreeboxDownloadSettings>()), 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<IFreeboxDownloadProxy>()
.Verify(v => v.AddTaskFromUrl(It.IsAny<string>(), _encodedDefaultDestinationAndCategory, It.IsAny<bool>(), It.IsAny<bool>(), It.IsAny<double?>(), It.IsAny<FreeboxDownloadSettings>()), 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<IFreeboxDownloadProxy>()
.Verify(v => v.AddTaskFromUrl(It.IsAny<string>(), _encodedDefaultDestination, It.IsAny<bool>(), It.IsAny<bool>(), It.IsAny<double?>(), It.IsAny<FreeboxDownloadSettings>()), 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<IFreeboxDownloadProxy>()
.Verify(v => v.AddTaskFromUrl(It.IsAny<string>(), It.IsAny<string>(), toBePausedFlag, It.IsAny<bool>(), It.IsAny<double?>(), It.IsAny<FreeboxDownloadSettings>()), 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<IFreeboxDownloadProxy>()
.Verify(v => v.AddTaskFromUrl(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<bool>(), toBeQueuedFirstFlag, It.IsAny<double?>(), It.IsAny<FreeboxDownloadSettings>()), 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<IFreeboxDownloadProxy>()
.Verify(v => v.AddTaskFromUrl(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<bool>(), It.IsAny<bool>(), expectedSeedRatio, It.IsAny<FreeboxDownloadSettings>()), Times.Once());

@ -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<IHadoukenProxy>()
.Setup(v => v.AddTorrentUri(It.IsAny<HadoukenSettings>(), It.IsAny<string>()));
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<HadoukenSettings>(), It.IsAny<byte[]>()))
.Returns("hash");
var result = Subject.Download(remoteMovie);
var result = Subject.Download(remoteMovie, CreateIndexer());
Assert.IsFalse(result.Any(c => char.IsLower(c)));
}

@ -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<DownloadClientException>(() => Subject.Download(remoteMovie));
Assert.Throws<DownloadClientException>(() => Subject.Download(remoteMovie, CreateIndexer()));
}
[Test]

@ -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<DownloadClientRejectedReleaseException>(() => Subject.Download(remoteMovie));
Assert.Throws<DownloadClientRejectedReleaseException>(() => Subject.Download(remoteMovie, CreateIndexer()));
}
[Test]

@ -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<IHttpClient>(),
Mocker.Resolve<IIndexerStatusService>(),
Mocker.Resolve<IConfigService>(),
Mocker.Resolve<IParsingService>(),
Mocker.Resolve<Logger>());
_downloadClientItem = Builder<DownloadClientItem>
.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<IHttpClient>().Verify(c => c.DownloadFile(_nzbUrl, _nzbPath), Times.Once());
}
@ -69,7 +81,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests
{
WithFailedDownload();
Assert.Throws<WebException>(() => Subject.Download(_remoteMovie));
Assert.Throws<WebException>(() => 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<IHttpClient>().Verify(c => c.DownloadFile(It.IsAny<string>(), expectedFilename), Times.Once());
}

@ -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<ReleaseDownloadException>(() => Subject.Download(remoteMovie));
Assert.Throws<ReleaseDownloadException>(() => 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<IQBittorrentProxy>()
.Verify(s => s.AddTorrentFromUrl(It.IsAny<string>(), It.IsAny<TorrentSeedConfiguration>(), It.IsAny<QBittorrentSettings>()), 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<IQBittorrentProxy>()
.Verify(v => v.MoveTorrentToTopInQueue(It.IsAny<string>(), It.IsAny<QBittorrentSettings>()), 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();
}

@ -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();
}

@ -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<ISabnzbdProxy>()
.Verify(v => v.DownloadNzb(It.IsAny<byte[]>(), filename, It.IsAny<string>(), It.IsAny<int>(), It.IsAny<SabnzbdSettings>()), 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<ISabnzbdProxy>()
.Verify(v => v.DownloadNzb(It.IsAny<byte[]>(), It.IsAny<string>(), It.IsAny<string>(), (int)SabnzbdPriority.High, It.IsAny<SabnzbdSettings>()), Times.Once());

@ -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);
}

@ -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();
}

@ -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);
}

@ -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<RemoteMovie>()));
mock.Setup(s => s.Download(It.IsAny<RemoteMovie>(), It.IsAny<IIndexer>()));
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<RemoteMovie>()));
mock.Setup(s => s.Download(It.IsAny<RemoteMovie>(), It.IsAny<IIndexer>()));
Subject.DownloadReport(_parseResult);
mock.Verify(s => s.Download(It.IsAny<RemoteMovie>()), Times.Once());
mock.Verify(s => s.Download(It.IsAny<RemoteMovie>(), It.IsAny<IIndexer>()), Times.Once());
}
[Test]
public void Download_report_should_not_publish_on_failed_grab_event()
{
var mock = WithUsenetClient();
mock.Setup(s => s.Download(It.IsAny<RemoteMovie>()))
mock.Setup(s => s.Download(It.IsAny<RemoteMovie>(), It.IsAny<IIndexer>()))
.Throws(new WebException());
Assert.Throws<WebException>(() => 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<RemoteMovie>()))
.Callback<RemoteMovie>(v =>
mock.Setup(s => s.Download(It.IsAny<RemoteMovie>(), It.IsAny<IIndexer>()))
.Callback<RemoteMovie, IIndexer>((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<RemoteMovie>()))
.Callback<RemoteMovie>(v =>
mock.Setup(s => s.Download(It.IsAny<RemoteMovie>(), It.IsAny<IIndexer>()))
.Callback<RemoteMovie, IIndexer>((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<RemoteMovie>()))
.Callback<RemoteMovie>(v =>
mock.Setup(s => s.Download(It.IsAny<RemoteMovie>(), It.IsAny<IIndexer>()))
.Callback<RemoteMovie, IIndexer>((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<RemoteMovie>()))
mock.Setup(s => s.Download(It.IsAny<RemoteMovie>(), It.IsAny<IIndexer>()))
.Throws(new DownloadClientException("Some Error"));
Assert.Throws<DownloadClientException>(() => 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<RemoteMovie>()))
.Callback<RemoteMovie>(v =>
mock.Setup(s => s.Download(It.IsAny<RemoteMovie>(), It.IsAny<IIndexer>()))
.Callback<RemoteMovie, IIndexer>((v, indexer) =>
{
throw new ReleaseUnavailableException(v.Release, "Error", new WebException());
});
@ -194,7 +194,7 @@ namespace NzbDrone.Core.Test.Download
{
Assert.Throws<DownloadClientUnavailableException>(() => Subject.DownloadReport(_parseResult));
Mocker.GetMock<IDownloadClient>().Verify(c => c.Download(It.IsAny<RemoteMovie>()), Times.Never());
Mocker.GetMock<IDownloadClient>().Verify(c => c.Download(It.IsAny<RemoteMovie>(), It.IsAny<IIndexer>()), Times.Never());
VerifyEventNotPublished<MovieGrabbedEvent>();
}
@ -217,7 +217,7 @@ namespace NzbDrone.Core.Test.Download
Subject.DownloadReport(_parseResult);
Mocker.GetMock<IDownloadClientStatusService>().Verify(c => c.GetBlockedProviders(), Times.Never());
mockUsenet.Verify(c => c.Download(It.IsAny<RemoteMovie>()), Times.Once());
mockUsenet.Verify(c => c.Download(It.IsAny<RemoteMovie>(), It.IsAny<IIndexer>()), Times.Once());
VerifyEventPublished<MovieGrabbedEvent>();
}
@ -229,8 +229,8 @@ namespace NzbDrone.Core.Test.Download
Subject.DownloadReport(_parseResult);
mockTorrent.Verify(c => c.Download(It.IsAny<RemoteMovie>()), Times.Never());
mockUsenet.Verify(c => c.Download(It.IsAny<RemoteMovie>()), Times.Once());
mockTorrent.Verify(c => c.Download(It.IsAny<RemoteMovie>(), It.IsAny<IIndexer>()), Times.Never());
mockUsenet.Verify(c => c.Download(It.IsAny<RemoteMovie>(), It.IsAny<IIndexer>()), Times.Once());
}
[Test]
@ -243,8 +243,8 @@ namespace NzbDrone.Core.Test.Download
Subject.DownloadReport(_parseResult);
mockTorrent.Verify(c => c.Download(It.IsAny<RemoteMovie>()), Times.Once());
mockUsenet.Verify(c => c.Download(It.IsAny<RemoteMovie>()), Times.Never());
mockTorrent.Verify(c => c.Download(It.IsAny<RemoteMovie>(), It.IsAny<IIndexer>()), Times.Once());
mockUsenet.Verify(c => c.Download(It.IsAny<RemoteMovie>(), It.IsAny<IIndexer>()), Times.Never());
}
}
}

@ -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;

@ -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<DownloadClientItem> GetItems();
public virtual DownloadClientItem GetImportItem(DownloadClientItem item, DownloadClientItem previousImportAttempt)

@ -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);
}

@ -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<DownloadClientItem> GetItems();
DownloadClientItem GetImportItem(DownloadClientItem item, DownloadClientItem previousImportAttempt);
void RemoveItem(DownloadClientItem item, bool deleteData);

@ -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.");

@ -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;

@ -85,6 +85,11 @@ namespace NzbDrone.Core.Indexers
return requests;
}
public override HttpRequest GetDownloadRequest(string link)
{
return new HttpRequest(link);
}
protected virtual IList<ReleaseInfo> FetchReleases(Func<IIndexerRequestGenerator, IndexerPageableRequestChain> pageableRequestChainSelector, bool isRecent = false)
{
var releases = new List<ReleaseInfo>();

@ -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<ReleaseInfo> FetchRecent();
IList<ReleaseInfo> Fetch(MovieSearchCriteria searchCriteria);
HttpRequest GetDownloadRequest(string link);
}
}

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using FluentValidation.Results;
using NLog;
using NzbDrone.Common.Http;
using NzbDrone.Core.Configuration;
using NzbDrone.Core.IndexerSearch.Definitions;
using NzbDrone.Core.Parser;
@ -67,6 +68,7 @@ namespace NzbDrone.Core.Indexers
public abstract IList<ReleaseInfo> FetchRecent();
public abstract IList<ReleaseInfo> Fetch(MovieSearchCriteria searchCriteria);
public abstract HttpRequest GetDownloadRequest(string link);
protected virtual IList<ReleaseInfo> CleanupReleases(IEnumerable<ReleaseInfo> releases)
{

Loading…
Cancel
Save