Build download requests from indexer implementation

(cherry picked from commit a0b08f6c6f106d92cdb12fbb959dd2605c22fe6a)
pull/2427/head
Bogdan 2 years ago
parent 1978a726bb
commit 7a7039b1f7

@ -151,7 +151,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.Blackhole
{
var remoteBook = CreateRemoteBook();
Subject.Download(remoteBook);
Subject.Download(remoteBook, 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());
@ -163,9 +163,12 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.Blackhole
{
GivenMagnetFilePath();
Subject.Definition.Settings.As<TorrentBlackholeSettings>().SaveMagnetFiles = true;
var remoteBook = CreateRemoteBook();
remoteBook.Release.DownloadUrl = null;
Subject.Download(remoteBook);
Subject.Download(remoteBook, 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());
Mocker.GetMock<IDiskProvider>().Verify(c => c.OpenWriteStream(_magnetFilePath), Times.Once());
@ -184,7 +187,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.Blackhole
var remoteBook = CreateRemoteBook();
remoteBook.Release.DownloadUrl = null;
Subject.Download(remoteBook);
Subject.Download(remoteBook, 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());
@ -199,7 +202,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.Blackhole
var remoteBook = CreateRemoteBook();
remoteBook.Release.DownloadUrl = null;
Assert.Throws<ReleaseDownloadException>(() => Subject.Download(remoteBook));
Assert.Throws<ReleaseDownloadException>(() => Subject.Download(remoteBook, 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());
@ -214,7 +217,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.Blackhole
var remoteBook = CreateRemoteBook();
Subject.Download(remoteBook);
Subject.Download(remoteBook, 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());
@ -231,7 +234,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.Blackhole
var remoteBook = CreateRemoteBook();
remoteBook.Release.Title = illegalTitle;
Subject.Download(remoteBook);
Subject.Download(remoteBook, 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());
@ -244,7 +247,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.Blackhole
var remoteBook = CreateRemoteBook();
remoteBook.Release.DownloadUrl = null;
Assert.Throws<ReleaseDownloadException>(() => Subject.Download(remoteBook));
Assert.Throws<ReleaseDownloadException>(() => Subject.Download(remoteBook, CreateIndexer()));
}
[Test]
@ -318,7 +321,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.Blackhole
{
var remoteBook = CreateRemoteBook();
Subject.Download(remoteBook).Should().BeNull();
Subject.Download(remoteBook, CreateIndexer()).Should().BeNull();
}
}
}

@ -123,7 +123,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.Blackhole
{
var remoteBook = CreateRemoteBook();
Subject.Download(remoteBook);
Subject.Download(remoteBook, 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());
@ -139,7 +139,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.Blackhole
var remoteBook = CreateRemoteBook();
remoteBook.Release.Title = illegalTitle;
Subject.Download(remoteBook);
Subject.Download(remoteBook, 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 remoteBook = CreateRemoteBook();
var id = Subject.Download(remoteBook);
var id = Subject.Download(remoteBook, CreateIndexer());
id.Should().NotBeNullOrEmpty();
}
@ -219,7 +219,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DelugeTests
var remoteBook = CreateRemoteBook();
remoteBook.Release.DownloadUrl = magnetUrl;
var id = Subject.Download(remoteBook);
var id = Subject.Download(remoteBook, CreateIndexer());
id.Should().Be(expectedHash);
}

