Build download requests from indexer implementation

This commit is contained in:
Bogdan 2023-04-30 07:09:11 +03:00 committed by GitHub
parent 7aa8463438
commit a0b08f6c6f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
27 changed files with 135 additions and 98 deletions

View File

@ -147,7 +147,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.Blackhole
{
var remoteEpisode = CreateRemoteEpisode();
Subject.Download(remoteEpisode);
Subject.Download(remoteEpisode, 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,7 +163,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.Blackhole
var remoteEpisode = CreateRemoteEpisode();
remoteEpisode.Release.DownloadUrl = null;
Subject.Download(remoteEpisode);
Subject.Download(remoteEpisode, 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());
@ -182,7 +182,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.Blackhole
var remoteEpisode = CreateRemoteEpisode();
remoteEpisode.Release.DownloadUrl = null;
Subject.Download(remoteEpisode);
Subject.Download(remoteEpisode, 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 remoteEpisode = CreateRemoteEpisode();
remoteEpisode.Release.DownloadUrl = null;
Assert.Throws<ReleaseDownloadException>(() => Subject.Download(remoteEpisode));
Assert.Throws<ReleaseDownloadException>(() => Subject.Download(remoteEpisode, 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 remoteEpisode = CreateRemoteEpisode();
Subject.Download(remoteEpisode);
Subject.Download(remoteEpisode, 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 remoteEpisode = CreateRemoteEpisode();
remoteEpisode.Release.Title = illegalTitle;
Subject.Download(remoteEpisode);
Subject.Download(remoteEpisode, 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 remoteEpisode = CreateRemoteEpisode();
remoteEpisode.Release.DownloadUrl = null;
Assert.Throws<ReleaseDownloadException>(() => Subject.Download(remoteEpisode));
Assert.Throws<ReleaseDownloadException>(() => Subject.Download(remoteEpisode, CreateIndexer()));
}
[Test]
@ -316,7 +316,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.Blackhole
{
var remoteEpisode = CreateRemoteEpisode();
Subject.Download(remoteEpisode).Should().BeNull();
Subject.Download(remoteEpisode, CreateIndexer()).Should().BeNull();
}
}
}

View File

@ -119,7 +119,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.Blackhole
{
var remoteEpisode = CreateRemoteEpisode();
Subject.Download(remoteEpisode);
Subject.Download(remoteEpisode, 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 remoteEpisode = CreateRemoteEpisode();
remoteEpisode.Release.Title = illegalTitle;
Subject.Download(remoteEpisode);
Subject.Download(remoteEpisode, 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());

View File

@ -206,7 +206,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DelugeTests
var remoteEpisode = CreateRemoteEpisode();
var id = Subject.Download(remoteEpisode);
var id = Subject.Download(remoteEpisode, CreateIndexer());
id.Should().NotBeNullOrEmpty();
}
@ -219,7 +219,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DelugeTests
var remoteEpisode = CreateRemoteEpisode();
remoteEpisode.Release.DownloadUrl = magnetUrl;
var id = Subject.Download(remoteEpisode);
var id = Subject.Download(remoteEpisode, CreateIndexer());
id.Should().Be(expectedHash);
}

View File

@ -2,16 +2,19 @@
using System.Collections.Generic;
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.Parser;
using NzbDrone.Core.Parser.Model;
using NzbDrone.Core.RemotePathMappings;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Core.Test.IndexerTests;
using NzbDrone.Core.Tv;
namespace NzbDrone.Core.Test.Download.DownloadClientTests
@ -60,6 +63,15 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests
return remoteEpisode;
}
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);

View File

@ -381,7 +381,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests
var remoteEpisode = CreateRemoteEpisode();
var id = Subject.Download(remoteEpisode);
var id = Subject.Download(remoteEpisode, CreateIndexer());
id.Should().NotBeNullOrEmpty();
@ -398,7 +398,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests
var remoteEpisode = CreateRemoteEpisode();
var id = Subject.Download(remoteEpisode);
var id = Subject.Download(remoteEpisode, CreateIndexer());
id.Should().NotBeNullOrEmpty();
@ -414,7 +414,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests
var remoteEpisode = CreateRemoteEpisode();
var id = Subject.Download(remoteEpisode);
var id = Subject.Download(remoteEpisode, CreateIndexer());
id.Should().NotBeNullOrEmpty();
@ -493,7 +493,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());

View File

@ -259,7 +259,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests
var remoteEpisode = CreateRemoteEpisode();
var id = Subject.Download(remoteEpisode);
var id = Subject.Download(remoteEpisode, CreateIndexer());
id.Should().NotBeNullOrEmpty();
@ -276,7 +276,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests
var remoteEpisode = CreateRemoteEpisode();
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 = CreateRemoteEpisode();
var id = Subject.Download(remoteEpisode);
var id = Subject.Download(remoteEpisode, CreateIndexer());
id.Should().NotBeNullOrEmpty();
@ -371,7 +371,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());

