mirror of
https://github.com/Radarr/Radarr.git
synced 2024-09-11 20:12:41 +02:00
Build download requests from indexer implementation
(cherry picked from commit a0b08f6c6f106d92cdb12fbb959dd2605c22fe6a)
This commit is contained in:
parent
7c67382f6f
commit
1807ccfc48
@ -148,7 +148,7 @@ public void Download_should_download_file_if_it_doesnt_exist()
|
||||
{
|
||||
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 @@ public void Download_should_save_magnet_if_enabled()
|
||||
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 @@ public void Download_should_save_magnet_using_specified_extension()
|
||||
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 @@ public void Download_should_not_save_magnet_if_disabled()
|
||||
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 @@ public void Download_should_prefer_torrent_over_magnet()
|
||||
|
||||
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 @@ public void Download_should_replace_illegal_characters_in_title()
|
||||
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 @@ public void Download_should_throw_if_magnet_and_torrent_url_does_not_exist()
|
||||
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 @@ public void should_return_null_hash()
|
||||
{
|
||||
var remoteMovie = CreateRemoteMovie();
|
||||
|
||||
Subject.Download(remoteMovie).Should().BeNull();
|
||||
Subject.Download(remoteMovie, CreateIndexer()).Should().BeNull();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -119,7 +119,7 @@ public void Download_should_download_file_if_it_doesnt_exist()
|
||||
{
|
||||
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 @@ public void Download_should_replace_illegal_characters_in_title()
|
||||
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 @@ public void Download_should_return_unique_id()
|
||||
|
||||
var remoteMovie = CreateRemoteMovie();
|
||||
|
||||
var id = Subject.Download(remoteMovie);
|
||||
var id = Subject.Download(remoteMovie, CreateIndexer());
|
||||
|
||||
id.Should().NotBeNullOrEmpty();
|
||||
}
|
||||
@ -219,7 +219,7 @@ public void Download_should_get_hash_from_magnet_url(string magnetUrl, string ex
|
||||
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 @@ protected virtual RemoteMovie CreateRemoteMovie()
|
||||
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 @@ public void Download_with_TvDirectory_should_force_directory()
|
||||
|
||||
var remoteEpisode = CreateRemoteMovie();
|
||||
|
||||
var id = Subject.Download(remoteEpisode);
|
||||
var id = Subject.Download(remoteEpisode, CreateIndexer());
|
||||
|
||||
id.Should().NotBeNullOrEmpty();
|
||||
|
||||
@ -410,7 +410,7 @@ public void Download_with_category_should_force_directory()
|
||||
|
||||
var remoteEpisode = CreateRemoteMovie();
|
||||
|
||||
var id = Subject.Download(remoteEpisode);
|
||||
var id = Subject.Download(remoteEpisode, CreateIndexer());
|
||||
|
||||
id.Should().NotBeNullOrEmpty();
|
||||
|
||||
@ -426,7 +426,7 @@ public void Download_without_TvDirectory_and_Category_should_use_default()
|
||||
|
||||
var remoteEpisode = CreateRemoteMovie();
|
||||
|
||||
var id = Subject.Download(remoteEpisode);
|
||||
var id = Subject.Download(remoteEpisode, CreateIndexer());
|
||||
|
||||
id.Should().NotBeNullOrEmpty();
|
||||
|
||||
@ -505,7 +505,7 @@ public void Download_should_throw_and_not_add_task_if_cannot_get_serial_number()
|
||||
.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 @@ public void Download_with_TvDirectory_should_force_directory()
|
||||
|
||||
var remoteEpisode = CreateRemoteMovie();
|
||||
|
||||
var id = Subject.Download(remoteEpisode);
|
||||
var id = Subject.Download(remoteEpisode, CreateIndexer());
|
||||
|
||||
id.Should().NotBeNullOrEmpty();
|
||||
|
||||
@ -292,7 +292,7 @@ public void Download_with_category_should_force_directory()
|
||||
|
||||
var remoteEpisode = CreateRemoteMovie();
|
||||
|
||||
var id = Subject.Download(remoteEpisode);
|
||||
var id = Subject.Download(remoteEpisode, CreateIndexer());
|
||||
|
||||
id.Should().NotBeNullOrEmpty();
|
||||
|
||||
@ -308,7 +308,7 @@ public void Download_without_TvDirectory_and_Category_should_use_default()
|
||||
|
||||
var remoteEpisode = CreateRemoteMovie();
|
||||
|
||||
var id = Subject.Download(remoteEpisode);
|
||||
var id = Subject.Download(remoteEpisode, CreateIndexer());
|
||||
|
||||
id.Should().NotBeNullOrEmpty();
|
||||
|
||||
@ -387,7 +387,7 @@ public void Download_should_throw_and_not_add_task_if_cannot_get_serial_number()
|
||||
.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 @@ public void Download_with_DestinationDirectory_should_force_directory()
|
||||
|
||||
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 @@ public void Download_with_Category_should_force_directory()
|
||||
|
||||
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 @@ public void Download_without_DestinationDirectory_and_Category_should_use_defaul
|
||||
|
||||
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 @@ public void Download_should_pause_torrent_as_expected(bool addPausedSetting, boo
|
||||
|
||||
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 @@ public void Download_should_queue_torrent_first_as_expected(int ageDay, int olde
|
||||
|
||||
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 @@ public void Download_should_define_seed_ratio_as_expected(double? providerSeedRa
|
||||
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 @@ public void Download_should_return_unique_id()
|
||||
|
||||
var remoteMovie = CreateRemoteMovie();
|
||||
|
||||
var id = Subject.Download(remoteMovie);
|
||||
var id = Subject.Download(remoteMovie, CreateIndexer());
|
||||
|
||||
id.Should().NotBeNullOrEmpty();
|
||||
}
|
||||
@ -286,7 +286,7 @@ public void Download_from_magnet_link_should_return_hash_uppercase()
|
||||
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 @@ public void Download_from_torrent_file_should_return_hash_uppercase()
|
||||
.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 @@ public void Download_should_return_unique_id()
|
||||
|
||||
var remoteMovie = CreateRemoteMovie();
|
||||
|
||||
var id = Subject.Download(remoteMovie);
|
||||
var id = Subject.Download(remoteMovie, CreateIndexer());
|
||||
|
||||
id.Should().NotBeNullOrEmpty();
|
||||
}
|
||||
@ -218,7 +218,7 @@ public void Download_should_throw_if_failed()
|
||||
|
||||
var remoteMovie = CreateRemoteMovie();
|
||||
|
||||
Assert.Throws<DownloadClientException>(() => Subject.Download(remoteMovie));
|
||||
Assert.Throws<DownloadClientException>(() => Subject.Download(remoteMovie, CreateIndexer()));
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
@ -345,7 +345,7 @@ public void Download_should_return_unique_id()
|
||||
|
||||
var remoteMovie = CreateRemoteMovie();
|
||||
|
||||
var id = Subject.Download(remoteMovie);
|
||||
var id = Subject.Download(remoteMovie, CreateIndexer());
|
||||
|
||||
id.Should().NotBeNullOrEmpty();
|
||||
}
|
||||
@ -357,7 +357,7 @@ public void Download_should_throw_if_failed()
|
||||
|
||||
var remoteMovie = CreateRemoteMovie();
|
||||
|
||||
Assert.Throws<DownloadClientRejectedReleaseException>(() => Subject.Download(remoteMovie));
|
||||
Assert.Throws<DownloadClientRejectedReleaseException>(() => Subject.Download(remoteMovie, CreateIndexer()));
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
@ -3,12 +3,17 @@
|
||||
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 @@ public class PneumaticProviderFixture : CoreTest<Pneumatic>
|
||||
private string _strmFolder;
|
||||
private string _nzbPath;
|
||||
private RemoteMovie _remoteMovie;
|
||||
private IIndexer _indexer;
|
||||
private DownloadClientItem _downloadClientItem;
|
||||
|
||||
[SetUp]
|
||||
@ -39,6 +45,12 @@ public void Setup()
|
||||
|
||||
_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 @@ private void WithFailedDownload()
|
||||
[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 @@ public void should_throw_on_failed_download()
|
||||
{
|
||||
WithFailedDownload();
|
||||
|
||||
Assert.Throws<WebException>(() => Subject.Download(_remoteMovie));
|
||||
Assert.Throws<WebException>(() => Subject.Download(_remoteMovie, _indexer));
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -85,7 +97,7 @@ public void should_replace_illegal_characters_in_title()
|
||||
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 @@ public void Download_should_return_unique_id()
|
||||
|
||||
var remoteMovie = CreateRemoteMovie();
|
||||
|
||||
var id = Subject.Download(remoteMovie);
|
||||
var id = Subject.Download(remoteMovie, CreateIndexer());
|
||||
|
||||
id.Should().NotBeNullOrEmpty();
|
||||
}
|
||||
@ -466,7 +466,7 @@ public void Download_should_get_hash_from_magnet_url(string magnetUrl, string ex
|
||||
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 @@ public void Download_should_refuse_magnet_if_no_trackers_provided_and_dht_is_dis
|
||||
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 @@ public void Download_should_accept_magnet_if_trackers_provided_and_dht_is_disabl
|
||||
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 @@ public void Download_should_set_top_priority()
|
||||
|
||||
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 @@ public void Download_should_not_fail_if_top_priority_not_available()
|
||||
|
||||
var remoteMovie = CreateRemoteMovie();
|
||||
|
||||
var id = Subject.Download(remoteMovie);
|
||||
var id = Subject.Download(remoteMovie, CreateIndexer());
|
||||
|
||||
id.Should().NotBeNullOrEmpty();
|
||||
|
||||
@ -560,7 +560,7 @@ public void Download_should_handle_http_redirect_to_magnet()
|
||||
|
||||
var remoteMovie = CreateRemoteMovie();
|
||||
|
||||
var id = Subject.Download(remoteMovie);
|
||||
var id = Subject.Download(remoteMovie, CreateIndexer());
|
||||
|
||||
id.Should().NotBeNullOrEmpty();
|
||||
}
|
||||
@ -573,7 +573,7 @@ public void Download_should_handle_http_redirect_to_torrent()
|
||||
|
||||
var remoteMovie = CreateRemoteMovie();
|
||||
|
||||
var id = Subject.Download(remoteMovie);
|
||||
var id = Subject.Download(remoteMovie, CreateIndexer());
|
||||
|
||||
id.Should().NotBeNullOrEmpty();
|
||||
}
|
||||
|
@ -117,7 +117,7 @@ public void Download_should_return_unique_id()
|
||||
|
||||
var remoteEpisode = CreateRemoteMovie();
|
||||
|
||||
var id = Subject.Download(remoteEpisode);
|
||||
var id = Subject.Download(remoteEpisode, CreateIndexer());
|
||||
|
||||
id.Should().NotBeNullOrEmpty();
|
||||
}
|
||||
|
@ -306,7 +306,7 @@ public void Download_should_use_clean_title(string title, string filename)
|
||||
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 @@ public void Download_should_return_unique_id()
|
||||
|
||||
var remoteMovie = CreateRemoteMovie();
|
||||
|
||||
var id = Subject.Download(remoteMovie);
|
||||
var id = Subject.Download(remoteMovie, CreateIndexer());
|
||||
|
||||
id.Should().NotBeNullOrEmpty();
|
||||
}
|
||||
@ -366,7 +366,7 @@ public void Download_should_use_sabRecentTvPriority_when_recentEpisode_is_true()
|
||||
.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 @@ public void Download_should_return_unique_id()
|
||||
|
||||
var remoteMovie = CreateRemoteMovie();
|
||||
|
||||
var id = Subject.Download(remoteMovie);
|
||||
var id = Subject.Download(remoteMovie, CreateIndexer());
|
||||
|
||||
id.Should().NotBeNullOrEmpty();
|
||||
}
|
||||
@ -74,7 +74,7 @@ public void Download_with_MovieDirectory_should_force_directory()
|
||||
|
||||
var remoteMovie = CreateRemoteMovie();
|
||||
|
||||
var id = Subject.Download(remoteMovie);
|
||||
var id = Subject.Download(remoteMovie, CreateIndexer());
|
||||
|
||||
id.Should().NotBeNullOrEmpty();
|
||||
|
||||
@ -90,7 +90,7 @@ public void Download_with_category_should_force_directory()
|
||||
|
||||
var remoteMovie = CreateRemoteMovie();
|
||||
|
||||
var id = Subject.Download(remoteMovie);
|
||||
var id = Subject.Download(remoteMovie, CreateIndexer());
|
||||
|
||||
id.Should().NotBeNullOrEmpty();
|
||||
|
||||
@ -108,7 +108,7 @@ public void Download_with_category_should_not_have_double_slashes()
|
||||
|
||||
var remoteMovie = CreateRemoteMovie();
|
||||
|
||||
var id = Subject.Download(remoteMovie);
|
||||
var id = Subject.Download(remoteMovie, CreateIndexer());
|
||||
|
||||
id.Should().NotBeNullOrEmpty();
|
||||
|
||||
@ -123,7 +123,7 @@ public void Download_without_TvDirectory_and_Category_should_use_default()
|
||||
|
||||
var remoteMovie = CreateRemoteMovie();
|
||||
|
||||
var id = Subject.Download(remoteMovie);
|
||||
var id = Subject.Download(remoteMovie, CreateIndexer());
|
||||
|
||||
id.Should().NotBeNullOrEmpty();
|
||||
|
||||
@ -139,7 +139,7 @@ public void Download_should_get_hash_from_magnet_url(string magnetUrl, string ex
|
||||
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 @@ public void Download_should_return_unique_id()
|
||||
|
||||
var remoteMovie = CreateRemoteMovie();
|
||||
|
||||
var id = Subject.Download(remoteMovie);
|
||||
var id = Subject.Download(remoteMovie, CreateIndexer());
|
||||
|
||||
id.Should().NotBeNullOrEmpty();
|
||||
}
|
||||
@ -259,7 +259,7 @@ public void Download_should_get_hash_from_magnet_url(string magnetUrl, string ex
|
||||
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 @@ public void Download_should_handle_http_redirect_to_magnet()
|
||||
|
||||
var remoteMovie = CreateRemoteMovie();
|
||||
|
||||
var id = Subject.Download(remoteMovie);
|
||||
var id = Subject.Download(remoteMovie, CreateIndexer());
|
||||
|
||||
id.Should().NotBeNullOrEmpty();
|
||||
}
|
||||
@ -370,7 +370,7 @@ public void Download_should_handle_http_redirect_to_torrent()
|
||||
|
||||
var remoteMovie = CreateRemoteMovie();
|
||||
|
||||
var id = Subject.Download(remoteMovie);
|
||||
var id = Subject.Download(remoteMovie, CreateIndexer());
|
||||
|
||||
id.Should().NotBeNullOrEmpty();
|
||||
}
|
||||
|
@ -69,7 +69,7 @@ public void Download_should_return_unique_id()
|
||||
|
||||
var remoteMovie = CreateRemoteMovie();
|
||||
|
||||
var id = Subject.Download(remoteMovie);
|
||||
var id = Subject.Download(remoteMovie, CreateIndexer());
|
||||
|
||||
id.Should().NotBeNullOrEmpty();
|
||||
}
|
||||
@ -82,7 +82,7 @@ public void Download_with_MovieDirectory_should_force_directory()
|
||||
|
||||
var remoteMovie = CreateRemoteMovie();
|
||||
|
||||
var id = Subject.Download(remoteMovie);
|
||||
var id = Subject.Download(remoteMovie, CreateIndexer());
|
||||
|
||||
id.Should().NotBeNullOrEmpty();
|
||||
|
||||
@ -98,7 +98,7 @@ public void Download_with_category_should_force_directory()
|
||||
|
||||
var remoteMovie = CreateRemoteMovie();
|
||||
|
||||
var id = Subject.Download(remoteMovie);
|
||||
var id = Subject.Download(remoteMovie, CreateIndexer());
|
||||
|
||||
id.Should().NotBeNullOrEmpty();
|
||||
|
||||
@ -116,7 +116,7 @@ public void Download_with_category_should_not_have_double_slashes()
|
||||
|
||||
var remoteMovie = CreateRemoteMovie();
|
||||
|
||||
var id = Subject.Download(remoteMovie);
|
||||
var id = Subject.Download(remoteMovie, CreateIndexer());
|
||||
|
||||
id.Should().NotBeNullOrEmpty();
|
||||
|
||||
@ -131,7 +131,7 @@ public void Download_without_MovieDirectory_and_Category_should_use_default()
|
||||
|
||||
var remoteMovie = CreateRemoteMovie();
|
||||
|
||||
var id = Subject.Download(remoteMovie);
|
||||
var id = Subject.Download(remoteMovie, CreateIndexer());
|
||||
|
||||
id.Should().NotBeNullOrEmpty();
|
||||
|
||||
@ -147,7 +147,7 @@ public void Download_should_get_hash_from_magnet_url(string magnetUrl, string ex
|
||||
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 @@ private Mock<IDownloadClient> WithTorrentClient()
|
||||
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 @@ public void Download_report_should_publish_on_grab_event()
|
||||
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 @@ public void Download_report_should_not_publish_on_failed_grab_event()
|
||||
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 @@ public void Download_report_should_trigger_indexer_backoff_on_http429_with_long_
|
||||
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 @@ public void Download_report_should_trigger_indexer_backoff_on_http429_based_on_d
|
||||
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 @@ public void Download_report_should_trigger_indexer_backoff_on_http429_based_on_d
|
||||
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 @@ public void Download_report_should_not_trigger_indexer_backoff_on_downloadclient
|
||||
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 @@ public void should_not_attempt_download_if_client_isnt_configured()
|
||||
{
|
||||
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 @@ public void should_attempt_download_even_if_client_is_disabled()
|
||||
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 @@ public void should_send_download_to_correct_usenet_client()
|
||||
|
||||
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 @@ public void should_send_download_to_correct_torrent_client()
|
||||
|
||||
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 @@ public Pneumatic(IHttpClient httpClient,
|
||||
|
||||
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 @@ public abstract DownloadProtocol Protocol
|
||||
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 @@ public class DownloadService : IDownloadService
|
||||
{
|
||||
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 @@ public class DownloadService : IDownloadService
|
||||
|
||||
public DownloadService(IProvideDownloadClient downloadClientProvider,
|
||||
IDownloadClientStatusService downloadClientStatusService,
|
||||
IIndexerFactory indexerFactory,
|
||||
IIndexerStatusService indexerStatusService,
|
||||
IRateLimitService rateLimitService,
|
||||
IEventAggregator eventAggregator,
|
||||
@ -38,6 +40,7 @@ public DownloadService(IProvideDownloadClient downloadClientProvider,
|
||||
{
|
||||
_downloadClientProvider = downloadClientProvider;
|
||||
_downloadClientStatusService = downloadClientStatusService;
|
||||
_indexerFactory = indexerFactory;
|
||||
_indexerStatusService = indexerStatusService;
|
||||
_rateLimitService = rateLimitService;
|
||||
_eventAggregator = eventAggregator;
|
||||
@ -59,6 +62,7 @@ public void DownloadReport(RemoteMovie remoteMovie)
|
||||
|
||||
// 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 @@ public void DownloadReport(RemoteMovie remoteMovie)
|
||||
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 @@ protected TorrentClientBase(ITorrentFileInfoReader torrentFileInfoReader,
|
||||
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 @@ public override string Download(RemoteMovie remoteMovie)
|
||||
{
|
||||
try
|
||||
{
|
||||
return DownloadFromWebUrl(remoteMovie, torrentUrl);
|
||||
return DownloadFromWebUrl(remoteMovie, indexer, torrentUrl);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@ -115,20 +115,20 @@ public override string Download(RemoteMovie remoteMovie)
|
||||
|
||||
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 @@ private string DownloadFromWebUrl(RemoteMovie remoteMovie, string torrentUrl)
|
||||
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 @@ protected UsenetClientBase(IHttpClient httpClient,
|
||||
|
||||
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 @@ public override string Download(RemoteMovie remoteMovie)
|
||||
|
||||
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 @@ protected IndexerPageableRequestChain GetRequestChain(SearchCriteriaBase searchC
|
||||
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 @@ public interface IIndexer : IProvider
|
||||
|
||||
IList<ReleaseInfo> FetchRecent();
|
||||
IList<ReleaseInfo> Fetch(MovieSearchCriteria searchCriteria);
|
||||
HttpRequest GetDownloadRequest(string link);
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@
|
||||
using FluentValidation.Results;
|
||||
using NLog;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using NzbDrone.Common.Http;
|
||||
using NzbDrone.Core.Configuration;
|
||||
using NzbDrone.Core.IndexerSearch.Definitions;
|
||||
using NzbDrone.Core.Languages;
|
||||
@ -72,6 +73,7 @@ public virtual object RequestAction(string action, IDictionary<string, string> q
|
||||
|
||||
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…
Reference in New Issue
Block a user