@ -2,16 +2,19 @@ using System;
using System.Collections.Generic;
using FluentAssertions;
using Moq;
using NLog;
using NUnit.Framework;
using NzbDrone.Common.Disk;
using NzbDrone.Common.Http;
using NzbDrone.Core.Books;
using NzbDrone.Core.Configuration;
using NzbDrone.Core.Download;
using NzbDrone.Core.Indexers;
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
{
@ -58,6 +61,15 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests
return remoteBook;
}
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 remoteBook = CreateRemoteBook();
var id = Subject.Download(remoteBook);
var id = Subject.Download(remoteBook, CreateIndexer());
id.Should().NotBeNullOrEmpty();
@ -410,7 +410,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests
var remoteBook = CreateRemoteBook();
var id = Subject.Download(remoteBook);
var id = Subject.Download(remoteBook, CreateIndexer());
id.Should().NotBeNullOrEmpty();
@ -426,7 +426,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests
var remoteBook = CreateRemoteBook();
var id = Subject.Download(remoteBook);
var id = Subject.Download(remoteBook, 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(remoteBook));
Assert.Throws(Is.InstanceOf<Exception>(), () => Subject.Download(remoteBook, CreateIndexer()));
Mocker.GetMock<IDownloadStationTaskProxy>()
.Verify(v => v.AddTaskFromUrl(It.IsAny<string>(), null, _settings), Times.Never());

@ -270,7 +270,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests
var remoteBook = CreateRemoteBook();
var id = Subject.Download(remoteBook);
var id = Subject.Download(remoteBook, CreateIndexer());
id.Should().NotBeNullOrEmpty();
@ -287,7 +287,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests
var remoteBook = CreateRemoteBook();
var id = Subject.Download(remoteBook);
var id = Subject.Download(remoteBook, CreateIndexer());
id.Should().NotBeNullOrEmpty();
@ -303,7 +303,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests
var remoteBook = CreateRemoteBook();
var id = Subject.Download(remoteBook);
var id = Subject.Download(remoteBook, CreateIndexer());
id.Should().NotBeNullOrEmpty();
@ -382,7 +382,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(remoteBook));
Assert.Throws(Is.InstanceOf<Exception>(), () => Subject.Download(remoteBook, CreateIndexer()));
Mocker.GetMock<IDownloadStationTaskProxy>()
.Verify(v => v.AddTaskFromUrl(It.IsAny<string>(), null, _settings), Times.Never());

@ -202,7 +202,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.HadoukenTests
var remoteBook = CreateRemoteBook();
var id = Subject.Download(remoteBook);
var id = Subject.Download(remoteBook, 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(remoteBook);
var result = Subject.Download(remoteBook, 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(remoteBook);
var result = Subject.Download(remoteBook, CreateIndexer());
Assert.IsFalse(result.Any(c => char.IsLower(c)));
}

@ -206,7 +206,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.NzbVortexTests
var remoteBook = CreateRemoteBook();
var id = Subject.Download(remoteBook);
var id = Subject.Download(remoteBook, CreateIndexer());
id.Should().NotBeNullOrEmpty();
}
@ -218,7 +218,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.NzbVortexTests
var remoteBook = CreateRemoteBook();
Assert.Throws<DownloadClientException>(() => Subject.Download(remoteBook));
Assert.Throws<DownloadClientException>(() => Subject.Download(remoteBook, CreateIndexer()));
}
[Test]

@ -345,7 +345,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.NzbgetTests
var remoteBook = CreateRemoteBook();
var id = Subject.Download(remoteBook);
var id = Subject.Download(remoteBook, CreateIndexer());
id.Should().NotBeNullOrEmpty();
}
@ -357,7 +357,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.NzbgetTests
var remoteBook = CreateRemoteBook();
Assert.Throws<DownloadClientRejectedReleaseException>(() => Subject.Download(remoteBook));
Assert.Throws<DownloadClientRejectedReleaseException>(() => Subject.Download(remoteBook, 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 RemoteBook _remoteBook;
private IIndexer _indexer;
private DownloadClientItem _downloadClientItem;
[SetUp]
@ -39,6 +45,12 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests
_remoteBook.ParsedBookInfo = new ParsedBookInfo();
_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(_remoteBook);
Subject.Download(_remoteBook, _indexer);
Mocker.GetMock<IHttpClient>().Verify(c => c.DownloadFile(_nzbUrl, _nzbPath, null), Times.Once());
}
@ -69,7 +81,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests
{
WithFailedDownload();
Assert.Throws<WebException>(() => Subject.Download(_remoteBook));
Assert.Throws<WebException>(() => Subject.Download(_remoteBook, _indexer));
}
[Test]
@ -78,7 +90,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests
_remoteBook.Release.Title = "Alien Ant Farm - Discography";
_remoteBook.ParsedBookInfo.Discography = true;
Assert.Throws<NotSupportedException>(() => Subject.Download(_remoteBook));
Assert.Throws<NotSupportedException>(() => Subject.Download(_remoteBook, _indexer));
}
[Test]
@ -94,7 +106,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests
var expectedFilename = Path.Combine(_pneumaticFolder, "Saturday Night Live - S38E08 - Jeremy Renner+Maroon 5 [SDTV].nzb");
_remoteBook.Release.Title = illegalTitle;
Subject.Download(_remoteBook);
Subject.Download(_remoteBook, _indexer);
Mocker.GetMock<IHttpClient>().Verify(c => c.DownloadFile(It.IsAny<string>(), expectedFilename, null), Times.Once());
}