View File

@ -153,7 +153,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.FreeboxDownloadTests
var remoteEpisode = CreateRemoteEpisode();
Subject.Download(remoteEpisode);
Subject.Download(remoteEpisode, 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());
@ -168,7 +168,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.FreeboxDownloadTests
var remoteEpisode = CreateRemoteEpisode();
Subject.Download(remoteEpisode);
Subject.Download(remoteEpisode, 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());
@ -182,7 +182,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.FreeboxDownloadTests
var remoteEpisode = CreateRemoteEpisode();
Subject.Download(remoteEpisode);
Subject.Download(remoteEpisode, 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());
@ -199,7 +199,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.FreeboxDownloadTests
var remoteEpisode = CreateRemoteEpisode();
Subject.Download(remoteEpisode);
Subject.Download(remoteEpisode, 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());
@ -230,7 +230,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.FreeboxDownloadTests
remoteEpisode.Episodes.Add(episode);
Subject.Download(remoteEpisode);
Subject.Download(remoteEpisode, 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());
@ -248,7 +248,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.FreeboxDownloadTests
remoteEpisode.SeedConfiguration = new TorrentSeedConfiguration();
remoteEpisode.SeedConfiguration.Ratio = providerSeedRatio;
Subject.Download(remoteEpisode);
Subject.Download(remoteEpisode, 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());

View File

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

View File

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

View File

@ -346,7 +346,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.NzbgetTests
var remoteEpisode = CreateRemoteEpisode();
var id = Subject.Download(remoteEpisode);
var id = Subject.Download(remoteEpisode, CreateIndexer());
id.Should().NotBeNullOrEmpty();
}
@ -358,7 +358,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.NzbgetTests
var remoteEpisode = CreateRemoteEpisode();
Assert.Throws<DownloadClientRejectedReleaseException>(() => Subject.Download(remoteEpisode));
Assert.Throws<DownloadClientRejectedReleaseException>(() => Subject.Download(remoteEpisode, CreateIndexer()));
}
[Test]

View File

@ -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 RemoteEpisode _remoteEpisode;
private IIndexer _indexer;
private DownloadClientItem _downloadClientItem;
[SetUp]
@ -40,6 +46,12 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests
_remoteEpisode.ParsedEpisodeInfo = new ParsedEpisodeInfo();
_remoteEpisode.ParsedEpisodeInfo.FullSeason = false;
_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();
@ -60,7 +72,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests
[Test]
public void should_download_file_if_it_doesnt_exist()
{
Subject.Download(_remoteEpisode);
Subject.Download(_remoteEpisode, _indexer);
Mocker.GetMock<IHttpClient>().Verify(c => c.DownloadFile(_nzbUrl, _nzbPath), Times.Once());
}
@ -70,7 +82,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests
{
WithFailedDownload();
Assert.Throws<WebException>(() => Subject.Download(_remoteEpisode));
Assert.Throws<WebException>(() => Subject.Download(_remoteEpisode, _indexer));
}
[Test]
@ -79,7 +91,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests
_remoteEpisode.Release.Title = "30 Rock - Season 1";
_remoteEpisode.ParsedEpisodeInfo.FullSeason = true;
Assert.Throws<NotSupportedException>(() => Subject.Download(_remoteEpisode));
Assert.Throws<NotSupportedException>(() => Subject.Download(_remoteEpisode, _indexer));
}
[Test]
@ -95,7 +107,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests
var expectedFilename = Path.Combine(_pneumaticFolder, "Saturday Night Live - S38E08 - Jeremy Renner+Maroon 5 [SDTV].nzb");
_remoteEpisode.Release.Title = illegalTitle;
Subject.Download(_remoteEpisode);
Subject.Download(_remoteEpisode, _indexer);
Mocker.GetMock<IHttpClient>().Verify(c => c.DownloadFile(It.IsAny<string>(), expectedFilename), Times.Once());
}

