mirror of
https://github.com/Sonarr/Sonarr.git
synced 2024-12-12 11:15:43 +02:00
Build download requests from indexer implementation
This commit is contained in:
parent
7aa8463438
commit
a0b08f6c6f
@ -147,7 +147,7 @@ public void Download_should_download_file_if_it_doesnt_exist()
|
||||
{
|
||||
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 @@ public void Download_should_save_magnet_if_enabled()
|
||||
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 @@ public void Download_should_save_magnet_using_specified_extension()
|
||||
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 @@ public void Download_should_not_save_magnet_if_disabled()
|
||||
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 @@ public void Download_should_prefer_torrent_over_magnet()
|
||||
|
||||
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 @@ public void Download_should_replace_illegal_characters_in_title()
|
||||
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 @@ public void Download_should_throw_if_magnet_and_torrent_url_does_not_exist()
|
||||
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 @@ public void should_return_null_hash()
|
||||
{
|
||||
var remoteEpisode = CreateRemoteEpisode();
|
||||
|
||||
Subject.Download(remoteEpisode).Should().BeNull();
|
||||
Subject.Download(remoteEpisode, CreateIndexer()).Should().BeNull();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -119,7 +119,7 @@ public void Download_should_download_file_if_it_doesnt_exist()
|
||||
{
|
||||
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 @@ public void Download_should_replace_illegal_characters_in_title()
|
||||
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());
|
||||
|
@ -206,7 +206,7 @@ public void Download_should_return_unique_id()
|
||||
|
||||
var remoteEpisode = CreateRemoteEpisode();
|
||||
|
||||
var id = Subject.Download(remoteEpisode);
|
||||
var id = Subject.Download(remoteEpisode, CreateIndexer());
|
||||
|
||||
id.Should().NotBeNullOrEmpty();
|
||||
}
|
||||
@ -219,7 +219,7 @@ public void Download_should_get_hash_from_magnet_url(string magnetUrl, string ex
|
||||
var remoteEpisode = CreateRemoteEpisode();
|
||||
remoteEpisode.Release.DownloadUrl = magnetUrl;
|
||||
|
||||
var id = Subject.Download(remoteEpisode);
|
||||
var id = Subject.Download(remoteEpisode, CreateIndexer());
|
||||
|
||||
id.Should().Be(expectedHash);
|
||||
}
|
||||
|
@ -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 @@ protected virtual RemoteEpisode CreateRemoteEpisode()
|
||||
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);
|
||||
|
@ -381,7 +381,7 @@ public void Download_with_TvDirectory_should_force_directory()
|
||||
|
||||
var remoteEpisode = CreateRemoteEpisode();
|
||||
|
||||
var id = Subject.Download(remoteEpisode);
|
||||
var id = Subject.Download(remoteEpisode, CreateIndexer());
|
||||
|
||||
id.Should().NotBeNullOrEmpty();
|
||||
|
||||
@ -398,7 +398,7 @@ public void Download_with_category_should_force_directory()
|
||||
|
||||
var remoteEpisode = CreateRemoteEpisode();
|
||||
|
||||
var id = Subject.Download(remoteEpisode);
|
||||
var id = Subject.Download(remoteEpisode, CreateIndexer());
|
||||
|
||||
id.Should().NotBeNullOrEmpty();
|
||||
|
||||
@ -414,7 +414,7 @@ public void Download_without_TvDirectory_and_Category_should_use_default()
|
||||
|
||||
var remoteEpisode = CreateRemoteEpisode();
|
||||
|
||||
var id = Subject.Download(remoteEpisode);
|
||||
var id = Subject.Download(remoteEpisode, CreateIndexer());
|
||||
|
||||
id.Should().NotBeNullOrEmpty();
|
||||
|
||||
@ -493,7 +493,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());
|
||||
|
@ -259,7 +259,7 @@ public void Download_with_TvDirectory_should_force_directory()
|
||||
|
||||
var remoteEpisode = CreateRemoteEpisode();
|
||||
|
||||
var id = Subject.Download(remoteEpisode);
|
||||
var id = Subject.Download(remoteEpisode, CreateIndexer());
|
||||
|
||||
id.Should().NotBeNullOrEmpty();
|
||||
|
||||
@ -276,7 +276,7 @@ public void Download_with_category_should_force_directory()
|
||||
|
||||
var remoteEpisode = CreateRemoteEpisode();
|
||||
|
||||
var id = Subject.Download(remoteEpisode);
|
||||
var id = Subject.Download(remoteEpisode, CreateIndexer());
|
||||
|
||||
id.Should().NotBeNullOrEmpty();
|
||||
|
||||
@ -292,7 +292,7 @@ public void Download_without_TvDirectory_and_Category_should_use_default()
|
||||
|
||||
var remoteEpisode = CreateRemoteEpisode();
|
||||
|
||||
var id = Subject.Download(remoteEpisode);
|
||||
var id = Subject.Download(remoteEpisode, CreateIndexer());
|
||||
|
||||
id.Should().NotBeNullOrEmpty();
|
||||
|
||||
@ -371,7 +371,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());
|
||||
|
@ -153,7 +153,7 @@ public void Download_with_DestinationDirectory_should_force_directory()
|
||||
|
||||
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 @@ public void Download_with_Category_should_force_directory()
|
||||
|
||||
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 @@ public void Download_without_DestinationDirectory_and_Category_should_use_defaul
|
||||
|
||||
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 @@ public void Download_should_pause_torrent_as_expected(bool addPausedSetting, boo
|
||||
|
||||
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 @@ public void Download_should_queue_torrent_first_as_expected(int ageDay, int olde
|
||||
|
||||
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 @@ public void Download_should_define_seed_ratio_as_expected(double? providerSeedRa
|
||||
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());
|
||||
|
@ -202,7 +202,7 @@ public void Download_should_return_unique_id()
|
||||
|
||||
var remoteEpisode = CreateRemoteEpisode();
|
||||
|
||||
var id = Subject.Download(remoteEpisode);
|
||||
var id = Subject.Download(remoteEpisode, 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(remoteEpisode);
|
||||
var result = Subject.Download(remoteEpisode, 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(remoteEpisode);
|
||||
var result = Subject.Download(remoteEpisode, CreateIndexer());
|
||||
|
||||
Assert.IsFalse(result.Any(c => char.IsLower(c)));
|
||||
}
|
||||
|
@ -206,7 +206,7 @@ public void Download_should_return_unique_id()
|
||||
|
||||
var remoteEpisode = CreateRemoteEpisode();
|
||||
|
||||
var id = Subject.Download(remoteEpisode);
|
||||
var id = Subject.Download(remoteEpisode, CreateIndexer());
|
||||
|
||||
id.Should().NotBeNullOrEmpty();
|
||||
}
|
||||
@ -218,7 +218,7 @@ public void Download_should_throw_if_failed()
|
||||
|
||||
var remoteEpisode = CreateRemoteEpisode();
|
||||
|
||||
Assert.Throws<DownloadClientException>(() => Subject.Download(remoteEpisode));
|
||||
Assert.Throws<DownloadClientException>(() => Subject.Download(remoteEpisode, CreateIndexer()));
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
@ -346,7 +346,7 @@ public void Download_should_return_unique_id()
|
||||
|
||||
var remoteEpisode = CreateRemoteEpisode();
|
||||
|
||||
var id = Subject.Download(remoteEpisode);
|
||||
var id = Subject.Download(remoteEpisode, CreateIndexer());
|
||||
|
||||
id.Should().NotBeNullOrEmpty();
|
||||
}
|
||||
@ -358,7 +358,7 @@ public void Download_should_throw_if_failed()
|
||||
|
||||
var remoteEpisode = CreateRemoteEpisode();
|
||||
|
||||
Assert.Throws<DownloadClientRejectedReleaseException>(() => Subject.Download(remoteEpisode));
|
||||
Assert.Throws<DownloadClientRejectedReleaseException>(() => Subject.Download(remoteEpisode, 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 RemoteEpisode _remoteEpisode;
|
||||
private IIndexer _indexer;
|
||||
private DownloadClientItem _downloadClientItem;
|
||||
|
||||
[SetUp]
|
||||
@ -40,6 +46,12 @@ public void Setup()
|
||||
_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 @@ private void WithFailedDownload()
|
||||
[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 @@ public void should_throw_on_failed_download()
|
||||
{
|
||||
WithFailedDownload();
|
||||
|
||||
Assert.Throws<WebException>(() => Subject.Download(_remoteEpisode));
|
||||
Assert.Throws<WebException>(() => Subject.Download(_remoteEpisode, _indexer));
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -79,7 +91,7 @@ public void should_throw_if_full_season_download()
|
||||
_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 @@ public void should_replace_illegal_characters_in_title()
|
||||
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());
|
||||
}
|
||||
|
@ -454,7 +454,7 @@ public void Download_should_return_unique_id()
|
||||
|
||||
var remoteEpisode = CreateRemoteEpisode();
|
||||
|
||||
var id = Subject.Download(remoteEpisode);
|
||||
var id = Subject.Download(remoteEpisode, CreateIndexer());
|
||||
|
||||
id.Should().NotBeNullOrEmpty();
|
||||
}
|
||||
@ -467,7 +467,7 @@ public void Download_should_get_hash_from_magnet_url(string magnetUrl, string ex
|
||||
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 @@ public void Download_should_refuse_magnet_if_no_trackers_provided_and_dht_is_dis
|
||||
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 @@ public void Download_should_accept_magnet_if_trackers_provided_and_dht_is_disabl
|
||||
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 @@ public void Download_should_set_top_priority()
|
||||
|
||||
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 @@ public void Download_should_not_fail_if_top_priority_not_available()
|
||||
|
||||
var remoteEpisode = CreateRemoteEpisode();
|
||||
|
||||
var id = Subject.Download(remoteEpisode);
|
||||
var id = Subject.Download(remoteEpisode, CreateIndexer());
|
||||
|
||||
id.Should().NotBeNullOrEmpty();
|
||||
|
||||
@ -561,7 +561,7 @@ public void Download_should_handle_http_redirect_to_magnet()
|
||||
|
||||
var remoteEpisode = CreateRemoteEpisode();
|
||||
|
||||
var id = Subject.Download(remoteEpisode);
|
||||
var id = Subject.Download(remoteEpisode, CreateIndexer());
|
||||
|
||||
id.Should().NotBeNullOrEmpty();
|
||||
}
|
||||
@ -574,7 +574,7 @@ public void Download_should_handle_http_redirect_to_torrent()
|
||||
|
||||
var remoteEpisode = CreateRemoteEpisode();
|
||||
|
||||
var id = Subject.Download(remoteEpisode);
|
||||
var id = Subject.Download(remoteEpisode, CreateIndexer());
|
||||
|
||||
id.Should().NotBeNullOrEmpty();
|
||||
}
|
||||
|
@ -117,7 +117,7 @@ public void Download_should_return_unique_id()
|
||||
|
||||
var remoteEpisode = CreateRemoteEpisode();
|
||||
|
||||
var id = Subject.Download(remoteEpisode);
|
||||
var id = Subject.Download(remoteEpisode, CreateIndexer());
|
||||
|
||||
id.Should().NotBeNullOrEmpty();
|
||||
}
|
||||
|
@ -308,7 +308,7 @@ public void Download_should_use_clean_title(string title, string filename)
|
||||
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 @@ public void Download_should_return_unique_id()
|
||||
|
||||
var remoteEpisode = CreateRemoteEpisode();
|
||||
|
||||
var id = Subject.Download(remoteEpisode);
|
||||
var id = Subject.Download(remoteEpisode, CreateIndexer());
|
||||
|
||||
id.Should().NotBeNullOrEmpty();
|
||||
}
|
||||
@ -367,7 +367,7 @@ public void Download_should_use_sabRecentTvPriority_when_recentEpisode_is_true()
|
||||
.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());
|
||||
|
@ -61,7 +61,7 @@ public void Download_should_return_unique_id()
|
||||
|
||||
var remoteEpisode = CreateRemoteEpisode();
|
||||
|
||||
var id = Subject.Download(remoteEpisode);
|
||||
var id = Subject.Download(remoteEpisode, CreateIndexer());
|
||||
|
||||
id.Should().NotBeNullOrEmpty();
|
||||
}
|
||||
@ -74,7 +74,7 @@ public void Download_with_TvDirectory_should_force_directory()
|
||||
|
||||
var remoteEpisode = CreateRemoteEpisode();
|
||||
|
||||
var id = Subject.Download(remoteEpisode);
|
||||
var id = Subject.Download(remoteEpisode, CreateIndexer());
|
||||
|
||||
id.Should().NotBeNullOrEmpty();
|
||||
|
||||
@ -90,7 +90,7 @@ public void Download_with_category_should_force_directory()
|
||||
|
||||
var remoteEpisode = CreateRemoteEpisode();
|
||||
|
||||
var id = Subject.Download(remoteEpisode);
|
||||
var id = Subject.Download(remoteEpisode, CreateIndexer());
|
||||
|
||||
id.Should().NotBeNullOrEmpty();
|
||||
|
||||
@ -108,7 +108,7 @@ public void Download_with_category_should_not_have_double_slashes()
|
||||
|
||||
var remoteEpisode = CreateRemoteEpisode();
|
||||
|
||||
var id = Subject.Download(remoteEpisode);
|
||||
var id = Subject.Download(remoteEpisode, CreateIndexer());
|
||||
|
||||
id.Should().NotBeNullOrEmpty();
|
||||
|
||||
@ -123,7 +123,7 @@ public void Download_without_TvDirectory_and_Category_should_use_default()
|
||||
|
||||
var remoteEpisode = CreateRemoteEpisode();
|
||||
|
||||
var id = Subject.Download(remoteEpisode);
|
||||
var id = Subject.Download(remoteEpisode, CreateIndexer());
|
||||
|
||||
id.Should().NotBeNullOrEmpty();
|
||||
|
||||
@ -139,7 +139,7 @@ public void Download_should_get_hash_from_magnet_url(string magnetUrl, string ex
|
||||
var remoteEpisode = CreateRemoteEpisode();
|
||||
remoteEpisode.Release.DownloadUrl = magnetUrl;
|
||||
|
||||
var id = Subject.Download(remoteEpisode);
|
||||
var id = Subject.Download(remoteEpisode, CreateIndexer());
|
||||
|
||||
id.Should().Be(expectedHash);
|
||||
}
|
||||
|
@ -234,7 +234,7 @@ public void Download_should_return_unique_id()
|
||||
|
||||
var remoteEpisode = CreateRemoteEpisode();
|
||||
|
||||
var id = Subject.Download(remoteEpisode);
|
||||
var id = Subject.Download(remoteEpisode, CreateIndexer());
|
||||
|
||||
id.Should().NotBeNullOrEmpty();
|
||||
}
|
||||
@ -259,7 +259,7 @@ public void Download_should_get_hash_from_magnet_url(string magnetUrl, string ex
|
||||
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 @@ public void Download_should_handle_http_redirect_to_magnet()
|
||||
|
||||
var remoteEpisode = CreateRemoteEpisode();
|
||||
|
||||
var id = Subject.Download(remoteEpisode);
|
||||
var id = Subject.Download(remoteEpisode, CreateIndexer());
|
||||
|
||||
id.Should().NotBeNullOrEmpty();
|
||||
}
|
||||
@ -370,7 +370,7 @@ public void Download_should_handle_http_redirect_to_torrent()
|
||||
|
||||
var remoteEpisode = CreateRemoteEpisode();
|
||||
|
||||
var id = Subject.Download(remoteEpisode);
|
||||
var id = Subject.Download(remoteEpisode, CreateIndexer());
|
||||
|
||||
id.Should().NotBeNullOrEmpty();
|
||||
}
|
||||
|
@ -69,7 +69,7 @@ public void Download_should_return_unique_id()
|
||||
|
||||
var remoteEpisode = CreateRemoteEpisode();
|
||||
|
||||
var id = Subject.Download(remoteEpisode);
|
||||
var id = Subject.Download(remoteEpisode, CreateIndexer());
|
||||
|
||||
id.Should().NotBeNullOrEmpty();
|
||||
}
|
||||
@ -82,7 +82,7 @@ public void Download_with_TvDirectory_should_force_directory()
|
||||
|
||||
var remoteEpisode = CreateRemoteEpisode();
|
||||
|
||||
var id = Subject.Download(remoteEpisode);
|
||||
var id = Subject.Download(remoteEpisode, CreateIndexer());
|
||||
|
||||
id.Should().NotBeNullOrEmpty();
|
||||
|
||||
@ -98,7 +98,7 @@ public void Download_with_category_should_force_directory()
|
||||
|
||||
var remoteEpisode = CreateRemoteEpisode();
|
||||
|
||||
var id = Subject.Download(remoteEpisode);
|
||||
var id = Subject.Download(remoteEpisode, CreateIndexer());
|
||||
|
||||
id.Should().NotBeNullOrEmpty();
|
||||
|
||||
@ -116,7 +116,7 @@ public void Download_with_category_should_not_have_double_slashes()
|
||||
|
||||
var remoteEpisode = CreateRemoteEpisode();
|
||||
|
||||
var id = Subject.Download(remoteEpisode);
|
||||
var id = Subject.Download(remoteEpisode, CreateIndexer());
|
||||
|
||||
id.Should().NotBeNullOrEmpty();
|
||||
|
||||
@ -131,7 +131,7 @@ public void Download_without_TvDirectory_and_Category_should_use_default()
|
||||
|
||||
var remoteEpisode = CreateRemoteEpisode();
|
||||
|
||||
var id = Subject.Download(remoteEpisode);
|
||||
var id = Subject.Download(remoteEpisode, CreateIndexer());
|
||||
|
||||
id.Should().NotBeNullOrEmpty();
|
||||
|
||||
@ -147,7 +147,7 @@ public void Download_should_get_hash_from_magnet_url(string magnetUrl, string ex
|
||||
var remoteEpisode = CreateRemoteEpisode();
|
||||
remoteEpisode.Release.DownloadUrl = magnetUrl;
|
||||
|
||||
var id = Subject.Download(remoteEpisode);
|
||||
var id = Subject.Download(remoteEpisode, CreateIndexer());
|
||||
|
||||
id.Should().Be(expectedHash);
|
||||
}
|
||||
|
@ -82,7 +82,7 @@ private Mock<IDownloadClient> WithTorrentClient()
|
||||
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 @@ 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<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 @@ 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<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 @@ 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<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 @@ 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<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 @@ 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<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 @@ 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<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 @@ public void should_not_attempt_download_if_client_isnt_configured()
|
||||
{
|
||||
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 @@ public void should_attempt_download_even_if_client_is_disabled()
|
||||
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 @@ public void should_send_download_to_correct_usenet_client()
|
||||
|
||||
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 @@ public void should_send_download_to_correct_torrent_client()
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ public Pneumatic(IHttpClient httpClient,
|
||||
|
||||
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;
|
||||
|
@ -58,7 +58,7 @@ public abstract DownloadProtocol Protocol
|
||||
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)
|
||||
|
@ -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;
|
||||
@ -68,6 +71,7 @@ private void DownloadReport(RemoteEpisode remoteEpisode, IDownloadClient downloa
|
||||
|
||||
// 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 @@ private void DownloadReport(RemoteEpisode remoteEpisode, IDownloadClient downloa
|
||||
string downloadClientId;
|
||||
try
|
||||
{
|
||||
downloadClientId = downloadClient.Download(remoteEpisode);
|
||||
downloadClientId = downloadClient.Download(remoteEpisode, indexer);
|
||||
_downloadClientStatusService.RecordSuccess(downloadClient.Definition.Id);
|
||||
_indexerStatusService.RecordSuccess(remoteEpisode.Release.IndexerId);
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -41,7 +41,7 @@ protected TorrentClientBase(ITorrentFileInfoReader torrentFileInfoReader,
|
||||
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 @@ public override string Download(RemoteEpisode remoteEpisode)
|
||||
{
|
||||
try
|
||||
{
|
||||
return DownloadFromWebUrl(remoteEpisode, torrentUrl);
|
||||
return DownloadFromWebUrl(remoteEpisode, indexer, torrentUrl);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@ -114,20 +114,20 @@ public override string Download(RemoteEpisode remoteEpisode)
|
||||
|
||||
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 @@ private string DownloadFromWebUrl(RemoteEpisode remoteEpisode, string torrentUrl
|
||||
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.");
|
||||
|
@ -34,7 +34,7 @@ protected UsenetClientBase(IHttpClient httpClient,
|
||||
|
||||
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 @@ public override string Download(RemoteEpisode remoteEpisode)
|
||||
|
||||
try
|
||||
{
|
||||
var request = new HttpRequest(url);
|
||||
var request = indexer.GetDownloadRequest(url);
|
||||
request.RateLimitKey = remoteEpisode?.Release?.IndexerId.ToString();
|
||||
nzbData = _httpClient.Get(request).ResponseData;
|
||||
|
||||
|
@ -12,7 +12,6 @@
|
||||
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 @@ public override IList<ReleaseInfo> Fetch(SpecialEpisodeSearchCriteria searchCrit
|
||||
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;
|
||||
@ -18,5 +19,6 @@ public interface IIndexer : IProvider
|
||||
IList<ReleaseInfo> Fetch(DailySeasonSearchCriteria searchCriteria);
|
||||
IList<ReleaseInfo> Fetch(AnimeEpisodeSearchCriteria searchCriteria);
|
||||
IList<ReleaseInfo> Fetch(SpecialEpisodeSearchCriteria searchCriteria);
|
||||
HttpRequest GetDownloadRequest(string link);
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,7 @@
|
||||
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 @@ public virtual object RequestAction(string action, IDictionary<string, string> q
|
||||
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)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user