@ -454,7 +454,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.QBittorrentTests
var remoteBook = CreateRemoteBook();
var id = Subject.Download(remoteBook);
var id = Subject.Download(remoteBook, CreateIndexer());
id.Should().NotBeNullOrEmpty();
}
@ -467,7 +467,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.QBittorrentTests
var remoteBook = CreateRemoteBook();
remoteBook.Release.DownloadUrl = magnetUrl;
var id = Subject.Download(remoteBook);
var id = Subject.Download(remoteBook, CreateIndexer());
id.Should().Be(expectedHash);
}
@ -482,7 +482,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.QBittorrentTests
var remoteBook = CreateRemoteBook();
remoteBook.Release.DownloadUrl = "magnet:?xt=urn:btih:ZPBPA2P6ROZPKRHK44D5OW6NHXU5Z6KR";
Assert.Throws<ReleaseDownloadException>(() => Subject.Download(remoteBook));
Assert.Throws<ReleaseDownloadException>(() => Subject.Download(remoteBook, CreateIndexer()));
}
[Test]
@ -495,7 +495,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.QBittorrentTests
var remoteBook = CreateRemoteBook();
remoteBook.Release.DownloadUrl = "magnet:?xt=urn:btih:ZPBPA2P6ROZPKRHK44D5OW6NHXU5Z6KR&tr=udp://abc";
Assert.DoesNotThrow(() => Subject.Download(remoteBook));
Assert.DoesNotThrow(() => Subject.Download(remoteBook, CreateIndexer()));
Mocker.GetMock<IQBittorrentProxy>()
.Verify(s => s.AddTorrentFromUrl(It.IsAny<string>(), It.IsAny<TorrentSeedConfiguration>(), It.IsAny<QBittorrentSettings>()), Times.Once());
@ -509,7 +509,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.QBittorrentTests
var remoteBook = CreateRemoteBook();
var id = Subject.Download(remoteBook);
var id = Subject.Download(remoteBook, CreateIndexer());
Mocker.GetMock<IQBittorrentProxy>()
.Verify(v => v.MoveTorrentToTopInQueue(It.IsAny<string>(), It.IsAny<QBittorrentSettings>()), Times.Once());
@ -527,7 +527,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.QBittorrentTests
var remoteBook = CreateRemoteBook();
var id = Subject.Download(remoteBook);
var id = Subject.Download(remoteBook, CreateIndexer());
id.Should().NotBeNullOrEmpty();
@ -561,7 +561,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.QBittorrentTests
var remoteBook = CreateRemoteBook();
var id = Subject.Download(remoteBook);
var id = Subject.Download(remoteBook, CreateIndexer());
id.Should().NotBeNullOrEmpty();
}
@ -574,7 +574,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.QBittorrentTests
var remoteBook = CreateRemoteBook();
var id = Subject.Download(remoteBook);
var id = Subject.Download(remoteBook, CreateIndexer());
id.Should().NotBeNullOrEmpty();
}