View File

@ -454,7 +454,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.QBittorrentTests
var remoteEpisode = CreateRemoteEpisode();
var id = Subject.Download(remoteEpisode);
var id = Subject.Download(remoteEpisode, CreateIndexer());
id.Should().NotBeNullOrEmpty();
}
@ -467,7 +467,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.QBittorrentTests
var remoteEpisode = CreateRemoteEpisode();
remoteEpisode.Release.DownloadUrl = magnetUrl;
var id = Subject.Download(remoteEpisode);
var id = Subject.Download(remoteEpisode, CreateIndexer());
id.Should().Be(expectedHash);
}
@ -482,7 +482,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.QBittorrentTests
var remoteEpisode = CreateRemoteEpisode();
remoteEpisode.Release.DownloadUrl = "magnet:?xt=urn:btih:ZPBPA2P6ROZPKRHK44D5OW6NHXU5Z6KR";
Assert.Throws<ReleaseDownloadException>(() => Subject.Download(remoteEpisode));
Assert.Throws<ReleaseDownloadException>(() => Subject.Download(remoteEpisode, CreateIndexer()));
}
[Test]
@ -495,7 +495,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.QBittorrentTests
var remoteEpisode = CreateRemoteEpisode();
remoteEpisode.Release.DownloadUrl = "magnet:?xt=urn:btih:ZPBPA2P6ROZPKRHK44D5OW6NHXU5Z6KR&tr=udp://abc";
Assert.DoesNotThrow(() => Subject.Download(remoteEpisode));
Assert.DoesNotThrow(() => Subject.Download(remoteEpisode, 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 remoteEpisode = CreateRemoteEpisode();
var id = Subject.Download(remoteEpisode);
var id = Subject.Download(remoteEpisode, 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 remoteEpisode = CreateRemoteEpisode();
var id = Subject.Download(remoteEpisode);
var id = Subject.Download(remoteEpisode, CreateIndexer());
id.Should().NotBeNullOrEmpty();
@ -561,7 +561,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.QBittorrentTests
var remoteEpisode = CreateRemoteEpisode();
var id = Subject.Download(remoteEpisode);
var id = Subject.Download(remoteEpisode, CreateIndexer());
id.Should().NotBeNullOrEmpty();
}
@ -574,7 +574,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.QBittorrentTests
var remoteEpisode = CreateRemoteEpisode();
var id = Subject.Download(remoteEpisode);
var id = Subject.Download(remoteEpisode, CreateIndexer());
id.Should().NotBeNullOrEmpty();
}

View File

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

View File

@ -308,7 +308,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.SabnzbdTests
var remoteEpisode = CreateRemoteEpisode();
remoteEpisode.Release.Title = title;
var id = Subject.Download(remoteEpisode);
var id = Subject.Download(remoteEpisode, 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 remoteEpisode = CreateRemoteEpisode();
var id = Subject.Download(remoteEpisode);
var id = Subject.Download(remoteEpisode, CreateIndexer());
id.Should().NotBeNullOrEmpty();
}
@ -367,7 +367,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.SabnzbdTests
.Build()
.ToList();
Subject.Download(remoteEpisode);
Subject.Download(remoteEpisode, 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());

View File

@ -61,7 +61,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.TransmissionTests
var remoteEpisode = CreateRemoteEpisode();
var id = Subject.Download(remoteEpisode);
var id = Subject.Download(remoteEpisode, CreateIndexer());
id.Should().NotBeNullOrEmpty();
}
@ -74,7 +74,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.TransmissionTests
var remoteEpisode = CreateRemoteEpisode();
var id = Subject.Download(remoteEpisode);
var id = Subject.Download(remoteEpisode, CreateIndexer());
id.Should().NotBeNullOrEmpty();
@ -90,7 +90,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.TransmissionTests
var remoteEpisode = CreateRemoteEpisode();
var id = Subject.Download(remoteEpisode);
var id = Subject.Download(remoteEpisode, CreateIndexer());
id.Should().NotBeNullOrEmpty();
@ -108,7 +108,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.TransmissionTests
var remoteEpisode = CreateRemoteEpisode();
var id = Subject.Download(remoteEpisode);
var id = Subject.Download(remoteEpisode, CreateIndexer());
id.Should().NotBeNullOrEmpty();
@ -123,7 +123,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.TransmissionTests
var remoteEpisode = CreateRemoteEpisode();
var id = Subject.Download(remoteEpisode);
var id = Subject.Download(remoteEpisode, CreateIndexer());
id.Should().NotBeNullOrEmpty();
@ -139,7 +139,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.TransmissionTests
var remoteEpisode = CreateRemoteEpisode();
remoteEpisode.Release.DownloadUrl = magnetUrl;
var id = Subject.Download(remoteEpisode);
var id = Subject.Download(remoteEpisode, CreateIndexer());
id.Should().Be(expectedHash);
}

View File

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

View File

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

View File

@ -82,7 +82,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<RemoteEpisode>()));
mock.Setup(s => s.Download(It.IsAny<RemoteEpisode>(), It.IsAny<IIndexer>()));
Subject.DownloadReport(_parseResult, null);
@ -93,18 +93,18 @@ namespace NzbDrone.Core.Test.Download
public void Download_report_should_grab_using_client()
{
var mock = WithUsenetClient();
mock.Setup(s => s.Download(It.IsAny<RemoteEpisode>()));
mock.Setup(s => s.Download(It.IsAny<RemoteEpisode>(), It.IsAny<IIndexer>()));
Subject.DownloadReport(_parseResult, null);
mock.Verify(s => s.Download(It.IsAny<RemoteEpisode>()), Times.Once());
mock.Verify(s => s.Download(It.IsAny<RemoteEpisode>(), 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<RemoteEpisode>()))
mock.Setup(s => s.Download(It.IsAny<RemoteEpisode>(), It.IsAny<IIndexer>()))
.Throws(new WebException());
Assert.Throws<WebException>(() => Subject.DownloadReport(_parseResult, null));
@ -116,8 +116,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<RemoteEpisode>()))
.Callback<RemoteEpisode>(v =>
mock.Setup(s => s.Download(It.IsAny<RemoteEpisode>(), It.IsAny<IIndexer>()))
.Callback<RemoteEpisode, IIndexer>((v, indexer) =>
{
throw new ReleaseDownloadException(v.Release, "Error", new WebException());
});
@ -136,8 +136,8 @@ namespace NzbDrone.Core.Test.Download
response.Headers["Retry-After"] = "300";
var mock = WithUsenetClient();
mock.Setup(s => s.Download(It.IsAny<RemoteEpisode>()))
.Callback<RemoteEpisode>(v =>
mock.Setup(s => s.Download(It.IsAny<RemoteEpisode>(), It.IsAny<IIndexer>()))
.Callback<RemoteEpisode, IIndexer>((v, indexer) =>
{
throw new ReleaseDownloadException(v.Release, "Error", new TooManyRequestsException(request, response));
});
@ -156,8 +156,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<RemoteEpisode>()))
.Callback<RemoteEpisode>(v =>
mock.Setup(s => s.Download(It.IsAny<RemoteEpisode>(), It.IsAny<IIndexer>()))
.Callback<RemoteEpisode, IIndexer>((v, indexer) =>
{
throw new ReleaseDownloadException(v.Release, "Error", new TooManyRequestsException(request, response));
});
@ -173,7 +173,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<RemoteEpisode>()))
mock.Setup(s => s.Download(It.IsAny<RemoteEpisode>(), It.IsAny<IIndexer>()))
.Throws(new DownloadClientException("Some Error"));
Assert.Throws<DownloadClientException>(() => Subject.DownloadReport(_parseResult, null));
@ -186,8 +186,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<RemoteEpisode>()))
.Callback<RemoteEpisode>(v =>
mock.Setup(s => s.Download(It.IsAny<RemoteEpisode>(), It.IsAny<IIndexer>()))
.Callback<RemoteEpisode, IIndexer>((v, indexer) =>
{
throw new ReleaseUnavailableException(v.Release, "Error", new WebException());
});
@ -203,7 +203,7 @@ namespace NzbDrone.Core.Test.Download
{
Assert.Throws<DownloadClientUnavailableException>(() => Subject.DownloadReport(_parseResult, null));
Mocker.GetMock<IDownloadClient>().Verify(c => c.Download(It.IsAny<RemoteEpisode>()), Times.Never());
Mocker.GetMock<IDownloadClient>().Verify(c => c.Download(It.IsAny<RemoteEpisode>(), It.IsAny<IIndexer>()), Times.Never());
VerifyEventNotPublished<EpisodeGrabbedEvent>();
}
@ -226,7 +226,7 @@ namespace NzbDrone.Core.Test.Download
Subject.DownloadReport(_parseResult, null);
Mocker.GetMock<IDownloadClientStatusService>().Verify(c => c.GetBlockedProviders(), Times.Never());
mockUsenet.Verify(c => c.Download(It.IsAny<RemoteEpisode>()), Times.Once());
mockUsenet.Verify(c => c.Download(It.IsAny<RemoteEpisode>(), It.IsAny<IIndexer>()), Times.Once());
VerifyEventPublished<EpisodeGrabbedEvent>();
}
@ -238,8 +238,8 @@ namespace NzbDrone.Core.Test.Download
Subject.DownloadReport(_parseResult, null);
mockTorrent.Verify(c => c.Download(It.IsAny<RemoteEpisode>()), Times.Never());
mockUsenet.Verify(c => c.Download(It.IsAny<RemoteEpisode>()), Times.Once());
mockTorrent.Verify(c => c.Download(It.IsAny<RemoteEpisode>(), It.IsAny<IIndexer>()), Times.Never());
mockUsenet.Verify(c => c.Download(It.IsAny<RemoteEpisode>(), It.IsAny<IIndexer>()), Times.Once());
}
[Test]
@ -252,8 +252,8 @@ namespace NzbDrone.Core.Test.Download
Subject.DownloadReport(_parseResult, null);
mockTorrent.Verify(c => c.Download(It.IsAny<RemoteEpisode>()), Times.Once());
mockUsenet.Verify(c => c.Download(It.IsAny<RemoteEpisode>()), Times.Never());
mockTorrent.Verify(c => c.Download(It.IsAny<RemoteEpisode>(), It.IsAny<IIndexer>()), Times.Once());
mockUsenet.Verify(c => c.Download(It.IsAny<RemoteEpisode>(), It.IsAny<IIndexer>()), Times.Never());
}
}
}