@ -127,7 +127,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.RTorrentTests
var remoteBook = CreateRemoteBook();
var id = Subject.Download(remoteBook);
var id = Subject.Download(remoteBook, CreateIndexer());
id.Should().NotBeNullOrEmpty();
}

@ -308,7 +308,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.SabnzbdTests
var remoteBook = CreateRemoteBook();
remoteBook.Release.Title = title;
var id = Subject.Download(remoteBook);
var id = Subject.Download(remoteBook, CreateIndexer());
Mocker.GetMock<ISabnzbdProxy>()
.Verify(v => v.DownloadNzb(It.IsAny<byte[]>(), filename, It.IsAny<string>(), It.IsAny<int>(), It.IsAny<SabnzbdSettings>()), Times.Once());
@ -321,7 +321,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.SabnzbdTests
var remoteBook = CreateRemoteBook();
var id = Subject.Download(remoteBook);
var id = Subject.Download(remoteBook, CreateIndexer());
id.Should().NotBeNullOrEmpty();
}
@ -367,7 +367,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.SabnzbdTests
.Build()
.ToList();
Subject.Download(remoteBook);
Subject.Download(remoteBook, 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 remoteBook = CreateRemoteBook();
var id = Subject.Download(remoteBook);
var id = Subject.Download(remoteBook, CreateIndexer());
id.Should().NotBeNullOrEmpty();
}
@ -74,7 +74,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.TransmissionTests
var remoteBook = CreateRemoteBook();
var id = Subject.Download(remoteBook);
var id = Subject.Download(remoteBook, CreateIndexer());
id.Should().NotBeNullOrEmpty();
@ -90,7 +90,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.TransmissionTests
var remoteBook = CreateRemoteBook();
var id = Subject.Download(remoteBook);
var id = Subject.Download(remoteBook, CreateIndexer());
id.Should().NotBeNullOrEmpty();
@ -108,7 +108,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.TransmissionTests
var remoteBook = CreateRemoteBook();
var id = Subject.Download(remoteBook);
var id = Subject.Download(remoteBook, CreateIndexer());
id.Should().NotBeNullOrEmpty();
@ -123,7 +123,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.TransmissionTests
var remoteBook = CreateRemoteBook();
var id = Subject.Download(remoteBook);
var id = Subject.Download(remoteBook, CreateIndexer());
id.Should().NotBeNullOrEmpty();
@ -139,7 +139,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.TransmissionTests
var remoteBook = CreateRemoteBook();
remoteBook.Release.DownloadUrl = magnetUrl;
var id = Subject.Download(remoteBook);
var id = Subject.Download(remoteBook, CreateIndexer());
id.Should().Be(expectedHash);
}

@ -234,7 +234,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.UTorrentTests
var remoteBook = CreateRemoteBook();
var id = Subject.Download(remoteBook);
var id = Subject.Download(remoteBook, CreateIndexer());
id.Should().NotBeNullOrEmpty();
}
@ -259,7 +259,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.UTorrentTests
var remoteBook = CreateRemoteBook();
remoteBook.Release.DownloadUrl = magnetUrl;
var id = Subject.Download(remoteBook);
var id = Subject.Download(remoteBook, CreateIndexer());
id.Should().Be(expectedHash);
}
@ -357,7 +357,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.UTorrentTests
var remoteBook = CreateRemoteBook();
var id = Subject.Download(remoteBook);
var id = Subject.Download(remoteBook, CreateIndexer());
id.Should().NotBeNullOrEmpty();
}
@ -370,7 +370,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.UTorrentTests
var remoteBook = CreateRemoteBook();
var id = Subject.Download(remoteBook);
var id = Subject.Download(remoteBook, CreateIndexer());
id.Should().NotBeNullOrEmpty();
}

@ -69,7 +69,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.VuzeTests
var remoteBook = CreateRemoteBook();
var id = Subject.Download(remoteBook);
var id = Subject.Download(remoteBook, CreateIndexer());
id.Should().NotBeNullOrEmpty();
}
@ -82,7 +82,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.VuzeTests
var remoteBook = CreateRemoteBook();
var id = Subject.Download(remoteBook);
var id = Subject.Download(remoteBook, CreateIndexer());
id.Should().NotBeNullOrEmpty();
@ -98,7 +98,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.VuzeTests
var remoteBook = CreateRemoteBook();
var id = Subject.Download(remoteBook);
var id = Subject.Download(remoteBook, CreateIndexer());
id.Should().NotBeNullOrEmpty();
@ -116,7 +116,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.VuzeTests
var remoteBook = CreateRemoteBook();
var id = Subject.Download(remoteBook);
var id = Subject.Download(remoteBook, CreateIndexer());
id.Should().NotBeNullOrEmpty();
@ -131,7 +131,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.VuzeTests
var remoteBook = CreateRemoteBook();
var id = Subject.Download(remoteBook);
var id = Subject.Download(remoteBook, CreateIndexer());
id.Should().NotBeNullOrEmpty();
@ -147,7 +147,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.VuzeTests
var remoteBook = CreateRemoteBook();
remoteBook.Release.DownloadUrl = magnetUrl;
var id = Subject.Download(remoteBook);
var id = Subject.Download(remoteBook, CreateIndexer());
id.Should().Be(expectedHash);
}