View File

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

View File

@ -58,7 +58,7 @@ namespace NzbDrone.Core.Download
get;
}
public abstract string Download(RemoteEpisode remoteEpisode);
public abstract string Download(RemoteEpisode remoteEpisode, IIndexer indexer);
public abstract IEnumerable<DownloadClientItem> GetItems();
public virtual DownloadClientItem GetImportItem(DownloadClientItem item, DownloadClientItem previousImportAttempt)

View File

@ -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;
@ -68,6 +71,7 @@ namespace NzbDrone.Core.Download
// Get the seed configuration for this release.
remoteEpisode.SeedConfiguration = _seedConfigProvider.GetSeedConfiguration(remoteEpisode);
var indexer = _indexerFactory.GetInstance(_indexerFactory.Get(remoteEpisode.Release.IndexerId));
// Limit grabs to 2 per second.
if (remoteEpisode.Release.DownloadUrl.IsNotNullOrWhiteSpace() && !remoteEpisode.Release.DownloadUrl.StartsWith("magnet:"))
@ -79,7 +83,7 @@ namespace NzbDrone.Core.Download
string downloadClientId;
try
{
downloadClientId = downloadClient.Download(remoteEpisode);
downloadClientId = downloadClient.Download(remoteEpisode, indexer);
_downloadClientStatusService.RecordSuccess(downloadClient.Definition.Id);
_indexerStatusService.RecordSuccess(remoteEpisode.Release.IndexerId);
}

View File

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

View File