@ -80,7 +80,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<RemoteBook>()));
mock.Setup(s => s.Download(It.IsAny<RemoteBook>(), It.IsAny<IIndexer>()));
Subject.DownloadReport(_parseResult);
@ -91,18 +91,18 @@ namespace NzbDrone.Core.Test.Download
public void Download_report_should_grab_using_client()
{
var mock = WithUsenetClient();
mock.Setup(s => s.Download(It.IsAny<RemoteBook>()));
mock.Setup(s => s.Download(It.IsAny<RemoteBook>(), It.IsAny<IIndexer>()));
Subject.DownloadReport(_parseResult);
mock.Verify(s => s.Download(It.IsAny<RemoteBook>()), Times.Once());
mock.Verify(s => s.Download(It.IsAny<RemoteBook>(), 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<RemoteBook>()))
mock.Setup(s => s.Download(It.IsAny<RemoteBook>(), It.IsAny<IIndexer>()))
.Throws(new WebException());
Assert.Throws<WebException>(() => Subject.DownloadReport(_parseResult));
@ -114,8 +114,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<RemoteBook>()))
.Callback<RemoteBook>(v =>
mock.Setup(s => s.Download(It.IsAny<RemoteBook>(), It.IsAny<IIndexer>()))
.Callback<RemoteBook, IIndexer>((v, indexer) =>
{
throw new ReleaseDownloadException(v.Release, "Error", new WebException());
});
@ -134,8 +134,8 @@ namespace NzbDrone.Core.Test.Download
response.Headers["Retry-After"] = "300";
var mock = WithUsenetClient();
mock.Setup(s => s.Download(It.IsAny<RemoteBook>()))
.Callback<RemoteBook>(v =>
mock.Setup(s => s.Download(It.IsAny<RemoteBook>(), It.IsAny<IIndexer>()))
.Callback<RemoteBook, IIndexer>((v, indexer) =>
{
throw new ReleaseDownloadException(v.Release, "Error", new TooManyRequestsException(request, response));
});
@ -154,8 +154,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<RemoteBook>()))
.Callback<RemoteBook>(v =>
mock.Setup(s => s.Download(It.IsAny<RemoteBook>(), It.IsAny<IIndexer>()))
.Callback<RemoteBook, IIndexer>((v, indexer) =>
{
throw new ReleaseDownloadException(v.Release, "Error", new TooManyRequestsException(request, response));
});
@ -171,7 +171,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<RemoteBook>()))
mock.Setup(s => s.Download(It.IsAny<RemoteBook>(), It.IsAny<IIndexer>()))
.Throws(new DownloadClientException("Some Error"));
Assert.Throws<DownloadClientException>(() => Subject.DownloadReport(_parseResult));
@ -184,8 +184,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<RemoteBook>()))
.Callback<RemoteBook>(v =>
mock.Setup(s => s.Download(It.IsAny<RemoteBook>(), It.IsAny<IIndexer>()))
.Callback<RemoteBook, IIndexer>((v, indexer) =>
{
throw new ReleaseUnavailableException(v.Release, "Error", new WebException());
});
@ -201,7 +201,7 @@ namespace NzbDrone.Core.Test.Download
{
Assert.Throws<DownloadClientUnavailableException>(() => Subject.DownloadReport(_parseResult));
Mocker.GetMock<IDownloadClient>().Verify(c => c.Download(It.IsAny<RemoteBook>()), Times.Never());
Mocker.GetMock<IDownloadClient>().Verify(c => c.Download(It.IsAny<RemoteBook>(), It.IsAny<IIndexer>()), Times.Never());
VerifyEventNotPublished<BookGrabbedEvent>();
}
@ -224,7 +224,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<RemoteBook>()), Times.Once());
mockUsenet.Verify(c => c.Download(It.IsAny<RemoteBook>(), It.IsAny<IIndexer>()), Times.Once());
VerifyEventPublished<BookGrabbedEvent>();
}
@ -236,8 +236,8 @@ namespace NzbDrone.Core.Test.Download
Subject.DownloadReport(_parseResult);
mockTorrent.Verify(c => c.Download(It.IsAny<RemoteBook>()), Times.Never());
mockUsenet.Verify(c => c.Download(It.IsAny<RemoteBook>()), Times.Once());
mockTorrent.Verify(c => c.Download(It.IsAny<RemoteBook>(), It.IsAny<IIndexer>()), Times.Never());
mockUsenet.Verify(c => c.Download(It.IsAny<RemoteBook>(), It.IsAny<IIndexer>()), Times.Once());
}
[Test]
@ -250,8 +250,8 @@ namespace NzbDrone.Core.Test.Download
Subject.DownloadReport(_parseResult);
mockTorrent.Verify(c => c.Download(It.IsAny<RemoteBook>()), Times.Once());
mockUsenet.Verify(c => c.Download(It.IsAny<RemoteBook>()), Times.Never());
mockTorrent.Verify(c => c.Download(It.IsAny<RemoteBook>(), It.IsAny<IIndexer>()), Times.Once());
mockUsenet.Verify(c => c.Download(It.IsAny<RemoteBook>(), It.IsAny<IIndexer>()), Times.Never());
}
}
}

@ -32,7 +32,7 @@ namespace NzbDrone.Core.Download.Clients.Pneumatic
public override DownloadProtocol Protocol => DownloadProtocol.Usenet;
public override string Download(RemoteBook remoteBook)
public override string Download(RemoteBook remoteBook, IIndexer indexer)
{
var url = remoteBook.Release.DownloadUrl;
var title = remoteBook.Release.Title;

@ -59,7 +59,7 @@ namespace NzbDrone.Core.Download
get;
}
public abstract string Download(RemoteBook remoteBook);
public abstract string Download(RemoteBook remoteBook, 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;
@ -60,6 +63,7 @@ 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:"))
@ -71,7 +75,7 @@ namespace NzbDrone.Core.Download
string downloadClientId;
try
{
downloadClientId = downloadClient.Download(remoteBook);
downloadClientId = downloadClient.Download(remoteBook, indexer);
_downloadClientStatusService.RecordSuccess(downloadClient.Definition.Id);
_indexerStatusService.RecordSuccess(remoteBook.Release.IndexerId);
}

@ -8,7 +8,7 @@ namespace NzbDrone.Core.Download
public interface IDownloadClient : IProvider
{
DownloadProtocol Protocol { get; }
string Download(RemoteBook remoteBook);
string Download(RemoteBook remoteBook, IIndexer indexer);
IEnumerable<DownloadClientItem> GetItems();
DownloadClientItem GetImportItem(DownloadClientItem item, DownloadClientItem previousImportAttempt);
void RemoveItem(DownloadClientItem item, bool deleteData);

@ -41,7 +41,7 @@ namespace NzbDrone.Core.Download
protected abstract string AddFromMagnetLink(RemoteBook remoteBook, string hash, string magnetLink);
protected abstract string AddFromTorrentFile(RemoteBook remoteBook, string hash, string filename, byte[] fileContent);
public override string Download(RemoteBook remoteBook)
public override string Download(RemoteBook remoteBook, IIndexer indexer)
{
var torrentInfo = remoteBook.Release as TorrentInfo;
@ -68,7 +68,7 @@ namespace NzbDrone.Core.Download
{
try
{
return DownloadFromWebUrl(remoteBook, torrentUrl);
return DownloadFromWebUrl(remoteBook, indexer, torrentUrl);
}
catch (Exception ex)
{
@ -114,20 +114,20 @@ namespace NzbDrone.Core.Download
if (torrentUrl.IsNotNullOrWhiteSpace())
{
return DownloadFromWebUrl(remoteBook, torrentUrl);
return DownloadFromWebUrl(remoteBook, indexer, torrentUrl);
}
}
return null;
}
private string DownloadFromWebUrl(RemoteBook remoteBook, string torrentUrl)
private string DownloadFromWebUrl(RemoteBook remoteBook, IIndexer indexer, string torrentUrl)
{
byte[] torrentFile = null;
try
{
var request = new HttpRequest(torrentUrl);
var request = indexer.GetDownloadRequest(torrentUrl);
request.RateLimitKey = remoteBook?.Release?.IndexerId.ToString();
request.Headers.Accept = "application/x-bittorrent";
request.AllowAutoRedirect = false;
@ -149,7 +149,9 @@ namespace NzbDrone.Core.Download
return DownloadFromMagnetUrl(remoteBook, locationHeader);
}
return DownloadFromWebUrl(remoteBook, locationHeader);
request.Url += new HttpUri(locationHeader);
return DownloadFromWebUrl(remoteBook, 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(RemoteBook remoteBook, string filename, byte[] fileContent);
public override string Download(RemoteBook remoteBook)
public override string Download(RemoteBook remoteBook, IIndexer indexer)
{
var url = remoteBook.Release.DownloadUrl;
var filename = FileNameBuilder.CleanFileName(remoteBook.Release.Title) + ".nzb";
@ -44,7 +44,7 @@ namespace NzbDrone.Core.Download
try
{
var request = new HttpRequest(url);
var request = indexer.GetDownloadRequest(url);
request.RateLimitKey = remoteBook?.Release?.IndexerId.ToString();
// TODO: Look into moving download request handling to indexer

@ -68,6 +68,11 @@ namespace NzbDrone.Core.Indexers
return FetchReleases(g => g.GetSearchRequests(searchCriteria));
}
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;
@ -14,5 +15,6 @@ namespace NzbDrone.Core.Indexers
IList<ReleaseInfo> FetchRecent();
IList<ReleaseInfo> Fetch(BookSearchCriteria searchCriteria);
IList<ReleaseInfo> Fetch(AuthorSearchCriteria searchCriteria);
HttpRequest GetDownloadRequest(string link);
}
}

@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.Linq;
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.Parser;
@ -70,6 +70,7 @@ namespace NzbDrone.Core.Indexers
public abstract IList<ReleaseInfo> Fetch(BookSearchCriteria searchCriteria);
public abstract IList<ReleaseInfo> Fetch(AuthorSearchCriteria searchCriteria);
public abstract HttpRequest GetDownloadRequest(string link);
protected virtual IList<ReleaseInfo> CleanupReleases(IEnumerable<ReleaseInfo> releases)
{

Loading…
Cancel
Save