@ -41,7 +41,7 @@ namespace NzbDrone.Core.Download
protected abstract string AddFromMagnetLink(RemoteEpisode remoteEpisode, string hash, string magnetLink);
protected abstract string AddFromTorrentFile(RemoteEpisode remoteEpisode, string hash, string filename, byte[] fileContent);
public override string Download(RemoteEpisode remoteEpisode)
public override string Download(RemoteEpisode remoteEpisode, IIndexer indexer)
{
var torrentInfo = remoteEpisode.Release as TorrentInfo;
@ -68,7 +68,7 @@ namespace NzbDrone.Core.Download
{
try
{
return DownloadFromWebUrl(remoteEpisode, torrentUrl);
return DownloadFromWebUrl(remoteEpisode, indexer, torrentUrl);
}
catch (Exception ex)
{
@ -114,20 +114,20 @@ namespace NzbDrone.Core.Download
if (torrentUrl.IsNotNullOrWhiteSpace())
{
return DownloadFromWebUrl(remoteEpisode, torrentUrl);
return DownloadFromWebUrl(remoteEpisode, indexer, torrentUrl);
}
}
return null;
}
private string DownloadFromWebUrl(RemoteEpisode remoteEpisode, string torrentUrl)
private string DownloadFromWebUrl(RemoteEpisode remoteEpisode, IIndexer indexer, string torrentUrl)
{
byte[] torrentFile = null;
try
{
var request = new HttpRequest(torrentUrl);
var request = indexer.GetDownloadRequest(torrentUrl);
request.RateLimitKey = remoteEpisode?.Release?.IndexerId.ToString();
request.Headers.Accept = "application/x-bittorrent";
request.AllowAutoRedirect = false;
@ -149,7 +149,9 @@ namespace NzbDrone.Core.Download
return DownloadFromMagnetUrl(remoteEpisode, locationHeader);
}
return DownloadFromWebUrl(remoteEpisode, locationHeader);
request.Url += new HttpUri(locationHeader);
return DownloadFromWebUrl(remoteEpisode, indexer, request.Url.ToString());
}
throw new WebException("Remote website tried to redirect without providing a location.");

View File

@ -34,7 +34,7 @@ namespace NzbDrone.Core.Download
protected abstract string AddFromNzbFile(RemoteEpisode remoteEpisode, string filename, byte[] fileContent);
public override string Download(RemoteEpisode remoteEpisode)
public override string Download(RemoteEpisode remoteEpisode, IIndexer indexer)
{
var url = remoteEpisode.Release.DownloadUrl;
var filename = FileNameBuilder.CleanFileName(remoteEpisode.Release.Title) + ".nzb";
@ -43,7 +43,7 @@ namespace NzbDrone.Core.Download
try
{
var request = new HttpRequest(url);
var request = indexer.GetDownloadRequest(url);
request.RateLimitKey = remoteEpisode?.Release?.IndexerId.ToString();
nzbData = _httpClient.Get(request).ResponseData;

View File

@ -12,7 +12,6 @@ using NzbDrone.Core.Indexers.Exceptions;
using NzbDrone.Core.IndexerSearch.Definitions;
using NzbDrone.Core.Parser;
using NzbDrone.Core.Parser.Model;
using NzbDrone.Core.ThingiProvider;
namespace NzbDrone.Core.Indexers
{
@ -109,6 +108,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>();

View File

@ -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;
@ -18,5 +19,6 @@ namespace NzbDrone.Core.Indexers
IList<ReleaseInfo> Fetch(DailySeasonSearchCriteria searchCriteria);
IList<ReleaseInfo> Fetch(AnimeEpisodeSearchCriteria searchCriteria);
IList<ReleaseInfo> Fetch(SpecialEpisodeSearchCriteria searchCriteria);
HttpRequest GetDownloadRequest(string link);
}
}

View File

@ -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;
@ -74,6 +74,7 @@ namespace NzbDrone.Core.Indexers
public abstract IList<ReleaseInfo> Fetch(DailySeasonSearchCriteria searchCriteria);
public abstract IList<ReleaseInfo> Fetch(AnimeEpisodeSearchCriteria searchCriteria);
public abstract IList<ReleaseInfo> Fetch(SpecialEpisodeSearchCriteria searchCriteria);
public abstract HttpRequest GetDownloadRequest(string link);
protected virtual IList<ReleaseInfo> CleanupReleases(IEnumerable<ReleaseInfo> releases)
{