From 99f452e29925c767d882fc706bf47199ae3fdfdf Mon Sep 17 00:00:00 2001 From: Taloth Saldono Date: Sat, 26 Sep 2015 10:45:13 +0200 Subject: [PATCH 1/5] New: Added support for newznab indexers using tvdbid for searching. --- src/NzbDrone.Api/Parse/ParseModule.cs | 2 +- .../DownloadDecisionMakerFixture.cs | 14 +- .../DownloadClientFixtureBase.cs | 2 +- .../BroadcastheNetFixture.cs | 1 + .../NewznabTests/NewznabFixture.cs | 5 + .../NewznabRequestGeneratorFixture.cs | 87 ++++++- .../IndexerTests/RarbgTests/RarbgFixture.cs | 1 + .../TitansOfTvTests/TitansOfTvFixture.cs | 1 + .../TorznabTests/TorznabFixture.cs | 8 +- .../TorznabRequestGeneratorFixture.cs | 154 ------------ .../TorznabTests/TorznabSettingFixture.cs | 58 ----- .../NzbDrone.Core.Test.csproj | 2 - .../ParsingServiceTests/GetEpisodesFixture.cs | 20 +- .../ParsingServiceTests/MapFixture.cs | 45 +++- .../DecisionEngine/DownloadDecisionMaker.cs | 4 +- .../TrackedDownloadService.cs | 2 +- src/NzbDrone.Core/History/HistoryService.cs | 1 + .../BroadcastheNet/BroadcastheNetParser.cs | 4 + src/NzbDrone.Core/Indexers/Newznab/Newznab.cs | 47 +++- .../Indexers/Newznab/NewznabCapabilities.cs | 28 +++ .../NewznabCapabilitiesProvider.cs} | 30 +-- .../Newznab/NewznabRequestGenerator.cs | 152 +++++++++--- .../Indexers/Newznab/NewznabRssParser.cs | 14 ++ .../Indexers/Newznab/NewznabSettings.cs | 16 +- .../Indexers/Rarbg/RarbgParser.cs | 14 +- src/NzbDrone.Core/Indexers/Torznab/Torznab.cs | 15 +- .../Indexers/Torznab/TorznabCapabilities.cs | 28 --- .../Indexers/Torznab/TorznabException.cs | 3 +- .../Torznab/TorznabRequestGenerator.cs | 228 ------------------ .../Indexers/Torznab/TorznabRssParser.cs | 38 ++- .../Indexers/Torznab/TorznabSettings.cs | 48 ++-- src/NzbDrone.Core/NzbDrone.Core.csproj | 5 +- src/NzbDrone.Core/Parser/Model/ReleaseInfo.cs | 2 + src/NzbDrone.Core/Parser/ParsingService.cs | 52 ++-- 34 files changed, 489 insertions(+), 642 deletions(-) delete mode 100644 src/NzbDrone.Core.Test/IndexerTests/TorznabTests/TorznabRequestGeneratorFixture.cs delete mode 100644 src/NzbDrone.Core.Test/IndexerTests/TorznabTests/TorznabSettingFixture.cs create mode 100644 src/NzbDrone.Core/Indexers/Newznab/NewznabCapabilities.cs rename src/NzbDrone.Core/Indexers/{Torznab/TorznabCapabilitiesProvider.cs => Newznab/NewznabCapabilitiesProvider.cs} (81%) delete mode 100644 src/NzbDrone.Core/Indexers/Torznab/TorznabCapabilities.cs delete mode 100644 src/NzbDrone.Core/Indexers/Torznab/TorznabRequestGenerator.cs diff --git a/src/NzbDrone.Api/Parse/ParseModule.cs b/src/NzbDrone.Api/Parse/ParseModule.cs index 462839cfd..6be81934c 100644 --- a/src/NzbDrone.Api/Parse/ParseModule.cs +++ b/src/NzbDrone.Api/Parse/ParseModule.cs @@ -24,7 +24,7 @@ namespace NzbDrone.Api.Parse return null; } - var remoteEpisode = _parsingService.Map(parsedEpisodeInfo); + var remoteEpisode = _parsingService.Map(parsedEpisodeInfo, 0, 0); if (remoteEpisode == null) { diff --git a/src/NzbDrone.Core.Test/DecisionEngineTests/DownloadDecisionMakerFixture.cs b/src/NzbDrone.Core.Test/DecisionEngineTests/DownloadDecisionMakerFixture.cs index f3a7fb7e4..cb4d2a97d 100644 --- a/src/NzbDrone.Core.Test/DecisionEngineTests/DownloadDecisionMakerFixture.cs +++ b/src/NzbDrone.Core.Test/DecisionEngineTests/DownloadDecisionMakerFixture.cs @@ -54,7 +54,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests }; Mocker.GetMock() - .Setup(c => c.Map(It.IsAny(), It.IsAny(), It.IsAny())) + .Setup(c => c.Map(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) .Returns(_remoteEpisode); } @@ -125,7 +125,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests var results = Subject.GetRssDecision(_reports).ToList(); - Mocker.GetMock().Verify(c => c.Map(It.IsAny(), It.IsAny(), It.IsAny()), Times.Never()); + Mocker.GetMock().Verify(c => c.Map(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny()), Times.Never()); _pass1.Verify(c => c.IsSatisfiedBy(It.IsAny(), null), Times.Never()); _pass2.Verify(c => c.IsSatisfiedBy(It.IsAny(), null), Times.Never()); @@ -142,7 +142,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests var results = Subject.GetRssDecision(_reports).ToList(); - Mocker.GetMock().Verify(c => c.Map(It.IsAny(), It.IsAny(), It.IsAny()), Times.Never()); + Mocker.GetMock().Verify(c => c.Map(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny()), Times.Never()); _pass1.Verify(c => c.IsSatisfiedBy(It.IsAny(), null), Times.Never()); _pass2.Verify(c => c.IsSatisfiedBy(It.IsAny(), null), Times.Never()); @@ -170,7 +170,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests { GivenSpecifications(_pass1); - Mocker.GetMock().Setup(c => c.Map(It.IsAny(), It.IsAny(), It.IsAny())) + Mocker.GetMock().Setup(c => c.Map(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) .Throws(); _reports = new List @@ -182,7 +182,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests Subject.GetRssDecision(_reports); - Mocker.GetMock().Verify(c => c.Map(It.IsAny(), It.IsAny(), It.IsAny()), Times.Exactly(_reports.Count)); + Mocker.GetMock().Verify(c => c.Map(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny()), Times.Exactly(_reports.Count)); ExceptionVerification.ExpectedErrors(3); } @@ -221,8 +221,8 @@ namespace NzbDrone.Core.Test.DecisionEngineTests }).ToList(); Mocker.GetMock() - .Setup(v => v.Map(It.IsAny(), It.IsAny(), It.IsAny())) - .Returns((p,id,c) => + .Setup(v => v.Map(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) + .Returns((p,tvdbid,tvrageid,c) => new RemoteEpisode { DownloadAllowed = true, diff --git a/src/NzbDrone.Core.Test/Download/DownloadClientTests/DownloadClientFixtureBase.cs b/src/NzbDrone.Core.Test/Download/DownloadClientTests/DownloadClientFixtureBase.cs index de696feda..c0eacf7bc 100644 --- a/src/NzbDrone.Core.Test/Download/DownloadClientTests/DownloadClientFixtureBase.cs +++ b/src/NzbDrone.Core.Test/Download/DownloadClientTests/DownloadClientFixtureBase.cs @@ -30,7 +30,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests .Returns(30); Mocker.GetMock() - .Setup(s => s.Map(It.IsAny(), It.IsAny(), (SearchCriteriaBase)null)) + .Setup(s => s.Map(It.IsAny(), It.IsAny(), It.IsAny(), (SearchCriteriaBase)null)) .Returns(() => CreateRemoteEpisode()); Mocker.GetMock() diff --git a/src/NzbDrone.Core.Test/IndexerTests/BroadcastheNetTests/BroadcastheNetFixture.cs b/src/NzbDrone.Core.Test/IndexerTests/BroadcastheNetTests/BroadcastheNetFixture.cs index fb35e1987..0945eef82 100644 --- a/src/NzbDrone.Core.Test/IndexerTests/BroadcastheNetTests/BroadcastheNetFixture.cs +++ b/src/NzbDrone.Core.Test/IndexerTests/BroadcastheNetTests/BroadcastheNetFixture.cs @@ -51,6 +51,7 @@ namespace NzbDrone.Core.Test.IndexerTests.BroadcastheNetTests torrentInfo.PublishDate.Should().Be(DateTime.Parse("2014/09/16 21:15:33")); torrentInfo.Size.Should().Be(505099926); torrentInfo.InfoHash.Should().Be("123"); + torrentInfo.TvdbId.Should().Be(71998); torrentInfo.TvRageId.Should().Be(4055); torrentInfo.MagnetUrl.Should().BeNullOrEmpty(); torrentInfo.Peers.Should().Be(40+9); diff --git a/src/NzbDrone.Core.Test/IndexerTests/NewznabTests/NewznabFixture.cs b/src/NzbDrone.Core.Test/IndexerTests/NewznabTests/NewznabFixture.cs index dd675bd12..899015030 100644 --- a/src/NzbDrone.Core.Test/IndexerTests/NewznabTests/NewznabFixture.cs +++ b/src/NzbDrone.Core.Test/IndexerTests/NewznabTests/NewznabFixture.cs @@ -6,6 +6,7 @@ using NUnit.Framework; using NzbDrone.Common.Http; using NzbDrone.Core.Indexers; using NzbDrone.Core.Indexers.Newznab; +using NzbDrone.Core.Parser.Model; using NzbDrone.Core.Test.Framework; namespace NzbDrone.Core.Test.IndexerTests.NewznabTests @@ -26,6 +27,10 @@ namespace NzbDrone.Core.Test.IndexerTests.NewznabTests Categories = new int[] { 1 } } }; + + Mocker.GetMock() + .Setup(v => v.GetCapabilities(It.IsAny())) + .Returns(new NewznabCapabilities()); } [Test] diff --git a/src/NzbDrone.Core.Test/IndexerTests/NewznabTests/NewznabRequestGeneratorFixture.cs b/src/NzbDrone.Core.Test/IndexerTests/NewznabTests/NewznabRequestGeneratorFixture.cs index 1bc95a2a7..66cc059b3 100644 --- a/src/NzbDrone.Core.Test/IndexerTests/NewznabTests/NewznabRequestGeneratorFixture.cs +++ b/src/NzbDrone.Core.Test/IndexerTests/NewznabTests/NewznabRequestGeneratorFixture.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using FluentAssertions; +using Moq; using NUnit.Framework; using NzbDrone.Core.Indexers.Newznab; using NzbDrone.Core.IndexerSearch.Definitions; @@ -11,7 +12,9 @@ namespace NzbDrone.Core.Test.IndexerTests.NewznabTests { public class NewznabRequestGeneratorFixture : CoreTest { - AnimeEpisodeSearchCriteria _animeSearchCriteria; + private SingleEpisodeSearchCriteria _singleEpisodeSearchCriteria; + private AnimeEpisodeSearchCriteria _animeSearchCriteria; + private NewznabCapabilities _capabilities; [SetUp] public void SetUp() @@ -24,11 +27,25 @@ namespace NzbDrone.Core.Test.IndexerTests.NewznabTests ApiKey = "abcd", }; + _singleEpisodeSearchCriteria = new SingleEpisodeSearchCriteria + { + Series = new Tv.Series { TvRageId = 10, TvdbId = 20 }, + SceneTitles = new List { "Monkey Island" }, + SeasonNumber = 1, + EpisodeNumber = 2 + }; + _animeSearchCriteria = new AnimeEpisodeSearchCriteria() { SceneTitles = new List() { "Monkey+Island" }, AbsoluteEpisodeNumber = 100 }; + + _capabilities = new NewznabCapabilities(); + + Mocker.GetMock() + .Setup(v => v.GetCapabilities(It.IsAny())) + .Returns(_capabilities); } [Test] @@ -106,5 +123,73 @@ namespace NzbDrone.Core.Test.IndexerTests.NewznabTests pages.Count.Should().BeLessThan(500); } + + [Test] + public void should_not_search_by_rid_if_not_supported() + { + _capabilities.SupportedTvSearchParameters = new[] { "q", "season", "ep" }; + + var results = Subject.GetSearchRequests(_singleEpisodeSearchCriteria); + + results.Should().HaveCount(1); + + var page = results.First().First(); + + page.Url.Query.Should().NotContain("rid=10"); + page.Url.Query.Should().Contain("q=Monkey"); + } + + [Test] + public void should_search_by_rid_if_supported() + { + var results = Subject.GetSearchRequests(_singleEpisodeSearchCriteria); + results.Should().HaveCount(1); + + var page = results.First().First(); + + page.Url.Query.Should().Contain("rid=10"); + } + + [Test] + public void should_not_search_by_tvdbid_if_not_supported() + { + _capabilities.SupportedTvSearchParameters = new[] { "q", "season", "ep" }; + + var results = Subject.GetSearchRequests(_singleEpisodeSearchCriteria); + + results.Should().HaveCount(1); + + var page = results.First().First(); + + page.Url.Query.Should().NotContain("rid=10"); + page.Url.Query.Should().Contain("q=Monkey"); + } + + [Test] + public void should_search_by_tvdbid_if_supported() + { + _capabilities.SupportedTvSearchParameters = new[] { "q", "tvdbid", "season", "ep" }; + + var results = Subject.GetSearchRequests(_singleEpisodeSearchCriteria); + results.Should().HaveCount(1); + + var page = results.First().First(); + + page.Url.Query.Should().Contain("tvdbid=20"); + } + + [Test] + public void should_prefer_search_by_tvdbid_if_rid_supported() + { + _capabilities.SupportedTvSearchParameters = new[] { "q", "tvdbid", "rid", "season", "ep" }; + + var results = Subject.GetSearchRequests(_singleEpisodeSearchCriteria); + results.Should().HaveCount(1); + + var page = results.First().First(); + + page.Url.Query.Should().Contain("tvdbid=20"); + page.Url.Query.Should().NotContain("rid=10"); + } } } diff --git a/src/NzbDrone.Core.Test/IndexerTests/RarbgTests/RarbgFixture.cs b/src/NzbDrone.Core.Test/IndexerTests/RarbgTests/RarbgFixture.cs index 441133d6c..7f442fcb2 100644 --- a/src/NzbDrone.Core.Test/IndexerTests/RarbgTests/RarbgFixture.cs +++ b/src/NzbDrone.Core.Test/IndexerTests/RarbgTests/RarbgFixture.cs @@ -56,6 +56,7 @@ namespace NzbDrone.Core.Test.IndexerTests.RarbgTests torrentInfo.MagnetUrl.Should().BeNull(); torrentInfo.Peers.Should().Be(304 + 200); torrentInfo.Seeders.Should().Be(304); + torrentInfo.TvdbId.Should().Be(268156); torrentInfo.TvRageId.Should().Be(35197); } diff --git a/src/NzbDrone.Core.Test/IndexerTests/TitansOfTvTests/TitansOfTvFixture.cs b/src/NzbDrone.Core.Test/IndexerTests/TitansOfTvTests/TitansOfTvFixture.cs index 15ae31b8c..4847b1efe 100644 --- a/src/NzbDrone.Core.Test/IndexerTests/TitansOfTvTests/TitansOfTvFixture.cs +++ b/src/NzbDrone.Core.Test/IndexerTests/TitansOfTvTests/TitansOfTvFixture.cs @@ -51,6 +51,7 @@ namespace NzbDrone.Core.Test.IndexerTests.TitansOfTvTests torrentInfo.PublishDate.Should().Be(DateTime.Parse("2015-06-25 04:13:44")); torrentInfo.Size.Should().Be(435402993); torrentInfo.InfoHash.Should().BeNullOrEmpty(); + torrentInfo.TvdbId.Should().Be(0); torrentInfo.TvRageId.Should().Be(0); torrentInfo.MagnetUrl.Should().BeNullOrEmpty(); torrentInfo.Peers.Should().Be(2+5); diff --git a/src/NzbDrone.Core.Test/IndexerTests/TorznabTests/TorznabFixture.cs b/src/NzbDrone.Core.Test/IndexerTests/TorznabTests/TorznabFixture.cs index 6fd8d5588..be48f1ecf 100644 --- a/src/NzbDrone.Core.Test/IndexerTests/TorznabTests/TorznabFixture.cs +++ b/src/NzbDrone.Core.Test/IndexerTests/TorznabTests/TorznabFixture.cs @@ -5,6 +5,7 @@ using Moq; using NUnit.Framework; using NzbDrone.Common.Http; using NzbDrone.Core.Indexers; +using NzbDrone.Core.Indexers.Newznab; using NzbDrone.Core.Indexers.Torznab; using NzbDrone.Core.Parser.Model; using NzbDrone.Core.Test.Framework; @@ -27,9 +28,9 @@ namespace NzbDrone.Core.Test.IndexerTests.TorznabTests } }; - Mocker.GetMock() - .Setup(v => v.GetCapabilities(It.IsAny())) - .Returns(new TorznabCapabilities()); + Mocker.GetMock() + .Setup(v => v.GetCapabilities(It.IsAny())) + .Returns(new NewznabCapabilities()); } [Test] @@ -56,6 +57,7 @@ namespace NzbDrone.Core.Test.IndexerTests.TorznabTests releaseInfo.Indexer.Should().Be(Subject.Definition.Name); releaseInfo.PublishDate.Should().Be(DateTime.Parse("2015/03/14 21:10:42")); releaseInfo.Size.Should().Be(2538463390); + releaseInfo.TvdbId.Should().Be(273181); releaseInfo.TvRageId.Should().Be(37780); releaseInfo.InfoHash.Should().Be("63e07ff523710ca268567dad344ce1e0e6b7e8a3"); releaseInfo.Seeders.Should().Be(7); diff --git a/src/NzbDrone.Core.Test/IndexerTests/TorznabTests/TorznabRequestGeneratorFixture.cs b/src/NzbDrone.Core.Test/IndexerTests/TorznabTests/TorznabRequestGeneratorFixture.cs deleted file mode 100644 index ff33ba6d8..000000000 --- a/src/NzbDrone.Core.Test/IndexerTests/TorznabTests/TorznabRequestGeneratorFixture.cs +++ /dev/null @@ -1,154 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using FluentAssertions; -using Moq; -using NUnit.Framework; -using NzbDrone.Core.Indexers.Torznab; -using NzbDrone.Core.IndexerSearch.Definitions; -using NzbDrone.Core.Test.Framework; - -namespace NzbDrone.Core.Test.IndexerTests.TorznabTests -{ - public class TorznabRequestGeneratorFixture : CoreTest - { - private SingleEpisodeSearchCriteria _singleEpisodeSearchCriteria; - private AnimeEpisodeSearchCriteria _animeSearchCriteria; - private TorznabCapabilities _capabilities; - - [SetUp] - public void SetUp() - { - Subject.Settings = new TorznabSettings() - { - Url = "http://127.0.0.1:1234/", - Categories = new [] { 1, 2 }, - AnimeCategories = new [] { 3, 4 }, - ApiKey = "abcd", - EnableRageIDLookup = true - }; - - _singleEpisodeSearchCriteria = new SingleEpisodeSearchCriteria - { - Series = new Tv.Series { TvRageId = 10 }, - SceneTitles = new List { "Monkey Island" }, - SeasonNumber = 1, - EpisodeNumber = 2 - }; - - _animeSearchCriteria = new AnimeEpisodeSearchCriteria() - { - SceneTitles = new List() { "Monkey+Island" }, - AbsoluteEpisodeNumber = 100 - }; - - _capabilities = new TorznabCapabilities(); - - Mocker.GetMock() - .Setup(v => v.GetCapabilities(It.IsAny())) - .Returns(_capabilities); - } - - [Test] - public void should_use_all_categories_for_feed() - { - var results = Subject.GetRecentRequests(); - - results.Should().HaveCount(1); - - var page = results.First().First(); - - page.Url.Query.Should().Contain("&cat=1,2,3,4&"); - } - - [Test] - public void should_not_have_duplicate_categories() - { - Subject.Settings.Categories = new[] { 1, 2, 3 }; - - var results = Subject.GetRecentRequests(); - - results.Should().HaveCount(1); - - var page = results.First().First(); - - page.Url.Query.Should().Contain("&cat=1,2,3,4&"); - } - - [Test] - public void should_use_only_anime_categories_for_anime_search() - { - var results = Subject.GetSearchRequests(_animeSearchCriteria); - - results.Should().HaveCount(1); - - var page = results.First().First(); - - page.Url.Query.Should().Contain("&cat=3,4&"); - } - - [Test] - public void should_use_mode_search_for_anime() - { - var results = Subject.GetSearchRequests(_animeSearchCriteria); - - results.Should().HaveCount(1); - - var page = results.First().First(); - - page.Url.Query.Should().Contain("?t=search&"); - } - - [Test] - public void should_return_subsequent_pages() - { - var results = Subject.GetSearchRequests(_animeSearchCriteria); - - results.Should().HaveCount(1); - - var pages = results.First().Take(3).ToList(); - - pages[0].Url.Query.Should().Contain("&offset=0&"); - pages[1].Url.Query.Should().Contain("&offset=100&"); - pages[2].Url.Query.Should().Contain("&offset=200&"); - } - - [Test] - public void should_not_get_unlimited_pages() - { - var results = Subject.GetSearchRequests(_animeSearchCriteria); - - results.Should().HaveCount(1); - - var pages = results.First().Take(500).ToList(); - - pages.Count.Should().BeLessThan(500); - } - - [Test] - public void should_not_search_by_rid_if_not_supported() - { - _capabilities.SupportedTvSearchParameters = new[] { "q", "season", "ep" }; - - var results = Subject.GetSearchRequests(_singleEpisodeSearchCriteria); - - results.Should().HaveCount(1); - - var page = results.First().First(); - - page.Url.Query.Should().NotContain("rid=10"); - page.Url.Query.Should().Contain("q=Monkey"); - } - - [Test] - public void should_search_by_rid_if_supported() - { - var results = Subject.GetSearchRequests(_singleEpisodeSearchCriteria); - results.Should().HaveCount(1); - - var page = results.First().First(); - - page.Url.Query.Should().Contain("rid=10"); - } - } -} diff --git a/src/NzbDrone.Core.Test/IndexerTests/TorznabTests/TorznabSettingFixture.cs b/src/NzbDrone.Core.Test/IndexerTests/TorznabTests/TorznabSettingFixture.cs deleted file mode 100644 index 2fc06ba66..000000000 --- a/src/NzbDrone.Core.Test/IndexerTests/TorznabTests/TorznabSettingFixture.cs +++ /dev/null @@ -1,58 +0,0 @@ -using FluentAssertions; -using NUnit.Framework; -using NzbDrone.Core.Indexers.Torznab; -using NzbDrone.Core.Test.Framework; - -namespace NzbDrone.Core.Test.IndexerTests.TorznabTests -{ - public class TorznabSettingFixture : CoreTest - { - - [TestCase("http://hdaccess.net")] - public void requires_apikey(string url) - { - var setting = new TorznabSettings() - { - ApiKey = "", - Url = url - }; - - - setting.Validate().IsValid.Should().BeFalse(); - setting.Validate().Errors.Should().Contain(c => c.PropertyName == "ApiKey"); - - } - - [TestCase("")] - [TestCase(" ")] - [TestCase(null)] - public void invalid_url_should_not_apikey(string url) - { - var setting = new TorznabSettings - { - ApiKey = "", - Url = url - }; - - - setting.Validate().IsValid.Should().BeFalse(); - setting.Validate().Errors.Should().NotContain(c => c.PropertyName == "ApiKey"); - setting.Validate().Errors.Should().Contain(c => c.PropertyName == "Url"); - - } - - - [TestCase("http://myfancytracker.net")] - public void doesnt_requires_apikey(string url) - { - var setting = new TorznabSettings() - { - ApiKey = "", - Url = url - }; - - - setting.Validate().IsValid.Should().BeTrue(); - } - } -} \ No newline at end of file diff --git a/src/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj b/src/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj index 59ab1b43c..28fab06e6 100644 --- a/src/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj +++ b/src/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj @@ -226,8 +226,6 @@ - - diff --git a/src/NzbDrone.Core.Test/ParserTests/ParsingServiceTests/GetEpisodesFixture.cs b/src/NzbDrone.Core.Test/ParserTests/ParsingServiceTests/GetEpisodesFixture.cs index 898f70cb7..1c473a396 100644 --- a/src/NzbDrone.Core.Test/ParserTests/ParsingServiceTests/GetEpisodesFixture.cs +++ b/src/NzbDrone.Core.Test/ParserTests/ParsingServiceTests/GetEpisodesFixture.cs @@ -82,7 +82,7 @@ namespace NzbDrone.Core.Test.ParserTests.ParsingServiceTests GivenDailySeries(); GivenDailyParseResult(); - Subject.Map(_parsedEpisodeInfo, _series.TvRageId); + Subject.Map(_parsedEpisodeInfo, _series.TvdbId, _series.TvRageId); Mocker.GetMock() .Verify(v => v.FindEpisode(It.IsAny(), It.IsAny()), Times.Once()); @@ -94,7 +94,7 @@ namespace NzbDrone.Core.Test.ParserTests.ParsingServiceTests GivenDailySeries(); GivenDailyParseResult(); - Subject.Map(_parsedEpisodeInfo, _series.TvRageId, _singleEpisodeSearchCriteria); + Subject.Map(_parsedEpisodeInfo, _series.TvdbId, _series.TvRageId, _singleEpisodeSearchCriteria); Mocker.GetMock() .Verify(v => v.FindEpisode(It.IsAny(), It.IsAny()), Times.Never()); @@ -106,7 +106,7 @@ namespace NzbDrone.Core.Test.ParserTests.ParsingServiceTests GivenDailySeries(); _parsedEpisodeInfo.AirDate = DateTime.Today.AddDays(-5).ToString(Episode.AIR_DATE_FORMAT); ; - Subject.Map(_parsedEpisodeInfo, _series.TvRageId, _singleEpisodeSearchCriteria); + Subject.Map(_parsedEpisodeInfo, _series.TvdbId, _series.TvRageId, _singleEpisodeSearchCriteria); Mocker.GetMock() .Verify(v => v.FindEpisode(It.IsAny(), It.IsAny()), Times.Once()); @@ -117,7 +117,7 @@ namespace NzbDrone.Core.Test.ParserTests.ParsingServiceTests { GivenAbsoluteNumberingSeries(); - Subject.Map(_parsedEpisodeInfo, _series.TvRageId, _singleEpisodeSearchCriteria); + Subject.Map(_parsedEpisodeInfo, _series.TvdbId, _series.TvRageId, _singleEpisodeSearchCriteria); Mocker.GetMock() .Verify(v => v.FindEpisode(It.IsAny(), It.IsAny()), Times.Never()); @@ -128,7 +128,7 @@ namespace NzbDrone.Core.Test.ParserTests.ParsingServiceTests { GivenSceneNumberingSeries(); - Subject.Map(_parsedEpisodeInfo, _series.TvRageId); + Subject.Map(_parsedEpisodeInfo, _series.TvdbId, _series.TvRageId); Mocker.GetMock() .Verify(v => v.FindEpisodesBySceneNumbering(It.IsAny(), It.IsAny(), It.IsAny()), Times.Once()); @@ -139,7 +139,7 @@ namespace NzbDrone.Core.Test.ParserTests.ParsingServiceTests { GivenSceneNumberingSeries(); - Subject.Map(_parsedEpisodeInfo, _series.TvRageId, _singleEpisodeSearchCriteria); + Subject.Map(_parsedEpisodeInfo, _series.TvdbId, _series.TvRageId, _singleEpisodeSearchCriteria); Mocker.GetMock() .Verify(v => v.FindEpisodesBySceneNumbering(It.IsAny(), It.IsAny(), It.IsAny()), Times.Never()); @@ -151,7 +151,7 @@ namespace NzbDrone.Core.Test.ParserTests.ParsingServiceTests GivenSceneNumberingSeries(); _episodes.First().SceneEpisodeNumber = 10; - Subject.Map(_parsedEpisodeInfo, _series.TvRageId, _singleEpisodeSearchCriteria); + Subject.Map(_parsedEpisodeInfo, _series.TvdbId, _series.TvRageId, _singleEpisodeSearchCriteria); Mocker.GetMock() .Verify(v => v.FindEpisodesBySceneNumbering(It.IsAny(), It.IsAny(), It.IsAny()), Times.Once()); @@ -160,7 +160,7 @@ namespace NzbDrone.Core.Test.ParserTests.ParsingServiceTests [Test] public void should_find_episode() { - Subject.Map(_parsedEpisodeInfo, _series.TvRageId); + Subject.Map(_parsedEpisodeInfo, _series.TvdbId, _series.TvRageId); Mocker.GetMock() .Verify(v => v.FindEpisode(It.IsAny(), It.IsAny(), It.IsAny()), Times.Once()); @@ -169,7 +169,7 @@ namespace NzbDrone.Core.Test.ParserTests.ParsingServiceTests [Test] public void should_match_episode_with_search_criteria() { - Subject.Map(_parsedEpisodeInfo, _series.TvRageId, _singleEpisodeSearchCriteria); + Subject.Map(_parsedEpisodeInfo, _series.TvdbId, _series.TvRageId, _singleEpisodeSearchCriteria); Mocker.GetMock() .Verify(v => v.FindEpisode(It.IsAny(), It.IsAny(), It.IsAny()), Times.Never()); @@ -180,7 +180,7 @@ namespace NzbDrone.Core.Test.ParserTests.ParsingServiceTests { _episodes.First().EpisodeNumber = 10; - Subject.Map(_parsedEpisodeInfo, _series.TvRageId, _singleEpisodeSearchCriteria); + Subject.Map(_parsedEpisodeInfo, _series.TvdbId, _series.TvRageId, _singleEpisodeSearchCriteria); Mocker.GetMock() .Verify(v => v.FindEpisode(It.IsAny(), It.IsAny(), It.IsAny()), Times.Once()); diff --git a/src/NzbDrone.Core.Test/ParserTests/ParsingServiceTests/MapFixture.cs b/src/NzbDrone.Core.Test/ParserTests/ParsingServiceTests/MapFixture.cs index c237f5d46..2357472ce 100644 --- a/src/NzbDrone.Core.Test/ParserTests/ParsingServiceTests/MapFixture.cs +++ b/src/NzbDrone.Core.Test/ParserTests/ParsingServiceTests/MapFixture.cs @@ -59,6 +59,13 @@ namespace NzbDrone.Core.Test.ParserTests.ParsingServiceTests .Returns(_series); } + private void GivenMatchByTvdbId() + { + Mocker.GetMock() + .Setup(s => s.FindByTvdbId(It.IsAny())) + .Returns(_series); + } + private void GivenMatchByTvRageId() { Mocker.GetMock() @@ -76,18 +83,29 @@ namespace NzbDrone.Core.Test.ParserTests.ParsingServiceTests { GivenMatchBySeriesTitle(); - Subject.Map(_parsedEpisodeInfo, _series.TvRageId); + Subject.Map(_parsedEpisodeInfo, _series.TvdbId, _series.TvRageId); Mocker.GetMock() .Verify(v => v.FindByTitle(It.IsAny()), Times.Once()); } + [Test] + public void should_use_tvdbid_when_series_title_lookup_fails() + { + GivenMatchByTvdbId(); + + Subject.Map(_parsedEpisodeInfo, _series.TvdbId, _series.TvRageId); + + Mocker.GetMock() + .Verify(v => v.FindByTvdbId(It.IsAny()), Times.Once()); + } + [Test] public void should_use_tvrageid_when_series_title_lookup_fails() { GivenMatchByTvRageId(); - Subject.Map(_parsedEpisodeInfo, _series.TvRageId); + Subject.Map(_parsedEpisodeInfo, 0, _series.TvRageId); Mocker.GetMock() .Verify(v => v.FindByTvRageId(It.IsAny()), Times.Once()); @@ -102,7 +120,7 @@ namespace NzbDrone.Core.Test.ParserTests.ParsingServiceTests .Setup(v => v.FindTvdbId(It.IsAny())) .Returns(10); - var result = Subject.Map(_parsedEpisodeInfo, _series.TvRageId); + var result = Subject.Map(_parsedEpisodeInfo, _series.TvdbId, _series.TvRageId); Mocker.GetMock() .Verify(v => v.FindByTvRageId(It.IsAny()), Times.Never()); @@ -115,7 +133,7 @@ namespace NzbDrone.Core.Test.ParserTests.ParsingServiceTests { GivenMatchBySeriesTitle(); - Subject.Map(_parsedEpisodeInfo, _series.TvRageId, _singleEpisodeSearchCriteria); + Subject.Map(_parsedEpisodeInfo, _series.TvdbId, _series.TvRageId, _singleEpisodeSearchCriteria); Mocker.GetMock() .Verify(v => v.FindByTitle(It.IsAny()), Times.Never()); @@ -126,18 +144,29 @@ namespace NzbDrone.Core.Test.ParserTests.ParsingServiceTests { GivenParseResultSeriesDoesntMatchSearchCriteria(); - Subject.Map(_parsedEpisodeInfo, 10, _singleEpisodeSearchCriteria); + Subject.Map(_parsedEpisodeInfo, 10, 10, _singleEpisodeSearchCriteria); Mocker.GetMock() .Verify(v => v.FindByTitle(It.IsAny()), Times.Once()); } + [Test] + public void should_FindByTvdbId_when_search_criteria_and_FindByTitle_matching_fails() + { + GivenParseResultSeriesDoesntMatchSearchCriteria(); + + Subject.Map(_parsedEpisodeInfo, 10, 10, _singleEpisodeSearchCriteria); + + Mocker.GetMock() + .Verify(v => v.FindByTvdbId(It.IsAny()), Times.Once()); + } + [Test] public void should_FindByTvRageId_when_search_criteria_and_FindByTitle_matching_fails() { GivenParseResultSeriesDoesntMatchSearchCriteria(); - Subject.Map(_parsedEpisodeInfo, 10, _singleEpisodeSearchCriteria); + Subject.Map(_parsedEpisodeInfo, 10, 10, _singleEpisodeSearchCriteria); Mocker.GetMock() .Verify(v => v.FindByTvRageId(It.IsAny()), Times.Once()); @@ -150,7 +179,7 @@ namespace NzbDrone.Core.Test.ParserTests.ParsingServiceTests .Setup(s => s.FindTvdbId(It.IsAny())) .Returns(_series.TvdbId); - Subject.Map(_parsedEpisodeInfo, _series.TvRageId, _singleEpisodeSearchCriteria); + Subject.Map(_parsedEpisodeInfo, _series.TvdbId, _series.TvRageId, _singleEpisodeSearchCriteria); Mocker.GetMock() .Verify(v => v.FindByTitle(It.IsAny()), Times.Never()); @@ -161,7 +190,7 @@ namespace NzbDrone.Core.Test.ParserTests.ParsingServiceTests { GivenParseResultSeriesDoesntMatchSearchCriteria(); - Subject.Map(_parsedEpisodeInfo, _series.TvRageId, _singleEpisodeSearchCriteria); + Subject.Map(_parsedEpisodeInfo, _series.TvdbId, _series.TvRageId, _singleEpisodeSearchCriteria); Mocker.GetMock() .Verify(v => v.FindByTitle(It.IsAny()), Times.Never()); diff --git a/src/NzbDrone.Core/DecisionEngine/DownloadDecisionMaker.cs b/src/NzbDrone.Core/DecisionEngine/DownloadDecisionMaker.cs index 566380e6c..39adf6d87 100644 --- a/src/NzbDrone.Core/DecisionEngine/DownloadDecisionMaker.cs +++ b/src/NzbDrone.Core/DecisionEngine/DownloadDecisionMaker.cs @@ -65,7 +65,7 @@ namespace NzbDrone.Core.DecisionEngine if (parsedEpisodeInfo == null || parsedEpisodeInfo.IsPossibleSpecialEpisode) { - var specialEpisodeInfo = _parsingService.ParseSpecialEpisodeTitle(report.Title, report.TvRageId, searchCriteria); + var specialEpisodeInfo = _parsingService.ParseSpecialEpisodeTitle(report.Title, report.TvdbId, report.TvRageId, searchCriteria); if (specialEpisodeInfo != null) { @@ -75,7 +75,7 @@ namespace NzbDrone.Core.DecisionEngine if (parsedEpisodeInfo != null && !parsedEpisodeInfo.SeriesTitle.IsNullOrWhiteSpace()) { - var remoteEpisode = _parsingService.Map(parsedEpisodeInfo, report.TvRageId, searchCriteria); + var remoteEpisode = _parsingService.Map(parsedEpisodeInfo, report.TvdbId, report.TvRageId, searchCriteria); remoteEpisode.Release = report; if (remoteEpisode.Series != null) diff --git a/src/NzbDrone.Core/Download/TrackedDownloads/TrackedDownloadService.cs b/src/NzbDrone.Core/Download/TrackedDownloads/TrackedDownloadService.cs index 9375f2f6c..00bad1ab8 100644 --- a/src/NzbDrone.Core/Download/TrackedDownloads/TrackedDownloadService.cs +++ b/src/NzbDrone.Core/Download/TrackedDownloads/TrackedDownloadService.cs @@ -62,7 +62,7 @@ namespace NzbDrone.Core.Download.TrackedDownloads if (parsedEpisodeInfo != null) { - trackedDownload.RemoteEpisode = _parsingService.Map(parsedEpisodeInfo); + trackedDownload.RemoteEpisode = _parsingService.Map(parsedEpisodeInfo, 0, 0); } if (historyItems.Any()) diff --git a/src/NzbDrone.Core/History/HistoryService.cs b/src/NzbDrone.Core/History/HistoryService.cs index 4fee5e753..1db2e7778 100644 --- a/src/NzbDrone.Core/History/HistoryService.cs +++ b/src/NzbDrone.Core/History/HistoryService.cs @@ -151,6 +151,7 @@ namespace NzbDrone.Core.History history.Data.Add("Size", message.Episode.Release.Size.ToString()); history.Data.Add("DownloadUrl", message.Episode.Release.DownloadUrl); history.Data.Add("Guid", message.Episode.Release.Guid); + history.Data.Add("TvdbId", message.Episode.Release.TvdbId.ToString()); history.Data.Add("TvRageId", message.Episode.Release.TvRageId.ToString()); history.Data.Add("Protocol", ((int)message.Episode.Release.DownloadProtocol).ToString()); diff --git a/src/NzbDrone.Core/Indexers/BroadcastheNet/BroadcastheNetParser.cs b/src/NzbDrone.Core/Indexers/BroadcastheNet/BroadcastheNetParser.cs index 8379869b8..3b8d6fe44 100644 --- a/src/NzbDrone.Core/Indexers/BroadcastheNet/BroadcastheNetParser.cs +++ b/src/NzbDrone.Core/Indexers/BroadcastheNet/BroadcastheNetParser.cs @@ -56,6 +56,10 @@ namespace NzbDrone.Core.Indexers.BroadcastheNet torrentInfo.DownloadUrl = RegexProtocol.Replace(torrent.DownloadURL, protocol); torrentInfo.InfoUrl = string.Format("{0}//broadcasthe.net/torrents.php?id={1}&torrentid={2}", protocol, torrent.GroupID, torrent.TorrentID); //torrentInfo.CommentUrl = + if (torrent.TvdbID.HasValue) + { + torrentInfo.TvdbId = torrent.TvdbID.Value; + } if (torrent.TvrageID.HasValue) { torrentInfo.TvRageId = torrent.TvrageID.Value; diff --git a/src/NzbDrone.Core/Indexers/Newznab/Newznab.cs b/src/NzbDrone.Core/Indexers/Newznab/Newznab.cs index 82d83ecb6..ff18d65dc 100644 --- a/src/NzbDrone.Core/Indexers/Newznab/Newznab.cs +++ b/src/NzbDrone.Core/Indexers/Newznab/Newznab.cs @@ -1,7 +1,9 @@ using System; 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.Parser; @@ -11,6 +13,8 @@ namespace NzbDrone.Core.Indexers.Newznab { public class Newznab : HttpIndexerBase { + private readonly INewznabCapabilitiesProvider _capabilitiesProvider; + public override string Name { get @@ -24,7 +28,7 @@ namespace NzbDrone.Core.Indexers.Newznab public override IIndexerRequestGenerator GetRequestGenerator() { - return new NewznabRequestGenerator() + return new NewznabRequestGenerator(_capabilitiesProvider) { PageSize = PageSize, Settings = Settings @@ -50,10 +54,10 @@ namespace NzbDrone.Core.Indexers.Newznab } } - public Newznab(IHttpClient httpClient, IIndexerStatusService indexerStatusService, IConfigService configService, IParsingService parsingService, Logger logger) + public Newznab(INewznabCapabilitiesProvider capabilitiesProvider, IHttpClient httpClient, IIndexerStatusService indexerStatusService, IConfigService configService, IParsingService parsingService, Logger logger) : base(httpClient, indexerStatusService, configService, parsingService, logger) { - + _capabilitiesProvider = capabilitiesProvider; } private IndexerDefinition GetDefinition(string name, NewznabSettings settings) @@ -82,5 +86,42 @@ namespace NzbDrone.Core.Indexers.Newznab return settings; } + + protected override void Test(List failures) + { + base.Test(failures); + + failures.AddIfNotNull(TestCapabilities()); + } + + protected virtual ValidationFailure TestCapabilities() + { + try + { + var capabilities = _capabilitiesProvider.GetCapabilities(Settings); + + if (capabilities.SupportedSearchParameters != null && capabilities.SupportedSearchParameters.Contains("q")) + { + return null; + } + + if (capabilities.SupportedTvSearchParameters != null && + new[] { "q", "tvdbid", "rid" }.Any(v => capabilities.SupportedTvSearchParameters.Contains(v)) && + new[] { "season", "ep" }.All(v => capabilities.SupportedTvSearchParameters.Contains(v))) + { + return null; + } + + return new ValidationFailure(string.Empty, "Indexer does not support required search parameters"); + } + catch (Exception ex) + { + _logger.WarnException("Unable to connect to indexer: " + ex.Message, ex); + + return new ValidationFailure(string.Empty, "Unable to connect to indexer, check the log for more details"); + } + + return null; + } } } diff --git a/src/NzbDrone.Core/Indexers/Newznab/NewznabCapabilities.cs b/src/NzbDrone.Core/Indexers/Newznab/NewznabCapabilities.cs new file mode 100644 index 000000000..0c25c7802 --- /dev/null +++ b/src/NzbDrone.Core/Indexers/Newznab/NewznabCapabilities.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; + +namespace NzbDrone.Core.Indexers.Newznab +{ + public class NewznabCapabilities + { + public string[] SupportedSearchParameters { get; set; } + public string[] SupportedTvSearchParameters { get; set; } + public List Categories { get; set; } + + public NewznabCapabilities() + { + SupportedSearchParameters = new[] { "q" }; + SupportedTvSearchParameters = new[] { "q", "rid", "season", "ep" }; // This should remain 'rid' for older newznab installs. + Categories = new List(); + } + } + + public class NewznabCategory + { + public int Id { get; set; } + public string Name { get; set; } + public string Description { get; set; } + + public List Subcategories { get; set; } + } +} diff --git a/src/NzbDrone.Core/Indexers/Torznab/TorznabCapabilitiesProvider.cs b/src/NzbDrone.Core/Indexers/Newznab/NewznabCapabilitiesProvider.cs similarity index 81% rename from src/NzbDrone.Core/Indexers/Torznab/TorznabCapabilitiesProvider.cs rename to src/NzbDrone.Core/Indexers/Newznab/NewznabCapabilitiesProvider.cs index 3d5cef1ca..d415074a4 100644 --- a/src/NzbDrone.Core/Indexers/Torznab/TorznabCapabilitiesProvider.cs +++ b/src/NzbDrone.Core/Indexers/Newznab/NewznabCapabilitiesProvider.cs @@ -7,27 +7,27 @@ using NzbDrone.Common.Extensions; using NzbDrone.Common.Http; using NzbDrone.Common.Serializer; -namespace NzbDrone.Core.Indexers.Torznab +namespace NzbDrone.Core.Indexers.Newznab { - public interface ITorznabCapabilitiesProvider + public interface INewznabCapabilitiesProvider { - TorznabCapabilities GetCapabilities(TorznabSettings settings); + NewznabCapabilities GetCapabilities(NewznabSettings settings); } - public class TorznabCapabilitiesProvider : ITorznabCapabilitiesProvider + public class NewznabCapabilitiesProvider : INewznabCapabilitiesProvider { - private readonly ICached _capabilitiesCache; + private readonly ICached _capabilitiesCache; private readonly IHttpClient _httpClient; private readonly Logger _logger; - public TorznabCapabilitiesProvider(ICacheManager cacheManager, IHttpClient httpClient, Logger logger) + public NewznabCapabilitiesProvider(ICacheManager cacheManager, IHttpClient httpClient, Logger logger) { - _capabilitiesCache = cacheManager.GetCache(GetType()); + _capabilitiesCache = cacheManager.GetCache(GetType()); _httpClient = httpClient; _logger = logger; } - public TorznabCapabilities GetCapabilities(TorznabSettings indexerSettings) + public NewznabCapabilities GetCapabilities(NewznabSettings indexerSettings) { var key = indexerSettings.ToJson(); var capabilities = _capabilitiesCache.Get(key, () => FetchCapabilities(indexerSettings), TimeSpan.FromDays(7)); @@ -35,9 +35,9 @@ namespace NzbDrone.Core.Indexers.Torznab return capabilities; } - private TorznabCapabilities FetchCapabilities(TorznabSettings indexerSettings) + private NewznabCapabilities FetchCapabilities(NewznabSettings indexerSettings) { - var capabilities = new TorznabCapabilities(); + var capabilities = new NewznabCapabilities(); var url = string.Format("{0}/api?t=caps", indexerSettings.Url.TrimEnd('/')); @@ -62,9 +62,9 @@ namespace NzbDrone.Core.Indexers.Torznab return capabilities; } - private TorznabCapabilities ParseCapabilities(HttpResponse response) + private NewznabCapabilities ParseCapabilities(HttpResponse response) { - var capabilities = new TorznabCapabilities(); + var capabilities = new NewznabCapabilities(); var xmlRoot = XDocument.Parse(response.Content).Element("caps"); @@ -97,17 +97,17 @@ namespace NzbDrone.Core.Indexers.Torznab { foreach (var xmlCategory in xmlCategories.Elements("category")) { - var cat = new TorznabCategory + var cat = new NewznabCategory { Id = int.Parse(xmlCategory.Attribute("id").Value), Name = xmlCategory.Attribute("name").Value, Description = xmlCategory.Attribute("description") != null ? xmlCategory.Attribute("description").Value : string.Empty, - Subcategories = new List() + Subcategories = new List() }; foreach (var xmlSubcat in xmlCategory.Elements("subcat")) { - cat.Subcategories.Add(new TorznabCategory + cat.Subcategories.Add(new NewznabCategory { Id = int.Parse(xmlSubcat.Attribute("id").Value), Name = xmlSubcat.Attribute("name").Value, diff --git a/src/NzbDrone.Core/Indexers/Newznab/NewznabRequestGenerator.cs b/src/NzbDrone.Core/Indexers/Newznab/NewznabRequestGenerator.cs index 1091f948b..61ca41b12 100644 --- a/src/NzbDrone.Core/Indexers/Newznab/NewznabRequestGenerator.cs +++ b/src/NzbDrone.Core/Indexers/Newznab/NewznabRequestGenerator.cs @@ -9,21 +9,79 @@ namespace NzbDrone.Core.Indexers.Newznab { public class NewznabRequestGenerator : IIndexerRequestGenerator { - public Int32 MaxPages { get; set; } - public Int32 PageSize { get; set; } + private readonly INewznabCapabilitiesProvider _capabilitiesProvider; + public int MaxPages { get; set; } + public int PageSize { get; set; } public NewznabSettings Settings { get; set; } - public NewznabRequestGenerator() + public NewznabRequestGenerator(INewznabCapabilitiesProvider capabilitiesProvider) { + _capabilitiesProvider = capabilitiesProvider; + MaxPages = 30; PageSize = 100; } + private bool SupportsSearch + { + get + { + var capabilities = _capabilitiesProvider.GetCapabilities(Settings); + + return capabilities.SupportedSearchParameters != null && + capabilities.SupportedSearchParameters.Contains("q"); + } + } + + private bool SupportsTvSearch + { + get + { + var capabilities = _capabilitiesProvider.GetCapabilities(Settings); + + return capabilities.SupportedTvSearchParameters != null && + capabilities.SupportedTvSearchParameters.Contains("q") && + capabilities.SupportedTvSearchParameters.Contains("season") && + capabilities.SupportedTvSearchParameters.Contains("ep"); + } + } + + private bool SupportsTvdbSearch + { + get + { + var capabilities = _capabilitiesProvider.GetCapabilities(Settings); + + return capabilities.SupportedTvSearchParameters != null && + capabilities.SupportedTvSearchParameters.Contains("tvdbid") && + capabilities.SupportedTvSearchParameters.Contains("season") && + capabilities.SupportedTvSearchParameters.Contains("ep"); + } + } + + private bool SupportsTvRageSearch + { + get + { + var capabilities = _capabilitiesProvider.GetCapabilities(Settings); + + return capabilities.SupportedTvSearchParameters != null && + capabilities.SupportedTvSearchParameters.Contains("rid") && + capabilities.SupportedTvSearchParameters.Contains("season") && + capabilities.SupportedTvSearchParameters.Contains("ep"); + } + } + public virtual IList> GetRecentRequests() { var pageableRequests = new List>(); - pageableRequests.AddIfNotNull(GetPagedRequests(MaxPages, Settings.Categories.Concat(Settings.AnimeCategories), "tvsearch", "")); + var capabilities = _capabilitiesProvider.GetCapabilities(Settings); + + if (capabilities.SupportedTvSearchParameters != null) + { + pageableRequests.AddIfNotNull(GetPagedRequests(MaxPages, Settings.Categories.Concat(Settings.AnimeCategories), "tvsearch", "")); + } return pageableRequests; } @@ -32,20 +90,28 @@ namespace NzbDrone.Core.Indexers.Newznab { var pageableRequests = new List>(); - if (searchCriteria.Series.TvRageId > 0) + if (searchCriteria.Series.TvdbId > 0 && SupportsTvdbSearch) { pageableRequests.AddIfNotNull(GetPagedRequests(MaxPages, Settings.Categories, "tvsearch", - String.Format("&rid={0}&season={1}&ep={2}", + string.Format("&tvdbid={0}&season={1}&ep={2}", + searchCriteria.Series.TvdbId, + searchCriteria.SeasonNumber, + searchCriteria.EpisodeNumber))); + } + else if (searchCriteria.Series.TvRageId > 0 && SupportsTvRageSearch) + { + pageableRequests.AddIfNotNull(GetPagedRequests(MaxPages, Settings.Categories, "tvsearch", + string.Format("&rid={0}&season={1}&ep={2}", searchCriteria.Series.TvRageId, searchCriteria.SeasonNumber, searchCriteria.EpisodeNumber))); } - else + else if (SupportsTvSearch) { foreach (var queryTitle in searchCriteria.QueryTitles) { pageableRequests.AddIfNotNull(GetPagedRequests(MaxPages, Settings.Categories, "tvsearch", - String.Format("&q={0}&season={1}&ep={2}", + string.Format("&q={0}&season={1}&ep={2}", NewsnabifyTitle(queryTitle), searchCriteria.SeasonNumber, searchCriteria.EpisodeNumber))); @@ -59,19 +125,26 @@ namespace NzbDrone.Core.Indexers.Newznab { var pageableRequests = new List>(); - if (searchCriteria.Series.TvRageId > 0) + if (searchCriteria.Series.TvdbId > 0 && SupportsTvdbSearch) + { + pageableRequests.AddIfNotNull(GetPagedRequests(MaxPages, Settings.Categories, "tvsearch", + string.Format("&tvdbid={0}&season={1}", + searchCriteria.Series.TvdbId, + searchCriteria.SeasonNumber))); + } + else if (searchCriteria.Series.TvRageId > 0 && SupportsTvRageSearch) { pageableRequests.AddIfNotNull(GetPagedRequests(MaxPages, Settings.Categories, "tvsearch", - String.Format("&rid={0}&season={1}", + string.Format("&rid={0}&season={1}", searchCriteria.Series.TvRageId, searchCriteria.SeasonNumber))); } - else + else if (SupportsTvSearch) { foreach (var queryTitle in searchCriteria.QueryTitles) { pageableRequests.AddIfNotNull(GetPagedRequests(MaxPages, Settings.Categories, "tvsearch", - String.Format("&q={0}&season={1}", + string.Format("&q={0}&season={1}", NewsnabifyTitle(queryTitle), searchCriteria.SeasonNumber))); } @@ -84,19 +157,26 @@ namespace NzbDrone.Core.Indexers.Newznab { var pageableRequests = new List>(); - if (searchCriteria.Series.TvRageId > 0) + if (searchCriteria.Series.TvdbId > 0 && SupportsTvdbSearch) + { + pageableRequests.AddIfNotNull(GetPagedRequests(MaxPages, Settings.Categories, "tvsearch", + string.Format("&tvdbid={0}&season={1:yyyy}&ep={1:MM}/{1:dd}", + searchCriteria.Series.TvdbId, + searchCriteria.AirDate))); + } + else if (searchCriteria.Series.TvRageId > 0 && SupportsTvRageSearch) { pageableRequests.AddIfNotNull(GetPagedRequests(MaxPages, Settings.Categories, "tvsearch", - String.Format("&rid={0}&season={1:yyyy}&ep={1:MM}/{1:dd}", + string.Format("&rid={0}&season={1:yyyy}&ep={1:MM}/{1:dd}", searchCriteria.Series.TvRageId, searchCriteria.AirDate))); } - else + else if (SupportsTvSearch) { foreach (var queryTitle in searchCriteria.QueryTitles) { pageableRequests.AddIfNotNull(GetPagedRequests(MaxPages, Settings.Categories, "tvsearch", - String.Format("&q={0}&season={1:yyyy}&ep={1:MM}/{1:dd}", + string.Format("&q={0}&season={1:yyyy}&ep={1:MM}/{1:dd}", NewsnabifyTitle(queryTitle), searchCriteria.AirDate))); } @@ -109,12 +189,15 @@ namespace NzbDrone.Core.Indexers.Newznab { var pageableRequests = new List>(); - foreach (var queryTitle in searchCriteria.QueryTitles) + if (SupportsSearch) { - pageableRequests.AddIfNotNull(GetPagedRequests(MaxPages, Settings.AnimeCategories, "search", - String.Format("&q={0}+{1:00}", - NewsnabifyTitle(queryTitle), - searchCriteria.AbsoluteEpisodeNumber))); + foreach (var queryTitle in searchCriteria.QueryTitles) + { + pageableRequests.AddIfNotNull(GetPagedRequests(MaxPages, Settings.AnimeCategories, "search", + string.Format("&q={0}+{1:00}", + NewsnabifyTitle(queryTitle), + searchCriteria.AbsoluteEpisodeNumber))); + } } return pageableRequests; @@ -124,29 +207,32 @@ namespace NzbDrone.Core.Indexers.Newznab { var pageableRequests = new List>(); - foreach (var queryTitle in searchCriteria.EpisodeQueryTitles) + if (SupportsSearch) { - var query = queryTitle.Replace('+', ' '); - query = System.Web.HttpUtility.UrlEncode(query); + foreach (var queryTitle in searchCriteria.EpisodeQueryTitles) + { + var query = queryTitle.Replace('+', ' '); + query = System.Web.HttpUtility.UrlEncode(query); - pageableRequests.AddIfNotNull(GetPagedRequests(MaxPages, Settings.Categories.Concat(Settings.AnimeCategories), "search", - String.Format("&q={0}", - query))); + pageableRequests.AddIfNotNull(GetPagedRequests(MaxPages, Settings.Categories.Concat(Settings.AnimeCategories), "search", + string.Format("&q={0}", + query))); + } } return pageableRequests; } - private IEnumerable GetPagedRequests(Int32 maxPages, IEnumerable categories, String searchType, String parameters) + private IEnumerable GetPagedRequests(int maxPages, IEnumerable categories, string searchType, string parameters) { if (categories.Empty()) { yield break; } - var categoriesQuery = String.Join(",", categories.Distinct()); + var categoriesQuery = string.Join(",", categories.Distinct()); - var baseUrl = String.Format("{0}/api?t={1}&cat={2}&extended=1{3}", Settings.Url.TrimEnd('/'), searchType, categoriesQuery, Settings.AdditionalParameters); + var baseUrl = string.Format("{0}/api?t={1}&cat={2}&extended=1{3}", Settings.Url.TrimEnd('/'), searchType, categoriesQuery, Settings.AdditionalParameters); if (Settings.ApiKey.IsNotNullOrWhiteSpace()) { @@ -155,18 +241,18 @@ namespace NzbDrone.Core.Indexers.Newznab if (PageSize == 0) { - yield return new IndexerRequest(String.Format("{0}{1}", baseUrl, parameters), HttpAccept.Rss); + yield return new IndexerRequest(string.Format("{0}{1}", baseUrl, parameters), HttpAccept.Rss); } else { for (var page = 0; page < maxPages; page++) { - yield return new IndexerRequest(String.Format("{0}&offset={1}&limit={2}{3}", baseUrl, page * PageSize, PageSize, parameters), HttpAccept.Rss); + yield return new IndexerRequest(string.Format("{0}&offset={1}&limit={2}{3}", baseUrl, page * PageSize, PageSize, parameters), HttpAccept.Rss); } } } - private static String NewsnabifyTitle(String title) + private static string NewsnabifyTitle(string title) { return title.Replace("+", "%20"); } diff --git a/src/NzbDrone.Core/Indexers/Newznab/NewznabRssParser.cs b/src/NzbDrone.Core/Indexers/Newznab/NewznabRssParser.cs index cee878b04..77c110faf 100644 --- a/src/NzbDrone.Core/Indexers/Newznab/NewznabRssParser.cs +++ b/src/NzbDrone.Core/Indexers/Newznab/NewznabRssParser.cs @@ -44,6 +44,7 @@ namespace NzbDrone.Core.Indexers.Newznab { releaseInfo = base.ProcessItem(item, releaseInfo); + releaseInfo.TvdbId = GetTvdbId(item); releaseInfo.TvRageId = GetTvRageId(item); return releaseInfo; @@ -97,6 +98,19 @@ namespace NzbDrone.Core.Indexers.Newznab return url; } + protected virtual int GetTvdbId(XElement item) + { + var tvdbIdString = TryGetNewznabAttribute(item, "tvdbid"); + int tvdbId; + + if (!tvdbIdString.IsNullOrWhiteSpace() && int.TryParse(tvdbIdString, out tvdbId)) + { + return tvdbId; + } + + return 0; + } + protected virtual int GetTvRageId(XElement item) { var tvRageIdString = TryGetNewznabAttribute(item, "rageid"); diff --git a/src/NzbDrone.Core/Indexers/Newznab/NewznabSettings.cs b/src/NzbDrone.Core/Indexers/Newznab/NewznabSettings.cs index 534ed366f..d590e0c5b 100644 --- a/src/NzbDrone.Core/Indexers/Newznab/NewznabSettings.cs +++ b/src/NzbDrone.Core/Indexers/Newznab/NewznabSettings.cs @@ -61,24 +61,24 @@ namespace NzbDrone.Core.Indexers.Newznab public NewznabSettings() { - Categories = new[] {5030, 5040}; - AnimeCategories = Enumerable.Empty(); + Categories = new[] { 5030, 5040 }; + AnimeCategories = Enumerable.Empty(); } [FieldDefinition(0, Label = "URL")] - public String Url { get; set; } + public string Url { get; set; } [FieldDefinition(1, Label = "API Key")] - public String ApiKey { get; set; } + public string ApiKey { get; set; } [FieldDefinition(2, Label = "Categories", HelpText = "Comma Separated list, leave blank to disable standard/daily shows", Advanced = true)] - public IEnumerable Categories { get; set; } + public IEnumerable Categories { get; set; } [FieldDefinition(3, Label = "Anime Categories", HelpText = "Comma Separated list, leave blank to disable anime", Advanced = true)] - public IEnumerable AnimeCategories { get; set; } + public IEnumerable AnimeCategories { get; set; } - [FieldDefinition(4, Label = "Additional Parameters", HelpText = "Additional newznab parameters", Advanced = true)] - public String AdditionalParameters { get; set; } + [FieldDefinition(4, Label = "Additional Parameters", HelpText = "Additional Newznab parameters", Advanced = true)] + public string AdditionalParameters { get; set; } public NzbDroneValidationResult Validate() { diff --git a/src/NzbDrone.Core/Indexers/Rarbg/RarbgParser.cs b/src/NzbDrone.Core/Indexers/Rarbg/RarbgParser.cs index 93ea2e8fe..58d0b1957 100644 --- a/src/NzbDrone.Core/Indexers/Rarbg/RarbgParser.cs +++ b/src/NzbDrone.Core/Indexers/Rarbg/RarbgParser.cs @@ -57,10 +57,18 @@ namespace NzbDrone.Core.Indexers.Rarbg torrentInfo.PublishDate = torrent.pubdate; torrentInfo.Seeders = torrent.seeders; torrentInfo.Peers = torrent.leechers + torrent.seeders; - - if (torrent.episode_info != null && torrent.episode_info.tvrage != null) + + if (torrent.episode_info != null) { - torrentInfo.TvRageId = torrent.episode_info.tvrage.Value; + if (torrent.episode_info.tvdb != null) + { + torrentInfo.TvdbId = torrent.episode_info.tvdb.Value; + } + + if (torrent.episode_info.tvrage != null) + { + torrentInfo.TvRageId = torrent.episode_info.tvrage.Value; + } } results.Add(torrentInfo); diff --git a/src/NzbDrone.Core/Indexers/Torznab/Torznab.cs b/src/NzbDrone.Core/Indexers/Torznab/Torznab.cs index e4550e8df..cfeb5e6c6 100644 --- a/src/NzbDrone.Core/Indexers/Torznab/Torznab.cs +++ b/src/NzbDrone.Core/Indexers/Torznab/Torznab.cs @@ -6,6 +6,7 @@ using NLog; using NzbDrone.Common.Extensions; using NzbDrone.Common.Http; using NzbDrone.Core.Configuration; +using NzbDrone.Core.Indexers.Newznab; using NzbDrone.Core.Parser; using NzbDrone.Core.ThingiProvider; @@ -13,7 +14,7 @@ namespace NzbDrone.Core.Indexers.Torznab { public class Torznab : HttpIndexerBase { - private readonly ITorznabCapabilitiesProvider _torznabCapabilitiesProvider; + private readonly INewznabCapabilitiesProvider _capabilitiesProvider; public override string Name { @@ -28,7 +29,7 @@ namespace NzbDrone.Core.Indexers.Torznab public override IIndexerRequestGenerator GetRequestGenerator() { - return new TorznabRequestGenerator(_torznabCapabilitiesProvider) + return new NewznabRequestGenerator(_capabilitiesProvider) { PageSize = PageSize, Settings = Settings @@ -48,10 +49,10 @@ namespace NzbDrone.Core.Indexers.Torznab } } - public Torznab(ITorznabCapabilitiesProvider torznabCapabilitiesProvider, IHttpClient httpClient, IIndexerStatusService indexerStatusService, IConfigService configService, IParsingService parsingService, Logger logger) + public Torznab(INewznabCapabilitiesProvider capabilitiesProvider, IHttpClient httpClient, IIndexerStatusService indexerStatusService, IConfigService configService, IParsingService parsingService, Logger logger) : base(httpClient, indexerStatusService, configService, parsingService, logger) { - _torznabCapabilitiesProvider = torznabCapabilitiesProvider; + _capabilitiesProvider = capabilitiesProvider; } private IndexerDefinition GetDefinition(string name, TorznabSettings settings) @@ -92,7 +93,7 @@ namespace NzbDrone.Core.Indexers.Torznab { try { - var capabilities = _torznabCapabilitiesProvider.GetCapabilities(Settings); + var capabilities = _capabilitiesProvider.GetCapabilities(Settings); if (capabilities.SupportedSearchParameters != null && capabilities.SupportedSearchParameters.Contains("q")) { @@ -100,8 +101,8 @@ namespace NzbDrone.Core.Indexers.Torznab } if (capabilities.SupportedTvSearchParameters != null && - (capabilities.SupportedSearchParameters.Contains("q") || capabilities.SupportedSearchParameters.Contains("rid")) && - capabilities.SupportedTvSearchParameters.Contains("season") && capabilities.SupportedTvSearchParameters.Contains("ep")) + new[] { "q", "tvdbid", "rid" }.Any(v => capabilities.SupportedTvSearchParameters.Contains(v)) && + new[] { "season", "ep" }.All(v => capabilities.SupportedTvSearchParameters.Contains(v))) { return null; } diff --git a/src/NzbDrone.Core/Indexers/Torznab/TorznabCapabilities.cs b/src/NzbDrone.Core/Indexers/Torznab/TorznabCapabilities.cs deleted file mode 100644 index f09c36477..000000000 --- a/src/NzbDrone.Core/Indexers/Torznab/TorznabCapabilities.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System; -using System.Collections.Generic; - -namespace NzbDrone.Core.Indexers.Torznab -{ - public class TorznabCapabilities - { - public string[] SupportedSearchParameters { get; set; } - public string[] SupportedTvSearchParameters { get; set; } - public List Categories { get; set; } - - public TorznabCapabilities() - { - SupportedSearchParameters = new[] { "q", "offset", "limit" }; - SupportedTvSearchParameters = new[] { "q", "rid", "season", "ep", "offset", "limit" }; - Categories = new List(); - } - } - - public class TorznabCategory - { - public int Id { get; set; } - public string Name { get; set; } - public string Description { get; set; } - - public List Subcategories { get; set; } - } -} diff --git a/src/NzbDrone.Core/Indexers/Torznab/TorznabException.cs b/src/NzbDrone.Core/Indexers/Torznab/TorznabException.cs index 7f0f3205a..258a12492 100644 --- a/src/NzbDrone.Core/Indexers/Torznab/TorznabException.cs +++ b/src/NzbDrone.Core/Indexers/Torznab/TorznabException.cs @@ -8,8 +8,7 @@ namespace NzbDrone.Core.Indexers.Torznab { } - public TorznabException(string message) - : base(message) + public TorznabException(string message) : base(message) { } } diff --git a/src/NzbDrone.Core/Indexers/Torznab/TorznabRequestGenerator.cs b/src/NzbDrone.Core/Indexers/Torznab/TorznabRequestGenerator.cs deleted file mode 100644 index 6d9315c12..000000000 --- a/src/NzbDrone.Core/Indexers/Torznab/TorznabRequestGenerator.cs +++ /dev/null @@ -1,228 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using NzbDrone.Common.Extensions; -using NzbDrone.Common.Http; -using NzbDrone.Core.IndexerSearch.Definitions; - -namespace NzbDrone.Core.Indexers.Torznab -{ - public class TorznabRequestGenerator : IIndexerRequestGenerator - { - private readonly ITorznabCapabilitiesProvider _capabilitiesProvider; - - public int MaxPages { get; set; } - public int PageSize { get; set; } - - public TorznabSettings Settings { get; set; } - - public TorznabRequestGenerator(ITorznabCapabilitiesProvider capabilitiesProvider) - { - _capabilitiesProvider = capabilitiesProvider; - - MaxPages = 30; - PageSize = 100; - } - - private bool SupportsSearch - { - get - { - var capabilities = _capabilitiesProvider.GetCapabilities(Settings); - - return capabilities.SupportedSearchParameters != null - && capabilities.SupportedSearchParameters.Contains("q"); - } - } - - private bool SupportsTvSearch - { - get - { - var capabilities = _capabilitiesProvider.GetCapabilities(Settings); - - return capabilities.SupportedTvSearchParameters != null - && capabilities.SupportedTvSearchParameters.Contains("q") - && capabilities.SupportedTvSearchParameters.Contains("season") - && capabilities.SupportedTvSearchParameters.Contains("ep"); - } - } - - private bool SupportsTvRageSearch - { - get - { - var capabilities = _capabilitiesProvider.GetCapabilities(Settings); - - return capabilities.SupportedTvSearchParameters != null - && capabilities.SupportedTvSearchParameters.Contains("rid") - && capabilities.SupportedTvSearchParameters.Contains("season") - && capabilities.SupportedTvSearchParameters.Contains("ep") - && Settings.EnableRageIDLookup; - } - } - - public virtual IList> GetRecentRequests() - { - var pageableRequests = new List>(); - - var capabilities = _capabilitiesProvider.GetCapabilities(Settings); - - if (capabilities.SupportedTvSearchParameters != null) - { - pageableRequests.AddIfNotNull(GetPagedRequests(MaxPages, Settings.Categories.Concat(Settings.AnimeCategories), "tvsearch", "")); - } - - return pageableRequests; - } - - public virtual IList> GetSearchRequests(SingleEpisodeSearchCriteria searchCriteria) - { - var pageableRequests = new List>(); - - if (searchCriteria.Series.TvRageId > 0 && SupportsTvRageSearch) - { - pageableRequests.AddIfNotNull(GetPagedRequests(MaxPages, Settings.Categories, "tvsearch", - string.Format("&rid={0}&season={1}&ep={2}", - searchCriteria.Series.TvRageId, - searchCriteria.SeasonNumber, - searchCriteria.EpisodeNumber))); - } - else if (SupportsTvSearch) - { - foreach (var queryTitle in searchCriteria.QueryTitles) - { - pageableRequests.AddIfNotNull(GetPagedRequests(MaxPages, Settings.Categories, "tvsearch", - string.Format("&q={0}&season={1}&ep={2}", - NewsnabifyTitle(queryTitle), - searchCriteria.SeasonNumber, - searchCriteria.EpisodeNumber))); - } - } - - return pageableRequests; - } - - public virtual IList> GetSearchRequests(SeasonSearchCriteria searchCriteria) - { - var pageableRequests = new List>(); - - if (searchCriteria.Series.TvRageId > 0 && SupportsTvRageSearch) - { - pageableRequests.AddIfNotNull(GetPagedRequests(MaxPages, Settings.Categories, "tvsearch", - string.Format("&rid={0}&season={1}", - searchCriteria.Series.TvRageId, - searchCriteria.SeasonNumber))); - } - else if (SupportsTvSearch) - { - foreach (var queryTitle in searchCriteria.QueryTitles) - { - pageableRequests.AddIfNotNull(GetPagedRequests(MaxPages, Settings.Categories, "tvsearch", - string.Format("&q={0}&season={1}", - NewsnabifyTitle(queryTitle), - searchCriteria.SeasonNumber))); - } - } - - return pageableRequests; - } - - public virtual IList> GetSearchRequests(DailyEpisodeSearchCriteria searchCriteria) - { - var pageableRequests = new List>(); - - if (searchCriteria.Series.TvRageId > 0 && SupportsTvRageSearch) - { - pageableRequests.AddIfNotNull(GetPagedRequests(MaxPages, Settings.Categories, "tvsearch", - string.Format("&rid={0}&season={1:yyyy}&ep={1:MM}/{1:dd}", - searchCriteria.Series.TvRageId, - searchCriteria.AirDate))); - } - else if (SupportsTvSearch) - { - foreach (var queryTitle in searchCriteria.QueryTitles) - { - pageableRequests.AddIfNotNull(GetPagedRequests(MaxPages, Settings.Categories, "tvsearch", - string.Format("&q={0}&season={1:yyyy}&ep={1:MM}/{1:dd}", - NewsnabifyTitle(queryTitle), - searchCriteria.AirDate))); - } - } - - return pageableRequests; - } - - public virtual IList> GetSearchRequests(AnimeEpisodeSearchCriteria searchCriteria) - { - var pageableRequests = new List>(); - - if (SupportsSearch) - { - foreach (var queryTitle in searchCriteria.QueryTitles) - { - pageableRequests.AddIfNotNull(GetPagedRequests(MaxPages, Settings.AnimeCategories, "search", - string.Format("&q={0}+{1:00}", - NewsnabifyTitle(queryTitle), - searchCriteria.AbsoluteEpisodeNumber))); - } - } - - return pageableRequests; - } - - public virtual IList> GetSearchRequests(SpecialEpisodeSearchCriteria searchCriteria) - { - var pageableRequests = new List>(); - - if (SupportsSearch) - { - foreach (var queryTitle in searchCriteria.EpisodeQueryTitles) - { - var query = queryTitle.Replace('+', ' '); - query = System.Web.HttpUtility.UrlEncode(query); - - pageableRequests.AddIfNotNull(GetPagedRequests(MaxPages, Settings.Categories.Concat(Settings.AnimeCategories), "search", - string.Format("&q={0}", - query))); - } - } - - return pageableRequests; - } - - private IEnumerable GetPagedRequests(int maxPages, IEnumerable categories, string searchType, string parameters) - { - if (categories.Empty()) - { - yield break; - } - - var categoriesQuery = string.Join(",", categories.Distinct()); - - var baseUrl = string.Format("{0}/api?t={1}&cat={2}&extended=1{3}", Settings.Url.TrimEnd('/'), searchType, categoriesQuery, Settings.AdditionalParameters); - - if (Settings.ApiKey.IsNotNullOrWhiteSpace()) - { - baseUrl += "&apikey=" + Settings.ApiKey; - } - - if (PageSize == 0) - { - yield return new IndexerRequest(string.Format("{0}{1}", baseUrl, parameters), HttpAccept.Rss); - } - else - { - for (var page = 0; page < maxPages; page++) - { - yield return new IndexerRequest(string.Format("{0}&offset={1}&limit={2}{3}", baseUrl, page * PageSize, PageSize, parameters), HttpAccept.Rss); - } - } - } - - private static string NewsnabifyTitle(string title) - { - return title.Replace("+", "%20"); - } - } -} diff --git a/src/NzbDrone.Core/Indexers/Torznab/TorznabRssParser.cs b/src/NzbDrone.Core/Indexers/Torznab/TorznabRssParser.cs index 0c82a7ab5..246056e66 100644 --- a/src/NzbDrone.Core/Indexers/Torznab/TorznabRssParser.cs +++ b/src/NzbDrone.Core/Indexers/Torznab/TorznabRssParser.cs @@ -13,7 +13,7 @@ namespace NzbDrone.Core.Indexers.Torznab protected override bool PreProcess(IndexerResponse indexerResponse) { - var xdoc = XDocument.Parse(indexerResponse.Content); + var xdoc = LoadXmlDocument(indexerResponse); var error = xdoc.Descendants("error").FirstOrDefault(); if (error == null) return true; @@ -40,6 +40,7 @@ namespace NzbDrone.Core.Indexers.Torznab { var torrentInfo = base.ProcessItem(item, releaseInfo) as TorrentInfo; + torrentInfo.TvdbId = GetTvdbId(item); torrentInfo.TvRageId = GetTvRageId(item); return torrentInfo; @@ -67,12 +68,12 @@ namespace NzbDrone.Core.Indexers.Torznab return ParseUrl(item.TryGetValue("comments")); } - protected override Int64 GetSize(XElement item) + protected override long GetSize(XElement item) { - Int64 size; + long size; var sizeString = TryGetTorznabAttribute(item, "size"); - if (!sizeString.IsNullOrWhiteSpace() && Int64.TryParse(sizeString, out size)) + if (!sizeString.IsNullOrWhiteSpace() && long.TryParse(sizeString, out size)) { return size; } @@ -99,12 +100,25 @@ namespace NzbDrone.Core.Indexers.Torznab return url; } - protected virtual Int32 GetTvRageId(XElement item) + protected virtual int GetTvdbId(XElement item) + { + var tvdbIdString = TryGetTorznabAttribute(item, "tvdbid"); + int tvdbId; + + if (!tvdbIdString.IsNullOrWhiteSpace() && int.TryParse(tvdbIdString, out tvdbId)) + { + return tvdbId; + } + + return 0; + } + + protected virtual int GetTvRageId(XElement item) { var tvRageIdString = TryGetTorznabAttribute(item, "rageid"); - Int32 tvRageId; + int tvRageId; - if (!tvRageIdString.IsNullOrWhiteSpace() && Int32.TryParse(tvRageIdString, out tvRageId)) + if (!tvRageIdString.IsNullOrWhiteSpace() && int.TryParse(tvRageIdString, out tvRageId)) { return tvRageId; } @@ -121,25 +135,25 @@ namespace NzbDrone.Core.Indexers.Torznab return TryGetTorznabAttribute(item, "magneturl"); } - protected override Int32? GetSeeders(XElement item) + protected override int? GetSeeders(XElement item) { var seeders = TryGetTorznabAttribute(item, "seeders"); if (seeders.IsNotNullOrWhiteSpace()) { - return Int32.Parse(seeders); + return int.Parse(seeders); } return base.GetSeeders(item); } - protected override Int32? GetPeers(XElement item) + protected override int? GetPeers(XElement item) { var peers = TryGetTorznabAttribute(item, "peers"); if (peers.IsNotNullOrWhiteSpace()) { - return Int32.Parse(peers); + return int.Parse(peers); } var seeders = TryGetTorznabAttribute(item, "seeders"); @@ -147,7 +161,7 @@ namespace NzbDrone.Core.Indexers.Torznab if (seeders.IsNotNullOrWhiteSpace() && leechers.IsNotNullOrWhiteSpace()) { - return Int32.Parse(seeders) + Int32.Parse(leechers); + return int.Parse(seeders) + int.Parse(leechers); } return base.GetPeers(item); diff --git a/src/NzbDrone.Core/Indexers/Torznab/TorznabSettings.cs b/src/NzbDrone.Core/Indexers/Torznab/TorznabSettings.cs index 55be40bed..e20d7d0d9 100644 --- a/src/NzbDrone.Core/Indexers/Torznab/TorznabSettings.cs +++ b/src/NzbDrone.Core/Indexers/Torznab/TorznabSettings.cs @@ -3,8 +3,10 @@ using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; using FluentValidation; +using FluentValidation.Results; using NzbDrone.Common.Extensions; using NzbDrone.Core.Annotations; +using NzbDrone.Core.Indexers.Newznab; using NzbDrone.Core.ThingiProvider; using NzbDrone.Core.Validation; @@ -14,7 +16,6 @@ namespace NzbDrone.Core.Indexers.Torznab { private static readonly string[] ApiKeyWhiteList = { - "hdaccess.net", "hd4free.xyz", }; @@ -32,46 +33,27 @@ namespace NzbDrone.Core.Indexers.Torznab public TorznabSettingsValidator() { + Custom(newznab => + { + if (newznab.Categories.Empty() && newznab.AnimeCategories.Empty()) + { + return new ValidationFailure("", "Either 'Categories' or 'Anime Categories' must be provided"); + } + + return null; + }); + RuleFor(c => c.Url).ValidRootUrl(); RuleFor(c => c.ApiKey).NotEmpty().When(ShouldHaveApiKey); - RuleFor(c => c.Categories).NotEmpty().When(c => !c.AnimeCategories.Any()); - RuleFor(c => c.AnimeCategories).NotEmpty().When(c => !c.Categories.Any()); - RuleFor(c => c.AdditionalParameters) - .Matches(AdditionalParametersRegex) - .When(c => !c.AdditionalParameters.IsNullOrWhiteSpace()); + RuleFor(c => c.AdditionalParameters).Matches(AdditionalParametersRegex) + .When(c => !c.AdditionalParameters.IsNullOrWhiteSpace()); } } - public class TorznabSettings : IProviderConfig + public class TorznabSettings : NewznabSettings { private static readonly TorznabSettingsValidator Validator = new TorznabSettingsValidator(); - public TorznabSettings() - { - Categories = new[] { 5030, 5040 }; - AnimeCategories = Enumerable.Empty(); - EnableRageIDLookup = true; - } - - [FieldDefinition(0, Label = "URL")] - public string Url { get; set; } - - [FieldDefinition(1, Label = "API Key")] - public string ApiKey { get; set; } - - [FieldDefinition(2, Label = "Categories", HelpText = "Comma Separated list, leave blank to disable standard/daily shows", Advanced = true)] - public IEnumerable Categories { get; set; } - - [FieldDefinition(3, Label = "Anime Categories", HelpText = "Comma Separated list, leave blank to disable anime", Advanced = true)] - public IEnumerable AnimeCategories { get; set; } - - [FieldDefinition(4, Label = "Additional Parameters", HelpText = "Additional Torznab parameters", Advanced = true)] - public string AdditionalParameters { get; set; } - - // TODO: To be removed in the next version. - [FieldDefinition(5, Type = FieldType.Checkbox, Label = "Enable RageID Lookup", HelpText = "Disable this if your tracker doesn't have tvrage ids, Sonarr will then use (more expensive) title queries.", Advanced = true)] - public bool EnableRageIDLookup { get; set; } - public NzbDroneValidationResult Validate() { return new NzbDroneValidationResult(Validator.Validate(this)); diff --git a/src/NzbDrone.Core/NzbDrone.Core.csproj b/src/NzbDrone.Core/NzbDrone.Core.csproj index 75c4b246f..620ae5dc8 100644 --- a/src/NzbDrone.Core/NzbDrone.Core.csproj +++ b/src/NzbDrone.Core/NzbDrone.Core.csproj @@ -519,6 +519,8 @@ + + @@ -558,11 +560,8 @@ - - - diff --git a/src/NzbDrone.Core/Parser/Model/ReleaseInfo.cs b/src/NzbDrone.Core/Parser/Model/ReleaseInfo.cs index 35ab34d27..6846dc882 100644 --- a/src/NzbDrone.Core/Parser/Model/ReleaseInfo.cs +++ b/src/NzbDrone.Core/Parser/Model/ReleaseInfo.cs @@ -15,6 +15,7 @@ namespace NzbDrone.Core.Parser.Model public int IndexerId { get; set; } public string Indexer { get; set; } public DownloadProtocol DownloadProtocol { get; set; } + public int TvdbId { get; set; } public int TvRageId { get; set; } public DateTime PublishDate { get; set; } @@ -73,6 +74,7 @@ namespace NzbDrone.Core.Parser.Model stringBuilder.AppendLine("Indexer: " + Indexer ?? "Empty"); stringBuilder.AppendLine("CommentUrl: " + CommentUrl ?? "Empty"); stringBuilder.AppendLine("DownloadProtocol: " + DownloadProtocol ?? "Empty"); + stringBuilder.AppendLine("TvdbId: " + TvdbId ?? "Empty"); stringBuilder.AppendLine("TvRageId: " + TvRageId ?? "Empty"); stringBuilder.AppendLine("PublishDate: " + PublishDate ?? "Empty"); return stringBuilder.ToString(); diff --git a/src/NzbDrone.Core/Parser/ParsingService.cs b/src/NzbDrone.Core/Parser/ParsingService.cs index de5e5f63f..b703d09d2 100644 --- a/src/NzbDrone.Core/Parser/ParsingService.cs +++ b/src/NzbDrone.Core/Parser/ParsingService.cs @@ -16,10 +16,10 @@ namespace NzbDrone.Core.Parser LocalEpisode GetLocalEpisode(string filename, Series series); LocalEpisode GetLocalEpisode(string filename, Series series, ParsedEpisodeInfo folderInfo, bool sceneSource); Series GetSeries(string title); - RemoteEpisode Map(ParsedEpisodeInfo parsedEpisodeInfo, Int32 tvRageId = 0, SearchCriteriaBase searchCriteria = null); - RemoteEpisode Map(ParsedEpisodeInfo parsedEpisodeInfo, Int32 seriesId, IEnumerable episodeIds); + RemoteEpisode Map(ParsedEpisodeInfo parsedEpisodeInfo, int tvdbId, int tvRageId, SearchCriteriaBase searchCriteria = null); + RemoteEpisode Map(ParsedEpisodeInfo parsedEpisodeInfo, int seriesId, IEnumerable episodeIds); List GetEpisodes(ParsedEpisodeInfo parsedEpisodeInfo, Series series, bool sceneSource, SearchCriteriaBase searchCriteria = null); - ParsedEpisodeInfo ParseSpecialEpisodeTitle(string title, int tvRageId, SearchCriteriaBase searchCriteria = null); + ParsedEpisodeInfo ParseSpecialEpisodeTitle(string title, int tvdbId, int tvRageId, SearchCriteriaBase searchCriteria = null); } public class ParsingService : IParsingService @@ -109,14 +109,14 @@ namespace NzbDrone.Core.Parser return series; } - public RemoteEpisode Map(ParsedEpisodeInfo parsedEpisodeInfo, Int32 tvRageId, SearchCriteriaBase searchCriteria = null) + public RemoteEpisode Map(ParsedEpisodeInfo parsedEpisodeInfo, int tvdbId, int tvRageId, SearchCriteriaBase searchCriteria = null) { var remoteEpisode = new RemoteEpisode { ParsedEpisodeInfo = parsedEpisodeInfo, }; - var series = GetSeries(parsedEpisodeInfo, tvRageId, searchCriteria); + var series = GetSeries(parsedEpisodeInfo, tvdbId, tvRageId, searchCriteria); if (series == null) { @@ -286,20 +286,19 @@ namespace NzbDrone.Core.Parser return result; } - public ParsedEpisodeInfo ParseSpecialEpisodeTitle(string title, int tvRageId, SearchCriteriaBase searchCriteria = null) + public ParsedEpisodeInfo ParseSpecialEpisodeTitle(string title, int tvdbId, int tvRageId, SearchCriteriaBase searchCriteria = null) { if (searchCriteria != null) { - var tvdbId = _sceneMappingService.FindTvdbId(title); - if (tvdbId.HasValue) + if (tvdbId == 0) + tvdbId = _sceneMappingService.FindTvdbId(title) ?? 0; + + if (tvdbId != 0 && tvdbId == searchCriteria.Series.TvdbId) { - if (searchCriteria.Series.TvdbId == tvdbId) - { - return ParseSpecialEpisodeTitle(title, searchCriteria.Series); - } + return ParseSpecialEpisodeTitle(title, searchCriteria.Series); } - if (tvRageId == searchCriteria.Series.TvRageId) + if (tvRageId != 0 && tvRageId == searchCriteria.Series.TvRageId) { return ParseSpecialEpisodeTitle(title, searchCriteria.Series); } @@ -310,6 +309,10 @@ namespace NzbDrone.Core.Parser { series = _seriesService.FindByTitleInexact(title); } + if (series == null && tvdbId > 0) + { + series = _seriesService.FindByTvdbId(tvdbId); + } if (series == null && tvRageId > 0) { series = _seriesService.FindByTvRageId(tvRageId); @@ -351,20 +354,19 @@ namespace NzbDrone.Core.Parser return null; } - private Series GetSeries(ParsedEpisodeInfo parsedEpisodeInfo, int tvRageId, SearchCriteriaBase searchCriteria) + private Series GetSeries(ParsedEpisodeInfo parsedEpisodeInfo, int tvdbId, int tvRageId, SearchCriteriaBase searchCriteria) { Series series = null; - var tvdbId = _sceneMappingService.FindTvdbId(parsedEpisodeInfo.SeriesTitle); - - if (tvdbId.HasValue) + var sceneMappingTvdbId = _sceneMappingService.FindTvdbId(parsedEpisodeInfo.SeriesTitle); + if (sceneMappingTvdbId.HasValue) { - if (searchCriteria != null && searchCriteria.Series.TvdbId == tvdbId) + if (searchCriteria != null && searchCriteria.Series.TvdbId == sceneMappingTvdbId.Value) { return searchCriteria.Series; } - series = _seriesService.FindByTvdbId(tvdbId.Value); + series = _seriesService.FindByTvdbId(sceneMappingTvdbId.Value); if (series == null) { @@ -382,6 +384,12 @@ namespace NzbDrone.Core.Parser return searchCriteria.Series; } + if (tvdbId > 0 && tvdbId == searchCriteria.Series.TvdbId) + { + //TODO: If series is found by TvdbId, we should report it as a scene naming exception, since it will fail to import + return searchCriteria.Series; + } + if (tvRageId > 0 && tvRageId == searchCriteria.Series.TvRageId) { //TODO: If series is found by TvRageId, we should report it as a scene naming exception, since it will fail to import @@ -391,6 +399,12 @@ namespace NzbDrone.Core.Parser series = _seriesService.FindByTitle(parsedEpisodeInfo.SeriesTitle); + if (series == null && tvdbId > 0) + { + //TODO: If series is found by TvdbId, we should report it as a scene naming exception, since it will fail to import + series = _seriesService.FindByTvdbId(tvdbId); + } + if (series == null && tvRageId > 0) { //TODO: If series is found by TvRageId, we should report it as a scene naming exception, since it will fail to import From 88ce0ec487ddbd4214c723cc8b79595945efdeec Mon Sep 17 00:00:00 2001 From: Taloth Saldono Date: Sat, 3 Oct 2015 21:43:03 +0200 Subject: [PATCH 2/5] Missing TvdbId on ReleaseResource. --- src/NzbDrone.Api/Indexers/ReleaseResource.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/NzbDrone.Api/Indexers/ReleaseResource.cs b/src/NzbDrone.Api/Indexers/ReleaseResource.cs index 0e2190603..8eea6748b 100644 --- a/src/NzbDrone.Api/Indexers/ReleaseResource.cs +++ b/src/NzbDrone.Api/Indexers/ReleaseResource.cs @@ -33,6 +33,7 @@ namespace NzbDrone.Api.Indexers public bool Approved { get; set; } public bool TemporarilyRejected { get; set; } public bool Rejected { get; set; } + public int TvdbId { get; set; } public int TvRageId { get; set; } public IEnumerable Rejections { get; set; } public DateTime PublishDate { get; set; } From 1ad1d73c91d4bdc897431044bd9b28934e44d90a Mon Sep 17 00:00:00 2001 From: Taloth Saldono Date: Fri, 9 Oct 2015 20:56:40 +0200 Subject: [PATCH 3/5] Added tiered indexer requests to support fallback to wildcard queries. --- .../NewznabRequestGeneratorFixture.cs | 76 +++++++--- .../IndexerTests/SeasonSearchFixture.cs | 5 +- .../BitMeTv/BitMeTvRequestGenerator.cs | 26 ++-- .../BroadcastheNetRequestGenerator.cs | 56 +++---- .../Indexers/Fanzub/FanzubRequestGenerator.cs | 26 ++-- .../Indexers/HDBits/HDBitsRequestGenerator.cs | 39 ++--- src/NzbDrone.Core/Indexers/HttpIndexerBase.cs | 66 ++++---- .../Indexers/IIndexerRequestGenerator.cs | 14 +- .../IPTorrents/IPTorrentsRequestGenerator.cs | 26 ++-- .../Indexers/IndexerPageableRequest.cs | 25 ++++ .../Indexers/IndexerPageableRequestChain.cs | 51 +++++++ .../KickassTorrentsRequestGenerator.cs | 38 ++--- .../Newznab/NewznabRequestGenerator.cs | 141 +++++++----------- .../Indexers/Nyaa/NyaaRequestGenerator.cs | 32 ++-- .../Omgwtfnzbs/OmgwtfnzbsRequestGenerator.cs | 34 ++--- .../Indexers/Rarbg/RarbgRequestGenerator.cs | 32 ++-- .../Indexers/RssIndexerRequestGenerator.cs | 25 ++-- .../TitansOfTv/TitansOfTvRequestGenerator.cs | 40 ++--- .../TorrentRssIndexerRequestGenerator.cs | 26 ++-- .../TorrentRss/TorrentRssSettingsDetector.cs | 2 +- .../TorrentleechRequestGenerator.cs | 26 ++-- src/NzbDrone.Core/NzbDrone.Core.csproj | 2 + 22 files changed, 448 insertions(+), 360 deletions(-) create mode 100644 src/NzbDrone.Core/Indexers/IndexerPageableRequest.cs create mode 100644 src/NzbDrone.Core/Indexers/IndexerPageableRequestChain.cs diff --git a/src/NzbDrone.Core.Test/IndexerTests/NewznabTests/NewznabRequestGeneratorFixture.cs b/src/NzbDrone.Core.Test/IndexerTests/NewznabTests/NewznabRequestGeneratorFixture.cs index 66cc059b3..20f7f70ea 100644 --- a/src/NzbDrone.Core.Test/IndexerTests/NewznabTests/NewznabRequestGeneratorFixture.cs +++ b/src/NzbDrone.Core.Test/IndexerTests/NewznabTests/NewznabRequestGeneratorFixture.cs @@ -53,9 +53,9 @@ namespace NzbDrone.Core.Test.IndexerTests.NewznabTests { var results = Subject.GetRecentRequests(); - results.Should().HaveCount(1); + results.GetAllTiers().Should().HaveCount(1); - var page = results.First().First(); + var page = results.GetAllTiers().First().First(); page.Url.Query.Should().Contain("&cat=1,2,3,4&"); } @@ -67,9 +67,9 @@ namespace NzbDrone.Core.Test.IndexerTests.NewznabTests var results = Subject.GetRecentRequests(); - results.Should().HaveCount(1); + results.GetAllTiers().Should().HaveCount(1); - var page = results.First().First(); + var page = results.GetAllTiers().First().First(); page.Url.Query.Should().Contain("&cat=1,2,3,4&"); } @@ -79,9 +79,9 @@ namespace NzbDrone.Core.Test.IndexerTests.NewznabTests { var results = Subject.GetSearchRequests(_animeSearchCriteria); - results.Should().HaveCount(1); + results.GetAllTiers().Should().HaveCount(1); - var page = results.First().First(); + var page = results.GetAllTiers().First().First(); page.Url.Query.Should().Contain("&cat=3,4&"); } @@ -91,9 +91,9 @@ namespace NzbDrone.Core.Test.IndexerTests.NewznabTests { var results = Subject.GetSearchRequests(_animeSearchCriteria); - results.Should().HaveCount(1); + results.GetAllTiers().Should().HaveCount(1); - var page = results.First().First(); + var page = results.GetAllTiers().First().First(); page.Url.Query.Should().Contain("?t=search&"); } @@ -103,9 +103,9 @@ namespace NzbDrone.Core.Test.IndexerTests.NewznabTests { var results = Subject.GetSearchRequests(_animeSearchCriteria); - results.Should().HaveCount(1); + results.GetAllTiers().Should().HaveCount(1); - var pages = results.First().Take(3).ToList(); + var pages = results.GetAllTiers().First().Take(3).ToList(); pages[0].Url.Query.Should().Contain("&offset=0&"); pages[1].Url.Query.Should().Contain("&offset=100&"); @@ -117,9 +117,9 @@ namespace NzbDrone.Core.Test.IndexerTests.NewznabTests { var results = Subject.GetSearchRequests(_animeSearchCriteria); - results.Should().HaveCount(1); + results.GetAllTiers().Should().HaveCount(1); - var pages = results.First().Take(500).ToList(); + var pages = results.GetAllTiers().First().Take(500).ToList(); pages.Count.Should().BeLessThan(500); } @@ -131,9 +131,9 @@ namespace NzbDrone.Core.Test.IndexerTests.NewznabTests var results = Subject.GetSearchRequests(_singleEpisodeSearchCriteria); - results.Should().HaveCount(1); + results.GetAllTiers().Should().HaveCount(1); - var page = results.First().First(); + var page = results.GetAllTiers().First().First(); page.Url.Query.Should().NotContain("rid=10"); page.Url.Query.Should().Contain("q=Monkey"); @@ -143,9 +143,9 @@ namespace NzbDrone.Core.Test.IndexerTests.NewznabTests public void should_search_by_rid_if_supported() { var results = Subject.GetSearchRequests(_singleEpisodeSearchCriteria); - results.Should().HaveCount(1); + results.GetTier(0).Should().HaveCount(1); - var page = results.First().First(); + var page = results.GetAllTiers().First().First(); page.Url.Query.Should().Contain("rid=10"); } @@ -156,10 +156,9 @@ namespace NzbDrone.Core.Test.IndexerTests.NewznabTests _capabilities.SupportedTvSearchParameters = new[] { "q", "season", "ep" }; var results = Subject.GetSearchRequests(_singleEpisodeSearchCriteria); + results.GetTier(0).Should().HaveCount(1); - results.Should().HaveCount(1); - - var page = results.First().First(); + var page = results.GetAllTiers().First().First(); page.Url.Query.Should().NotContain("rid=10"); page.Url.Query.Should().Contain("q=Monkey"); @@ -171,9 +170,9 @@ namespace NzbDrone.Core.Test.IndexerTests.NewznabTests _capabilities.SupportedTvSearchParameters = new[] { "q", "tvdbid", "season", "ep" }; var results = Subject.GetSearchRequests(_singleEpisodeSearchCriteria); - results.Should().HaveCount(1); + results.GetTier(0).Should().HaveCount(1); - var page = results.First().First(); + var page = results.GetAllTiers().First().First(); page.Url.Query.Should().Contain("tvdbid=20"); } @@ -184,12 +183,43 @@ namespace NzbDrone.Core.Test.IndexerTests.NewznabTests _capabilities.SupportedTvSearchParameters = new[] { "q", "tvdbid", "rid", "season", "ep" }; var results = Subject.GetSearchRequests(_singleEpisodeSearchCriteria); - results.Should().HaveCount(1); + results.GetTier(0).Should().HaveCount(1); - var page = results.First().First(); + var page = results.GetAllTiers().First().First(); page.Url.Query.Should().Contain("tvdbid=20"); page.Url.Query.Should().NotContain("rid=10"); } + + [Test] + public void should_use_aggregrated_id_search_if_supported() + { + _capabilities.SupportedTvSearchParameters = new[] { "q", "tvdbid", "rid", "season", "ep" }; + _capabilities.SupportsAggregateIdSearch = true; + + var results = Subject.GetSearchRequests(_singleEpisodeSearchCriteria); + results.GetTier(0).Should().HaveCount(1); + + var page = results.GetTier(0).First().First(); + + page.Url.Query.Should().Contain("tvdbid=20"); + page.Url.Query.Should().Contain("rid=10"); + } + + [Test] + public void should_fallback_to_q() + { + _capabilities.SupportedTvSearchParameters = new[] { "q", "tvdbid", "rid", "season", "ep" }; + _capabilities.SupportsAggregateIdSearch = true; + + var results = Subject.GetSearchRequests(_singleEpisodeSearchCriteria); + results.Tiers.Should().Be(2); + + var pageTier2 = results.GetTier(1).First().First(); + + pageTier2.Url.Query.Should().NotContain("tvdbid=20"); + pageTier2.Url.Query.Should().NotContain("rid=10"); + pageTier2.Url.Query.Should().Contain("q="); + } } } diff --git a/src/NzbDrone.Core.Test/IndexerTests/SeasonSearchFixture.cs b/src/NzbDrone.Core.Test/IndexerTests/SeasonSearchFixture.cs index 1244814d6..075bb73e2 100644 --- a/src/NzbDrone.Core.Test/IndexerTests/SeasonSearchFixture.cs +++ b/src/NzbDrone.Core.Test/IndexerTests/SeasonSearchFixture.cs @@ -43,8 +43,11 @@ namespace NzbDrone.Core.Test.IndexerTests .With(v => v.HttpRequest.Method = HttpMethod.GET) .Build(); + var pageable = new IndexerPageableRequestChain(); + pageable.Add(requests); + requestGenerator.Setup(s => s.GetSearchRequests(It.IsAny())) - .Returns(new List> { requests }); + .Returns(pageable); var parser = Mocker.GetMock(); Subject._parser = parser.Object; diff --git a/src/NzbDrone.Core/Indexers/BitMeTv/BitMeTvRequestGenerator.cs b/src/NzbDrone.Core/Indexers/BitMeTv/BitMeTvRequestGenerator.cs index 826e4537f..ff9165b6a 100644 --- a/src/NzbDrone.Core/Indexers/BitMeTv/BitMeTvRequestGenerator.cs +++ b/src/NzbDrone.Core/Indexers/BitMeTv/BitMeTvRequestGenerator.cs @@ -10,38 +10,38 @@ namespace NzbDrone.Core.Indexers.BitMeTv { public BitMeTvSettings Settings { get; set; } - public virtual IList> GetRecentRequests() + public virtual IndexerPageableRequestChain GetRecentRequests() { - var pageableRequests = new List>(); + var pageableRequests = new IndexerPageableRequestChain(); - pageableRequests.AddIfNotNull(GetRssRequests()); + pageableRequests.Add(GetRssRequests()); return pageableRequests; } - public virtual IList> GetSearchRequests(SingleEpisodeSearchCriteria searchCriteria) + public virtual IndexerPageableRequestChain GetSearchRequests(SingleEpisodeSearchCriteria searchCriteria) { - return new List>(); + return new IndexerPageableRequestChain(); } - public virtual IList> GetSearchRequests(SeasonSearchCriteria searchCriteria) + public virtual IndexerPageableRequestChain GetSearchRequests(SeasonSearchCriteria searchCriteria) { - return new List>(); + return new IndexerPageableRequestChain(); } - public virtual IList> GetSearchRequests(DailyEpisodeSearchCriteria searchCriteria) + public virtual IndexerPageableRequestChain GetSearchRequests(DailyEpisodeSearchCriteria searchCriteria) { - return new List>(); + return new IndexerPageableRequestChain(); } - public virtual IList> GetSearchRequests(AnimeEpisodeSearchCriteria searchCriteria) + public virtual IndexerPageableRequestChain GetSearchRequests(AnimeEpisodeSearchCriteria searchCriteria) { - return new List>(); + return new IndexerPageableRequestChain(); } - public virtual IList> GetSearchRequests(SpecialEpisodeSearchCriteria searchCriteria) + public virtual IndexerPageableRequestChain GetSearchRequests(SpecialEpisodeSearchCriteria searchCriteria) { - return new List>(); + return new IndexerPageableRequestChain(); } private IEnumerable GetRssRequests() diff --git a/src/NzbDrone.Core/Indexers/BroadcastheNet/BroadcastheNetRequestGenerator.cs b/src/NzbDrone.Core/Indexers/BroadcastheNet/BroadcastheNetRequestGenerator.cs index 24fb674c9..7a8034440 100644 --- a/src/NzbDrone.Core/Indexers/BroadcastheNet/BroadcastheNetRequestGenerator.cs +++ b/src/NzbDrone.Core/Indexers/BroadcastheNet/BroadcastheNetRequestGenerator.cs @@ -19,18 +19,18 @@ namespace NzbDrone.Core.Indexers.BroadcastheNet PageSize = 100; } - public virtual IList> GetRecentRequests() + public virtual IndexerPageableRequestChain GetRecentRequests() { - var pageableRequests = new List>(); + var pageableRequests = new IndexerPageableRequestChain(); - pageableRequests.AddIfNotNull(GetPagedRequests(MaxPages, null)); + pageableRequests.Add(GetPagedRequests(MaxPages, null)); return pageableRequests; } - public virtual IList> GetSearchRequests(SingleEpisodeSearchCriteria searchCriteria) + public virtual IndexerPageableRequestChain GetSearchRequests(SingleEpisodeSearchCriteria searchCriteria) { - var pageableRequest = new List>(); + var pageableRequests = new IndexerPageableRequestChain(); var parameters = new BroadcastheNetTorrentQuery(); if (AddSeriesSearchParameters(parameters, searchCriteria)) @@ -42,7 +42,7 @@ namespace NzbDrone.Core.Indexers.BroadcastheNet parameters.Category = "Episode"; parameters.Name = string.Format("S{0:00}E{1:00}", episode.SeasonNumber, episode.EpisodeNumber); - pageableRequest.AddIfNotNull(GetPagedRequests(MaxPages, parameters)); + pageableRequests.Add(GetPagedRequests(MaxPages, parameters)); } foreach (var seasonNumber in searchCriteria.Episodes.Select(v => v.SeasonNumber).Distinct()) @@ -52,42 +52,42 @@ namespace NzbDrone.Core.Indexers.BroadcastheNet parameters.Category = "Season"; parameters.Name = string.Format("Season {0}", seasonNumber); - pageableRequest.AddIfNotNull(GetPagedRequests(MaxPages, parameters)); + pageableRequests.Add(GetPagedRequests(MaxPages, parameters)); } } - return pageableRequest; + return pageableRequests; } - public virtual IList> GetSearchRequests(SeasonSearchCriteria searchCriteria) + public virtual IndexerPageableRequestChain GetSearchRequests(SeasonSearchCriteria searchCriteria) { - var pageableRequest = new List>(); + var pageableRequests = new IndexerPageableRequestChain(); var parameters = new BroadcastheNetTorrentQuery(); if (AddSeriesSearchParameters(parameters, searchCriteria)) { foreach (var seasonNumber in searchCriteria.Episodes.Select(v => v.SeasonNumber).Distinct()) { - parameters.Category = "Episode"; - parameters.Name = string.Format("S{0:00}E%", seasonNumber); + parameters.Category = "Season"; + parameters.Name = string.Format("Season {0}", seasonNumber); - pageableRequest.AddIfNotNull(GetPagedRequests(MaxPages, parameters)); + pageableRequests.Add(GetPagedRequests(MaxPages, parameters)); parameters = parameters.Clone(); - parameters.Category = "Season"; - parameters.Name = string.Format("Season {0}", seasonNumber); + parameters.Category = "Episode"; + parameters.Name = string.Format("S{0:00}E%", seasonNumber); - pageableRequest.AddIfNotNull(GetPagedRequests(MaxPages, parameters)); + pageableRequests.Add(GetPagedRequests(MaxPages, parameters)); } } - return pageableRequest; + return pageableRequests; } - public virtual IList> GetSearchRequests(DailyEpisodeSearchCriteria searchCriteria) + public virtual IndexerPageableRequestChain GetSearchRequests(DailyEpisodeSearchCriteria searchCriteria) { - var pageableRequest = new List>(); + var pageableRequests = new IndexerPageableRequestChain(); var parameters = new BroadcastheNetTorrentQuery(); if (AddSeriesSearchParameters(parameters, searchCriteria)) @@ -95,15 +95,15 @@ namespace NzbDrone.Core.Indexers.BroadcastheNet parameters.Category = "Episode"; parameters.Name = string.Format("{0:yyyy}.{0:MM}.{0:dd}", searchCriteria.AirDate); - pageableRequest.AddIfNotNull(GetPagedRequests(MaxPages, parameters)); + pageableRequests.Add(GetPagedRequests(MaxPages, parameters)); } - return pageableRequest; + return pageableRequests; } - public virtual IList> GetSearchRequests(AnimeEpisodeSearchCriteria searchCriteria) + public virtual IndexerPageableRequestChain GetSearchRequests(AnimeEpisodeSearchCriteria searchCriteria) { - var pageableRequest = new List>(); + var pageableRequests = new IndexerPageableRequestChain(); var parameters = new BroadcastheNetTorrentQuery(); if (AddSeriesSearchParameters(parameters, searchCriteria)) @@ -115,7 +115,7 @@ namespace NzbDrone.Core.Indexers.BroadcastheNet parameters.Category = "Episode"; parameters.Name = string.Format("S{0:00}E{1:00}", episode.SeasonNumber, episode.EpisodeNumber); - pageableRequest.AddIfNotNull(GetPagedRequests(MaxPages, parameters)); + pageableRequests.Add(GetPagedRequests(MaxPages, parameters)); } foreach (var seasonNumber in searchCriteria.Episodes.Select(v => v.SeasonNumber).Distinct()) @@ -125,16 +125,16 @@ namespace NzbDrone.Core.Indexers.BroadcastheNet parameters.Category = "Season"; parameters.Name = string.Format("Season {0}", seasonNumber); - pageableRequest.AddIfNotNull(GetPagedRequests(MaxPages, parameters)); + pageableRequests.Add(GetPagedRequests(MaxPages, parameters)); } } - return pageableRequest; + return pageableRequests; } - public virtual IList> GetSearchRequests(SpecialEpisodeSearchCriteria searchCriteria) + public virtual IndexerPageableRequestChain GetSearchRequests(SpecialEpisodeSearchCriteria searchCriteria) { - return new List>(); + return new IndexerPageableRequestChain(); } private bool AddSeriesSearchParameters(BroadcastheNetTorrentQuery parameters, SearchCriteriaBase searchCriteria) diff --git a/src/NzbDrone.Core/Indexers/Fanzub/FanzubRequestGenerator.cs b/src/NzbDrone.Core/Indexers/Fanzub/FanzubRequestGenerator.cs index 89bf9fc0a..b16d8d620 100644 --- a/src/NzbDrone.Core/Indexers/Fanzub/FanzubRequestGenerator.cs +++ b/src/NzbDrone.Core/Indexers/Fanzub/FanzubRequestGenerator.cs @@ -21,33 +21,33 @@ namespace NzbDrone.Core.Indexers.Fanzub PageSize = 100; } - public virtual IList> GetRecentRequests() + public virtual IndexerPageableRequestChain GetRecentRequests() { - var pageableRequests = new List>(); + var pageableRequests = new IndexerPageableRequestChain(); - pageableRequests.AddIfNotNull(GetPagedRequests(null)); + pageableRequests.Add(GetPagedRequests(null)); return pageableRequests; } - public virtual IList> GetSearchRequests(SingleEpisodeSearchCriteria searchCriteria) + public virtual IndexerPageableRequestChain GetSearchRequests(SingleEpisodeSearchCriteria searchCriteria) { - return new List>(); + return new IndexerPageableRequestChain(); } - public virtual IList> GetSearchRequests(SeasonSearchCriteria searchCriteria) + public virtual IndexerPageableRequestChain GetSearchRequests(SeasonSearchCriteria searchCriteria) { - return new List>(); + return new IndexerPageableRequestChain(); } - public virtual IList> GetSearchRequests(DailyEpisodeSearchCriteria searchCriteria) + public virtual IndexerPageableRequestChain GetSearchRequests(DailyEpisodeSearchCriteria searchCriteria) { - return new List>(); + return new IndexerPageableRequestChain(); } - public virtual IList> GetSearchRequests(AnimeEpisodeSearchCriteria searchCriteria) + public virtual IndexerPageableRequestChain GetSearchRequests(AnimeEpisodeSearchCriteria searchCriteria) { - var pageableRequests = new List>(); + var pageableRequests = new IndexerPageableRequestChain(); var searchTitles = searchCriteria.QueryTitles.SelectMany(v => GetTitleSearchStrings(v, searchCriteria.AbsoluteEpisodeNumber)).ToList(); @@ -56,9 +56,9 @@ namespace NzbDrone.Core.Indexers.Fanzub return pageableRequests; } - public virtual IList> GetSearchRequests(SpecialEpisodeSearchCriteria searchCriteria) + public virtual IndexerPageableRequestChain GetSearchRequests(SpecialEpisodeSearchCriteria searchCriteria) { - return new List>(); + return new IndexerPageableRequestChain(); } private IEnumerable GetPagedRequests(string query) diff --git a/src/NzbDrone.Core/Indexers/HDBits/HDBitsRequestGenerator.cs b/src/NzbDrone.Core/Indexers/HDBits/HDBitsRequestGenerator.cs index bf3979cad..9adcf1c46 100644 --- a/src/NzbDrone.Core/Indexers/HDBits/HDBitsRequestGenerator.cs +++ b/src/NzbDrone.Core/Indexers/HDBits/HDBitsRequestGenerator.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using NzbDrone.Common.Extensions; using NzbDrone.Common.Http; using NzbDrone.Common.Serializer; using NzbDrone.Core.IndexerSearch.Definitions; @@ -11,18 +12,18 @@ namespace NzbDrone.Core.Indexers.HDBits { public HDBitsSettings Settings { get; set; } - public IList> GetRecentRequests() + public virtual IndexerPageableRequestChain GetRecentRequests() { - var pageableRequests = new List>(); + var pageableRequests = new IndexerPageableRequestChain(); pageableRequests.Add(GetRequest(new TorrentQuery())); return pageableRequests; } - public IList> GetSearchRequests(AnimeEpisodeSearchCriteria searchCriteria) + public virtual IndexerPageableRequestChain GetSearchRequests(AnimeEpisodeSearchCriteria searchCriteria) { - var requests = new List>(); + var pageableRequests = new IndexerPageableRequestChain(); var queryBase = new TorrentQuery(); if (TryAddSearchParameters(queryBase, searchCriteria)) @@ -36,32 +37,32 @@ namespace NzbDrone.Core.Indexers.HDBits } } - return requests; + return pageableRequests; } - public IList> GetSearchRequests(SpecialEpisodeSearchCriteria searchCriteria) + public virtual IndexerPageableRequestChain GetSearchRequests(SpecialEpisodeSearchCriteria searchCriteria) { - return new List>(); + return new IndexerPageableRequestChain(); } - public IList> GetSearchRequests(DailyEpisodeSearchCriteria searchCriteria) + public virtual IndexerPageableRequestChain GetSearchRequests(DailyEpisodeSearchCriteria searchCriteria) { - var requests = new List>(); + var pageableRequests = new IndexerPageableRequestChain(); var query = new TorrentQuery(); if (TryAddSearchParameters(query, searchCriteria)) { query.Search = string.Format("{0:yyyy}-{0:MM}-{0:dd}", searchCriteria.AirDate); - requests.Add(GetRequest(query)); + pageableRequests.Add(GetRequest(query)); } - return requests; + return pageableRequests; } - public IList> GetSearchRequests(SeasonSearchCriteria searchCriteria) + public virtual IndexerPageableRequestChain GetSearchRequests(SeasonSearchCriteria searchCriteria) { - var requests = new List>(); + var pageableRequests = new IndexerPageableRequestChain(); var queryBase = new TorrentQuery(); if (TryAddSearchParameters(queryBase, searchCriteria)) @@ -72,16 +73,16 @@ namespace NzbDrone.Core.Indexers.HDBits query.TvdbInfo.Season = seasonNumber; - requests.Add(GetRequest(query)); + pageableRequests.Add(GetRequest(query)); } } - return requests; + return pageableRequests; } - public IList> GetSearchRequests(SingleEpisodeSearchCriteria searchCriteria) + public virtual IndexerPageableRequestChain GetSearchRequests(SingleEpisodeSearchCriteria searchCriteria) { - var requests = new List>(); + var pageableRequests = new IndexerPageableRequestChain(); var queryBase = new TorrentQuery(); if (TryAddSearchParameters(queryBase, searchCriteria)) @@ -93,11 +94,11 @@ namespace NzbDrone.Core.Indexers.HDBits query.TvdbInfo.Season = episode.SeasonNumber; query.TvdbInfo.Episode = episode.EpisodeNumber; - requests.Add(GetRequest(query)); + pageableRequests.Add(GetRequest(query)); } } - return requests; + return pageableRequests; } private bool TryAddSearchParameters(TorrentQuery query, SearchCriteriaBase searchCriteria) diff --git a/src/NzbDrone.Core/Indexers/HttpIndexerBase.cs b/src/NzbDrone.Core/Indexers/HttpIndexerBase.cs index b4fdee029..5c3eb3e6d 100644 --- a/src/NzbDrone.Core/Indexers/HttpIndexerBase.cs +++ b/src/NzbDrone.Core/Indexers/HttpIndexerBase.cs @@ -111,7 +111,7 @@ namespace NzbDrone.Core.Indexers return FetchReleases(generator.GetSearchRequests(searchCriteria)); } - protected virtual IList FetchReleases(IList> pageableRequests, bool isRecent = false) + protected virtual IList FetchReleases(IndexerPageableRequestChain pageableRequestChain, bool isRecent = false) { var releases = new List(); var url = string.Empty; @@ -127,51 +127,61 @@ namespace NzbDrone.Core.Indexers lastReleaseInfo = _indexerStatusService.GetLastRssSyncReleaseInfo(Definition.Id); } - foreach (var pageableRequest in pageableRequests) + for (int i = 0; i < pageableRequestChain.Tiers; i++) { - var pagedReleases = new List(); + var pageableRequests = pageableRequestChain.GetTier(i); - foreach (var request in pageableRequest) + foreach (var pageableRequest in pageableRequests) { - url = request.Url.ToString(); + var pagedReleases = new List(); - var page = FetchPage(request, parser); + foreach (var request in pageableRequest) + { + url = request.Url.ToString(); - pagedReleases.AddRange(page); + var page = FetchPage(request, parser); - if (isRecent && page.Any()) - { - if (lastReleaseInfo == null) + pagedReleases.AddRange(page); + + if (isRecent && page.Any()) { - fullyUpdated = true; - break; + if (lastReleaseInfo == null) + { + fullyUpdated = true; + break; + } + var oldestReleaseDate = page.Select(v => v.PublishDate).Min(); + if (oldestReleaseDate < lastReleaseInfo.PublishDate || page.Any(v => v.DownloadUrl == lastReleaseInfo.DownloadUrl)) + { + fullyUpdated = true; + break; + } + + if (pagedReleases.Count >= MaxNumResultsPerQuery && + oldestReleaseDate < DateTime.UtcNow - TimeSpan.FromHours(24)) + { + fullyUpdated = false; + break; + } } - var oldestReleaseDate = page.Select(v => v.PublishDate).Min(); - if (oldestReleaseDate < lastReleaseInfo.PublishDate || page.Any(v => v.DownloadUrl == lastReleaseInfo.DownloadUrl)) + else if (pagedReleases.Count >= MaxNumResultsPerQuery) { - fullyUpdated = true; break; } - if (pagedReleases.Count >= MaxNumResultsPerQuery && - oldestReleaseDate < DateTime.UtcNow - TimeSpan.FromHours(24)) + if (!IsFullPage(page)) { - fullyUpdated = false; break; } } - else if (pagedReleases.Count >= MaxNumResultsPerQuery) - { - break; - } - if (!IsFullPage(page)) - { - break; - } + releases.AddRange(pagedReleases); } - releases.AddRange(pagedReleases); + if (releases.Any()) + { + break; + } } if (isRecent && !releases.Empty()) @@ -277,7 +287,7 @@ namespace NzbDrone.Core.Indexers { var parser = GetParser(); var generator = GetRequestGenerator(); - var releases = FetchPage(generator.GetRecentRequests().First().First(), parser); + var releases = FetchPage(generator.GetRecentRequests().GetAllTiers().First().First(), parser); if (releases.Empty()) { diff --git a/src/NzbDrone.Core/Indexers/IIndexerRequestGenerator.cs b/src/NzbDrone.Core/Indexers/IIndexerRequestGenerator.cs index 02ef5ee3e..5926af8da 100644 --- a/src/NzbDrone.Core/Indexers/IIndexerRequestGenerator.cs +++ b/src/NzbDrone.Core/Indexers/IIndexerRequestGenerator.cs @@ -5,11 +5,11 @@ namespace NzbDrone.Core.Indexers { public interface IIndexerRequestGenerator { - IList> GetRecentRequests(); - IList> GetSearchRequests(SingleEpisodeSearchCriteria searchCriteria); - IList> GetSearchRequests(SeasonSearchCriteria searchCriteria); - IList> GetSearchRequests(DailyEpisodeSearchCriteria searchCriteria); - IList> GetSearchRequests(AnimeEpisodeSearchCriteria searchCriteria); - IList> GetSearchRequests(SpecialEpisodeSearchCriteria searchCriteria); + IndexerPageableRequestChain GetRecentRequests(); + IndexerPageableRequestChain GetSearchRequests(SingleEpisodeSearchCriteria searchCriteria); + IndexerPageableRequestChain GetSearchRequests(SeasonSearchCriteria searchCriteria); + IndexerPageableRequestChain GetSearchRequests(DailyEpisodeSearchCriteria searchCriteria); + IndexerPageableRequestChain GetSearchRequests(AnimeEpisodeSearchCriteria searchCriteria); + IndexerPageableRequestChain GetSearchRequests(SpecialEpisodeSearchCriteria searchCriteria); } -} +} \ No newline at end of file diff --git a/src/NzbDrone.Core/Indexers/IPTorrents/IPTorrentsRequestGenerator.cs b/src/NzbDrone.Core/Indexers/IPTorrents/IPTorrentsRequestGenerator.cs index d69adc270..c9f238e38 100644 --- a/src/NzbDrone.Core/Indexers/IPTorrents/IPTorrentsRequestGenerator.cs +++ b/src/NzbDrone.Core/Indexers/IPTorrents/IPTorrentsRequestGenerator.cs @@ -9,38 +9,38 @@ namespace NzbDrone.Core.Indexers.IPTorrents { public IPTorrentsSettings Settings { get; set; } - public virtual IList> GetRecentRequests() + public virtual IndexerPageableRequestChain GetRecentRequests() { - var pageableRequests = new List>(); + var pageableRequests = new IndexerPageableRequestChain(); - pageableRequests.AddIfNotNull(GetRssRequests()); + pageableRequests.Add(GetRssRequests()); return pageableRequests; } - public virtual IList> GetSearchRequests(SingleEpisodeSearchCriteria searchCriteria) + public virtual IndexerPageableRequestChain GetSearchRequests(SingleEpisodeSearchCriteria searchCriteria) { - return new List>(); + return new IndexerPageableRequestChain(); } - public virtual IList> GetSearchRequests(SeasonSearchCriteria searchCriteria) + public virtual IndexerPageableRequestChain GetSearchRequests(SeasonSearchCriteria searchCriteria) { - return new List>(); + return new IndexerPageableRequestChain(); } - public virtual IList> GetSearchRequests(DailyEpisodeSearchCriteria searchCriteria) + public virtual IndexerPageableRequestChain GetSearchRequests(DailyEpisodeSearchCriteria searchCriteria) { - return new List>(); + return new IndexerPageableRequestChain(); } - public virtual IList> GetSearchRequests(AnimeEpisodeSearchCriteria searchCriteria) + public virtual IndexerPageableRequestChain GetSearchRequests(AnimeEpisodeSearchCriteria searchCriteria) { - return new List>(); + return new IndexerPageableRequestChain(); } - public virtual IList> GetSearchRequests(SpecialEpisodeSearchCriteria searchCriteria) + public virtual IndexerPageableRequestChain GetSearchRequests(SpecialEpisodeSearchCriteria searchCriteria) { - return new List>(); + return new IndexerPageableRequestChain(); } private IEnumerable GetRssRequests() diff --git a/src/NzbDrone.Core/Indexers/IndexerPageableRequest.cs b/src/NzbDrone.Core/Indexers/IndexerPageableRequest.cs new file mode 100644 index 000000000..dff34143e --- /dev/null +++ b/src/NzbDrone.Core/Indexers/IndexerPageableRequest.cs @@ -0,0 +1,25 @@ +using System.Collections; +using System.Collections.Generic; + +namespace NzbDrone.Core.Indexers +{ + public class IndexerPageableRequest : IEnumerable + { + private readonly IEnumerable _enumerable; + + public IndexerPageableRequest(IEnumerable enumerable) + { + _enumerable = enumerable; + } + + public IEnumerator GetEnumerator() + { + return _enumerable.GetEnumerator(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return _enumerable.GetEnumerator(); + } + } +} diff --git a/src/NzbDrone.Core/Indexers/IndexerPageableRequestChain.cs b/src/NzbDrone.Core/Indexers/IndexerPageableRequestChain.cs new file mode 100644 index 000000000..498f21ec1 --- /dev/null +++ b/src/NzbDrone.Core/Indexers/IndexerPageableRequestChain.cs @@ -0,0 +1,51 @@ +using System.Collections.Generic; +using System.Linq; + +namespace NzbDrone.Core.Indexers +{ + public class IndexerPageableRequestChain + { + private List> _chains; + + public IndexerPageableRequestChain() + { + _chains = new List>(); + _chains.Add(new List()); + } + + public int Tiers + { + get { return _chains.Count; } + } + + public IEnumerable GetAllTiers() + { + return _chains.SelectMany(v => v); + } + + public IEnumerable GetTier(int index) + { + return _chains[index]; + } + + public void Add(IEnumerable request) + { + if (request == null) return; + + _chains.Last().Add(new IndexerPageableRequest(request)); + } + + public void AddTier(IEnumerable request) + { + AddTier(); + Add(request); + } + + public void AddTier() + { + if (_chains.Last().Count == 0) return; + + _chains.Add(new List()); + } + } +} \ No newline at end of file diff --git a/src/NzbDrone.Core/Indexers/KickassTorrents/KickassTorrentsRequestGenerator.cs b/src/NzbDrone.Core/Indexers/KickassTorrents/KickassTorrentsRequestGenerator.cs index b887ec112..b8541e83a 100644 --- a/src/NzbDrone.Core/Indexers/KickassTorrents/KickassTorrentsRequestGenerator.cs +++ b/src/NzbDrone.Core/Indexers/KickassTorrents/KickassTorrentsRequestGenerator.cs @@ -20,28 +20,28 @@ namespace NzbDrone.Core.Indexers.KickassTorrents PageSize = 25; } - public virtual IList> GetRecentRequests() + public virtual IndexerPageableRequestChain GetRecentRequests() { - var pageableRequests = new List>(); + var pageableRequests = new IndexerPageableRequestChain(); - pageableRequests.AddIfNotNull(GetPagedRequests(MaxPages, "tv")); + pageableRequests.Add(GetPagedRequests(MaxPages, "tv")); return pageableRequests; } - public virtual IList> GetSearchRequests(SingleEpisodeSearchCriteria searchCriteria) + public virtual IndexerPageableRequestChain GetSearchRequests(SingleEpisodeSearchCriteria searchCriteria) { - var pageableRequests = new List>(); + var pageableRequests = new IndexerPageableRequestChain(); foreach (var queryTitle in searchCriteria.QueryTitles) { - pageableRequests.AddIfNotNull(GetPagedRequests(MaxPages, "usearch", + pageableRequests.Add(GetPagedRequests(MaxPages, "usearch", PrepareQuery(queryTitle), "category:tv", string.Format("season:{0}", searchCriteria.SeasonNumber), string.Format("episode:{0}", searchCriteria.EpisodeNumber))); - pageableRequests.AddIfNotNull(GetPagedRequests(MaxPages, "usearch", + pageableRequests.Add(GetPagedRequests(MaxPages, "usearch", PrepareQuery(queryTitle), string.Format("S{0:00}E{1:00}", searchCriteria.SeasonNumber, searchCriteria.EpisodeNumber), "category:tv")); @@ -50,18 +50,18 @@ namespace NzbDrone.Core.Indexers.KickassTorrents return pageableRequests; } - public virtual IList> GetSearchRequests(SeasonSearchCriteria searchCriteria) + public virtual IndexerPageableRequestChain GetSearchRequests(SeasonSearchCriteria searchCriteria) { - var pageableRequests = new List>(); + var pageableRequests = new IndexerPageableRequestChain(); foreach (var queryTitle in searchCriteria.QueryTitles) { - pageableRequests.AddIfNotNull(GetPagedRequests(MaxPages, "usearch", + pageableRequests.Add(GetPagedRequests(MaxPages, "usearch", PrepareQuery(queryTitle), "category:tv", string.Format("season:{0}", searchCriteria.SeasonNumber))); - pageableRequests.AddIfNotNull(GetPagedRequests(MaxPages, "usearch", + pageableRequests.Add(GetPagedRequests(MaxPages, "usearch", PrepareQuery(queryTitle), "category:tv", string.Format("S{0:00}", searchCriteria.SeasonNumber))); @@ -70,13 +70,13 @@ namespace NzbDrone.Core.Indexers.KickassTorrents return pageableRequests; } - public virtual IList> GetSearchRequests(DailyEpisodeSearchCriteria searchCriteria) + public virtual IndexerPageableRequestChain GetSearchRequests(DailyEpisodeSearchCriteria searchCriteria) { - var pageableRequests = new List>(); + var pageableRequests = new IndexerPageableRequestChain(); foreach (var queryTitle in searchCriteria.QueryTitles) { - pageableRequests.AddIfNotNull(GetPagedRequests(MaxPages, "usearch", + pageableRequests.Add(GetPagedRequests(MaxPages, "usearch", PrepareQuery(queryTitle), string.Format("{0:yyyy-MM-dd}", searchCriteria.AirDate), "category:tv")); @@ -85,18 +85,18 @@ namespace NzbDrone.Core.Indexers.KickassTorrents return pageableRequests; } - public virtual IList> GetSearchRequests(AnimeEpisodeSearchCriteria searchCriteria) + public virtual IndexerPageableRequestChain GetSearchRequests(AnimeEpisodeSearchCriteria searchCriteria) { - return new List>(); + return new IndexerPageableRequestChain(); } - public virtual IList> GetSearchRequests(SpecialEpisodeSearchCriteria searchCriteria) + public virtual IndexerPageableRequestChain GetSearchRequests(SpecialEpisodeSearchCriteria searchCriteria) { - var pageableRequests = new List>(); + var pageableRequests = new IndexerPageableRequestChain(); foreach (var queryTitle in searchCriteria.EpisodeQueryTitles) { - pageableRequests.AddIfNotNull(GetPagedRequests(MaxPages, "usearch", + pageableRequests.Add(GetPagedRequests(MaxPages, "usearch", PrepareQuery(queryTitle), "category:tv")); } diff --git a/src/NzbDrone.Core/Indexers/Newznab/NewznabRequestGenerator.cs b/src/NzbDrone.Core/Indexers/Newznab/NewznabRequestGenerator.cs index 61ca41b12..c88a1b79f 100644 --- a/src/NzbDrone.Core/Indexers/Newznab/NewznabRequestGenerator.cs +++ b/src/NzbDrone.Core/Indexers/Newznab/NewznabRequestGenerator.cs @@ -72,128 +72,63 @@ namespace NzbDrone.Core.Indexers.Newznab } } - public virtual IList> GetRecentRequests() + public virtual IndexerPageableRequestChain GetRecentRequests() { - var pageableRequests = new List>(); + var pageableRequests = new IndexerPageableRequestChain(); var capabilities = _capabilitiesProvider.GetCapabilities(Settings); if (capabilities.SupportedTvSearchParameters != null) { - pageableRequests.AddIfNotNull(GetPagedRequests(MaxPages, Settings.Categories.Concat(Settings.AnimeCategories), "tvsearch", "")); + pageableRequests.Add(GetPagedRequests(MaxPages, Settings.Categories.Concat(Settings.AnimeCategories), "tvsearch", "")); } return pageableRequests; } - public virtual IList> GetSearchRequests(SingleEpisodeSearchCriteria searchCriteria) + public virtual IndexerPageableRequestChain GetSearchRequests(SingleEpisodeSearchCriteria searchCriteria) { - var pageableRequests = new List>(); + var pageableRequests = new IndexerPageableRequestChain(); - if (searchCriteria.Series.TvdbId > 0 && SupportsTvdbSearch) - { - pageableRequests.AddIfNotNull(GetPagedRequests(MaxPages, Settings.Categories, "tvsearch", - string.Format("&tvdbid={0}&season={1}&ep={2}", - searchCriteria.Series.TvdbId, - searchCriteria.SeasonNumber, - searchCriteria.EpisodeNumber))); - } - else if (searchCriteria.Series.TvRageId > 0 && SupportsTvRageSearch) - { - pageableRequests.AddIfNotNull(GetPagedRequests(MaxPages, Settings.Categories, "tvsearch", - string.Format("&rid={0}&season={1}&ep={2}", - searchCriteria.Series.TvRageId, + AddTvIdPageableRequests(pageableRequests, MaxPages, Settings.Categories, searchCriteria, + string.Format("&season={0}&ep={1}", searchCriteria.SeasonNumber, - searchCriteria.EpisodeNumber))); - } - else if (SupportsTvSearch) - { - foreach (var queryTitle in searchCriteria.QueryTitles) - { - pageableRequests.AddIfNotNull(GetPagedRequests(MaxPages, Settings.Categories, "tvsearch", - string.Format("&q={0}&season={1}&ep={2}", - NewsnabifyTitle(queryTitle), - searchCriteria.SeasonNumber, - searchCriteria.EpisodeNumber))); - } - } + searchCriteria.EpisodeNumber)); return pageableRequests; } - public virtual IList> GetSearchRequests(SeasonSearchCriteria searchCriteria) + public virtual IndexerPageableRequestChain GetSearchRequests(SeasonSearchCriteria searchCriteria) { - var pageableRequests = new List>(); + var pageableRequests = new IndexerPageableRequestChain(); - if (searchCriteria.Series.TvdbId > 0 && SupportsTvdbSearch) - { - pageableRequests.AddIfNotNull(GetPagedRequests(MaxPages, Settings.Categories, "tvsearch", - string.Format("&tvdbid={0}&season={1}", - searchCriteria.Series.TvdbId, - searchCriteria.SeasonNumber))); - } - else if (searchCriteria.Series.TvRageId > 0 && SupportsTvRageSearch) - { - pageableRequests.AddIfNotNull(GetPagedRequests(MaxPages, Settings.Categories, "tvsearch", - string.Format("&rid={0}&season={1}", - searchCriteria.Series.TvRageId, - searchCriteria.SeasonNumber))); - } - else if (SupportsTvSearch) - { - foreach (var queryTitle in searchCriteria.QueryTitles) - { - pageableRequests.AddIfNotNull(GetPagedRequests(MaxPages, Settings.Categories, "tvsearch", - string.Format("&q={0}&season={1}", - NewsnabifyTitle(queryTitle), - searchCriteria.SeasonNumber))); - } - } + AddTvIdPageableRequests(pageableRequests, MaxPages, Settings.Categories, searchCriteria, + string.Format("&season={0}", + searchCriteria.SeasonNumber)); return pageableRequests; } - public virtual IList> GetSearchRequests(DailyEpisodeSearchCriteria searchCriteria) + public virtual IndexerPageableRequestChain GetSearchRequests(DailyEpisodeSearchCriteria searchCriteria) { - var pageableRequests = new List>(); + var pageableRequests = new IndexerPageableRequestChain(); - if (searchCriteria.Series.TvdbId > 0 && SupportsTvdbSearch) - { - pageableRequests.AddIfNotNull(GetPagedRequests(MaxPages, Settings.Categories, "tvsearch", - string.Format("&tvdbid={0}&season={1:yyyy}&ep={1:MM}/{1:dd}", - searchCriteria.Series.TvdbId, - searchCriteria.AirDate))); - } - else if (searchCriteria.Series.TvRageId > 0 && SupportsTvRageSearch) - { - pageableRequests.AddIfNotNull(GetPagedRequests(MaxPages, Settings.Categories, "tvsearch", - string.Format("&rid={0}&season={1:yyyy}&ep={1:MM}/{1:dd}", - searchCriteria.Series.TvRageId, - searchCriteria.AirDate))); - } - else if (SupportsTvSearch) - { - foreach (var queryTitle in searchCriteria.QueryTitles) - { - pageableRequests.AddIfNotNull(GetPagedRequests(MaxPages, Settings.Categories, "tvsearch", - string.Format("&q={0}&season={1:yyyy}&ep={1:MM}/{1:dd}", - NewsnabifyTitle(queryTitle), - searchCriteria.AirDate))); - } - } + AddTvIdPageableRequests(pageableRequests, MaxPages, Settings.Categories, searchCriteria, + string.Format("&season={0:yyyy}&ep={0:MM}/{0:dd}", + searchCriteria.AirDate)); return pageableRequests; } - public virtual IList> GetSearchRequests(AnimeEpisodeSearchCriteria searchCriteria) + public virtual IndexerPageableRequestChain GetSearchRequests(AnimeEpisodeSearchCriteria searchCriteria) { - var pageableRequests = new List>(); + var pageableRequests = new IndexerPageableRequestChain(); if (SupportsSearch) { foreach (var queryTitle in searchCriteria.QueryTitles) { - pageableRequests.AddIfNotNull(GetPagedRequests(MaxPages, Settings.AnimeCategories, "search", + pageableRequests.Add(GetPagedRequests(MaxPages, Settings.AnimeCategories, "search", string.Format("&q={0}+{1:00}", NewsnabifyTitle(queryTitle), searchCriteria.AbsoluteEpisodeNumber))); @@ -203,9 +138,9 @@ namespace NzbDrone.Core.Indexers.Newznab return pageableRequests; } - public virtual IList> GetSearchRequests(SpecialEpisodeSearchCriteria searchCriteria) + public virtual IndexerPageableRequestChain GetSearchRequests(SpecialEpisodeSearchCriteria searchCriteria) { - var pageableRequests = new List>(); + var pageableRequests = new IndexerPageableRequestChain(); if (SupportsSearch) { @@ -214,7 +149,7 @@ namespace NzbDrone.Core.Indexers.Newznab var query = queryTitle.Replace('+', ' '); query = System.Web.HttpUtility.UrlEncode(query); - pageableRequests.AddIfNotNull(GetPagedRequests(MaxPages, Settings.Categories.Concat(Settings.AnimeCategories), "search", + pageableRequests.Add(GetPagedRequests(MaxPages, Settings.Categories.Concat(Settings.AnimeCategories), "search", string.Format("&q={0}", query))); } @@ -223,6 +158,34 @@ namespace NzbDrone.Core.Indexers.Newznab return pageableRequests; } + private void AddTvIdPageableRequests(IndexerPageableRequestChain chain, int maxPages, IEnumerable categories, SearchCriteriaBase searchCriteria, string parameters) + { + { + if (searchCriteria.Series.TvdbId > 0 && SupportsTvdbSearch) + { + chain.Add(GetPagedRequests(maxPages, categories, "tvsearch", + string.Format("&tvdbid={0}{1}", searchCriteria.Series.TvdbId, parameters))); + } + else if (searchCriteria.Series.TvRageId > 0 && SupportsTvRageSearch) + { + chain.Add(GetPagedRequests(maxPages, categories, "tvsearch", + string.Format("&rid={0}{1}", searchCriteria.Series.TvRageId, parameters))); + } + } + + if (SupportsTvSearch) + { + chain.AddTier(); + foreach (var queryTitle in searchCriteria.QueryTitles) + { + chain.Add(GetPagedRequests(MaxPages, Settings.Categories, "tvsearch", + string.Format("&q={0}{1}", + NewsnabifyTitle(queryTitle), + parameters))); + } + } + } + private IEnumerable GetPagedRequests(int maxPages, IEnumerable categories, string searchType, string parameters) { if (categories.Empty()) diff --git a/src/NzbDrone.Core/Indexers/Nyaa/NyaaRequestGenerator.cs b/src/NzbDrone.Core/Indexers/Nyaa/NyaaRequestGenerator.cs index 543b26ee9..23bc8ce6d 100644 --- a/src/NzbDrone.Core/Indexers/Nyaa/NyaaRequestGenerator.cs +++ b/src/NzbDrone.Core/Indexers/Nyaa/NyaaRequestGenerator.cs @@ -19,46 +19,46 @@ namespace NzbDrone.Core.Indexers.Nyaa PageSize = 100; } - public virtual IList> GetRecentRequests() + public virtual IndexerPageableRequestChain GetRecentRequests() { - var pageableRequests = new List>(); + var pageableRequests = new IndexerPageableRequestChain(); - pageableRequests.AddIfNotNull(GetPagedRequests(MaxPages, null)); + pageableRequests.Add(GetPagedRequests(MaxPages, null)); return pageableRequests; } - public virtual IList> GetSearchRequests(SingleEpisodeSearchCriteria searchCriteria) + public virtual IndexerPageableRequestChain GetSearchRequests(SingleEpisodeSearchCriteria searchCriteria) { - return new List>(); + return new IndexerPageableRequestChain(); } - public virtual IList> GetSearchRequests(SeasonSearchCriteria searchCriteria) + public virtual IndexerPageableRequestChain GetSearchRequests(SeasonSearchCriteria searchCriteria) { - return new List>(); + return new IndexerPageableRequestChain(); } - public virtual IList> GetSearchRequests(DailyEpisodeSearchCriteria searchCriteria) + public virtual IndexerPageableRequestChain GetSearchRequests(DailyEpisodeSearchCriteria searchCriteria) { - return new List>(); + return new IndexerPageableRequestChain(); } - public virtual IList> GetSearchRequests(AnimeEpisodeSearchCriteria searchCriteria) + public virtual IndexerPageableRequestChain GetSearchRequests(AnimeEpisodeSearchCriteria searchCriteria) { - var pageableRequests = new List>(); + var pageableRequests = new IndexerPageableRequestChain(); foreach (var queryTitle in searchCriteria.QueryTitles) { var searchTitle = PrepareQuery(queryTitle); - pageableRequests.AddIfNotNull(GetPagedRequests(MaxPages, + pageableRequests.Add(GetPagedRequests(MaxPages, string.Format("&term={0}+{1:0}", searchTitle, searchCriteria.AbsoluteEpisodeNumber))); if (searchCriteria.AbsoluteEpisodeNumber < 10) { - pageableRequests.AddIfNotNull(GetPagedRequests(MaxPages, + pageableRequests.Add(GetPagedRequests(MaxPages, string.Format("&term={0}+{1:00}", searchTitle, searchCriteria.AbsoluteEpisodeNumber))); @@ -68,13 +68,13 @@ namespace NzbDrone.Core.Indexers.Nyaa return pageableRequests; } - public virtual IList> GetSearchRequests(SpecialEpisodeSearchCriteria searchCriteria) + public virtual IndexerPageableRequestChain GetSearchRequests(SpecialEpisodeSearchCriteria searchCriteria) { - var pageableRequests = new List>(); + var pageableRequests = new IndexerPageableRequestChain(); foreach (var queryTitle in searchCriteria.EpisodeQueryTitles) { - pageableRequests.AddIfNotNull(GetPagedRequests(MaxPages, + pageableRequests.Add(GetPagedRequests(MaxPages, string.Format("&term={0}", PrepareQuery(queryTitle)))); } diff --git a/src/NzbDrone.Core/Indexers/Omgwtfnzbs/OmgwtfnzbsRequestGenerator.cs b/src/NzbDrone.Core/Indexers/Omgwtfnzbs/OmgwtfnzbsRequestGenerator.cs index a557d0e32..d9c0ea2f8 100644 --- a/src/NzbDrone.Core/Indexers/Omgwtfnzbs/OmgwtfnzbsRequestGenerator.cs +++ b/src/NzbDrone.Core/Indexers/Omgwtfnzbs/OmgwtfnzbsRequestGenerator.cs @@ -17,22 +17,22 @@ namespace NzbDrone.Core.Indexers.Omgwtfnzbs BaseUrl = "https://rss.omgwtfnzbs.org/rss-download.php"; } - public virtual IList> GetRecentRequests() + public virtual IndexerPageableRequestChain GetRecentRequests() { - var pageableRequests = new List>(); + var pageableRequests = new IndexerPageableRequestChain(); - pageableRequests.AddIfNotNull(GetPagedRequests(null)); + pageableRequests.Add(GetPagedRequests(null)); return pageableRequests; } - public virtual IList> GetSearchRequests(SingleEpisodeSearchCriteria searchCriteria) + public virtual IndexerPageableRequestChain GetSearchRequests(SingleEpisodeSearchCriteria searchCriteria) { - var pageableRequests = new List>(); + var pageableRequests = new IndexerPageableRequestChain(); foreach (var queryTitle in searchCriteria.QueryTitles) { - pageableRequests.AddIfNotNull(GetPagedRequests(string.Format("{0}+S{1:00}E{2:00}", + pageableRequests.Add(GetPagedRequests(string.Format("{0}+S{1:00}E{2:00}", queryTitle, searchCriteria.SeasonNumber, searchCriteria.EpisodeNumber))); @@ -41,13 +41,13 @@ namespace NzbDrone.Core.Indexers.Omgwtfnzbs return pageableRequests; } - public virtual IList> GetSearchRequests(SeasonSearchCriteria searchCriteria) + public virtual IndexerPageableRequestChain GetSearchRequests(SeasonSearchCriteria searchCriteria) { - var pageableRequests = new List>(); + var pageableRequests = new IndexerPageableRequestChain(); foreach (var queryTitle in searchCriteria.QueryTitles) { - pageableRequests.AddIfNotNull(GetPagedRequests(string.Format("{0}+S{1:00}", + pageableRequests.Add(GetPagedRequests(string.Format("{0}+S{1:00}", queryTitle, searchCriteria.SeasonNumber))); } @@ -55,13 +55,13 @@ namespace NzbDrone.Core.Indexers.Omgwtfnzbs return pageableRequests; } - public virtual IList> GetSearchRequests(DailyEpisodeSearchCriteria searchCriteria) + public virtual IndexerPageableRequestChain GetSearchRequests(DailyEpisodeSearchCriteria searchCriteria) { - var pageableRequests = new List>(); + var pageableRequests = new IndexerPageableRequestChain(); foreach (var queryTitle in searchCriteria.QueryTitles) { - pageableRequests.AddIfNotNull(GetPagedRequests(string.Format("{0}+{1:yyyy MM dd}", + pageableRequests.Add(GetPagedRequests(string.Format("{0}+{1:yyyy MM dd}", queryTitle, searchCriteria.AirDate))); } @@ -69,21 +69,21 @@ namespace NzbDrone.Core.Indexers.Omgwtfnzbs return pageableRequests; } - public virtual IList> GetSearchRequests(AnimeEpisodeSearchCriteria searchCriteria) + public virtual IndexerPageableRequestChain GetSearchRequests(AnimeEpisodeSearchCriteria searchCriteria) { - return new List>(); + return new IndexerPageableRequestChain(); } - public virtual IList> GetSearchRequests(SpecialEpisodeSearchCriteria searchCriteria) + public virtual IndexerPageableRequestChain GetSearchRequests(SpecialEpisodeSearchCriteria searchCriteria) { - var pageableRequests = new List>(); + var pageableRequests = new IndexerPageableRequestChain(); foreach (var queryTitle in searchCriteria.EpisodeQueryTitles) { var query = queryTitle.Replace('+', ' '); query = System.Web.HttpUtility.UrlEncode(query); - pageableRequests.AddIfNotNull(GetPagedRequests(query)); + pageableRequests.Add(GetPagedRequests(query)); } return pageableRequests; diff --git a/src/NzbDrone.Core/Indexers/Rarbg/RarbgRequestGenerator.cs b/src/NzbDrone.Core/Indexers/Rarbg/RarbgRequestGenerator.cs index 3c27c8dd6..342e7d767 100644 --- a/src/NzbDrone.Core/Indexers/Rarbg/RarbgRequestGenerator.cs +++ b/src/NzbDrone.Core/Indexers/Rarbg/RarbgRequestGenerator.cs @@ -17,50 +17,50 @@ namespace NzbDrone.Core.Indexers.Rarbg _tokenProvider = tokenProvider; } - public virtual IList> GetRecentRequests() + public virtual IndexerPageableRequestChain GetRecentRequests() { - var pageableRequests = new List>(); + var pageableRequests = new IndexerPageableRequestChain(); - pageableRequests.AddIfNotNull(GetPagedRequests("list", null, null)); + pageableRequests.Add(GetPagedRequests("list", null, null)); return pageableRequests; } - public virtual IList> GetSearchRequests(SingleEpisodeSearchCriteria searchCriteria) + public virtual IndexerPageableRequestChain GetSearchRequests(SingleEpisodeSearchCriteria searchCriteria) { - var pageableRequests = new List>(); + var pageableRequests = new IndexerPageableRequestChain(); - pageableRequests.AddIfNotNull(GetPagedRequests("search", searchCriteria.Series.TvdbId, "S{0:00}E{1:00}", searchCriteria.SeasonNumber, searchCriteria.EpisodeNumber)); + pageableRequests.Add(GetPagedRequests("search", searchCriteria.Series.TvdbId, "S{0:00}E{1:00}", searchCriteria.SeasonNumber, searchCriteria.EpisodeNumber)); return pageableRequests; } - public virtual IList> GetSearchRequests(SeasonSearchCriteria searchCriteria) + public virtual IndexerPageableRequestChain GetSearchRequests(SeasonSearchCriteria searchCriteria) { - var pageableRequests = new List>(); + var pageableRequests = new IndexerPageableRequestChain(); - pageableRequests.AddIfNotNull(GetPagedRequests("search", searchCriteria.Series.TvdbId, "S{0:00}", searchCriteria.SeasonNumber)); + pageableRequests.Add(GetPagedRequests("search", searchCriteria.Series.TvdbId, "S{0:00}", searchCriteria.SeasonNumber)); return pageableRequests; } - public virtual IList> GetSearchRequests(DailyEpisodeSearchCriteria searchCriteria) + public virtual IndexerPageableRequestChain GetSearchRequests(DailyEpisodeSearchCriteria searchCriteria) { - var pageableRequests = new List>(); + var pageableRequests = new IndexerPageableRequestChain(); - pageableRequests.AddIfNotNull(GetPagedRequests("search", searchCriteria.Series.TvdbId, "\"{0:yyyy MM dd}\"", searchCriteria.AirDate)); + pageableRequests.Add(GetPagedRequests("search", searchCriteria.Series.TvdbId, "\"{0:yyyy MM dd}\"", searchCriteria.AirDate)); return pageableRequests; } - public virtual IList> GetSearchRequests(AnimeEpisodeSearchCriteria searchCriteria) + public virtual IndexerPageableRequestChain GetSearchRequests(AnimeEpisodeSearchCriteria searchCriteria) { - return new List>(); + return new IndexerPageableRequestChain(); } - public virtual IList> GetSearchRequests(SpecialEpisodeSearchCriteria searchCriteria) + public virtual IndexerPageableRequestChain GetSearchRequests(SpecialEpisodeSearchCriteria searchCriteria) { - return new List>(); + return new IndexerPageableRequestChain(); } private IEnumerable GetPagedRequests(string mode, int? tvdbId, string query, params object[] args) diff --git a/src/NzbDrone.Core/Indexers/RssIndexerRequestGenerator.cs b/src/NzbDrone.Core/Indexers/RssIndexerRequestGenerator.cs index 0c94604ad..a8f8b6e2f 100644 --- a/src/NzbDrone.Core/Indexers/RssIndexerRequestGenerator.cs +++ b/src/NzbDrone.Core/Indexers/RssIndexerRequestGenerator.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using NzbDrone.Common.Extensions; using NzbDrone.Common.Http; using NzbDrone.Core.IndexerSearch.Definitions; @@ -15,38 +16,38 @@ namespace NzbDrone.Core.Indexers } - public virtual IList> GetRecentRequests() + public virtual IndexerPageableRequestChain GetRecentRequests() { - var pageableRequests = new List>(); + var pageableRequests = new IndexerPageableRequestChain(); pageableRequests.Add(new[] { new IndexerRequest(_baseUrl, HttpAccept.Rss) }); return pageableRequests; } - public virtual IList> GetSearchRequests(SingleEpisodeSearchCriteria searchCriteria) + public virtual IndexerPageableRequestChain GetSearchRequests(SingleEpisodeSearchCriteria searchCriteria) { - return new List>(); + return new IndexerPageableRequestChain(); } - public virtual IList> GetSearchRequests(SeasonSearchCriteria searchCriteria) + public virtual IndexerPageableRequestChain GetSearchRequests(SeasonSearchCriteria searchCriteria) { - return new List>(); + return new IndexerPageableRequestChain(); } - public virtual IList> GetSearchRequests(DailyEpisodeSearchCriteria searchCriteria) + public virtual IndexerPageableRequestChain GetSearchRequests(DailyEpisodeSearchCriteria searchCriteria) { - return new List>(); + return new IndexerPageableRequestChain(); } - public virtual IList> GetSearchRequests(AnimeEpisodeSearchCriteria searchCriteria) + public virtual IndexerPageableRequestChain GetSearchRequests(AnimeEpisodeSearchCriteria searchCriteria) { - return new List>(); + return new IndexerPageableRequestChain(); } - public virtual IList> GetSearchRequests(SpecialEpisodeSearchCriteria searchCriteria) + public virtual IndexerPageableRequestChain GetSearchRequests(SpecialEpisodeSearchCriteria searchCriteria) { - return new List>(); + return new IndexerPageableRequestChain(); } } } diff --git a/src/NzbDrone.Core/Indexers/TitansOfTv/TitansOfTvRequestGenerator.cs b/src/NzbDrone.Core/Indexers/TitansOfTv/TitansOfTvRequestGenerator.cs index a7f665087..fc88432db 100644 --- a/src/NzbDrone.Core/Indexers/TitansOfTv/TitansOfTvRequestGenerator.cs +++ b/src/NzbDrone.Core/Indexers/TitansOfTv/TitansOfTvRequestGenerator.cs @@ -19,62 +19,64 @@ namespace NzbDrone.Core.Indexers.TitansOfTv PageSize = 100; } - public IList> GetRecentRequests() + public virtual IndexerPageableRequestChain GetRecentRequests() { - var pageableRequests = new List>(); + var pageableRequests = new IndexerPageableRequestChain(); - pageableRequests.AddIfNotNull(GetPagedRequests(MaxPages)); + pageableRequests.Add(GetPagedRequests(MaxPages)); return pageableRequests; } - public IList> GetSearchRequests(SingleEpisodeSearchCriteria searchCriteria) + public virtual IndexerPageableRequestChain GetSearchRequests(SingleEpisodeSearchCriteria searchCriteria) { - var pageableRequests = new List>(); + var pageableRequests = new IndexerPageableRequestChain(); - pageableRequests.AddIfNotNull(GetPagedRequests(MaxPages, + pageableRequests.Add(GetPagedRequests(MaxPages, series_id: searchCriteria.Series.TvdbId, episode: string.Format("S{0:00}E{1:00}", searchCriteria.SeasonNumber, searchCriteria.EpisodeNumber))); - pageableRequests.AddIfNotNull(GetPagedRequests(MaxPages, + pageableRequests.Add(GetPagedRequests(MaxPages, series_id: searchCriteria.Series.TvdbId, season: string.Format("Season {0:00}", searchCriteria.SeasonNumber))); return pageableRequests; } - public IList> GetSearchRequests(SeasonSearchCriteria searchCriteria) + public virtual IndexerPageableRequestChain GetSearchRequests(SeasonSearchCriteria searchCriteria) { - var pageableRequests = new List>(); + var pageableRequests = new IndexerPageableRequestChain(); - // TODO: Search for all episodes?!? - - pageableRequests.AddIfNotNull(GetPagedRequests(MaxPages, + pageableRequests.Add(GetPagedRequests(MaxPages, series_id: searchCriteria.Series.TvdbId, season: string.Format("Season {0:00}", searchCriteria.SeasonNumber))); + pageableRequests.AddTier(); + + // TODO: Search for all episodes?!? + return pageableRequests; } - public IList> GetSearchRequests(DailyEpisodeSearchCriteria searchCriteria) + public virtual IndexerPageableRequestChain GetSearchRequests(DailyEpisodeSearchCriteria searchCriteria) { - var pageableRequests = new List>(); + var pageableRequests = new IndexerPageableRequestChain(); - pageableRequests.AddIfNotNull(GetPagedRequests(MaxPages, + pageableRequests.Add(GetPagedRequests(MaxPages, series_id: searchCriteria.Series.TvdbId, air_date: searchCriteria.AirDate)); return pageableRequests; } - public IList> GetSearchRequests(AnimeEpisodeSearchCriteria searchCriteria) + public virtual IndexerPageableRequestChain GetSearchRequests(AnimeEpisodeSearchCriteria searchCriteria) { - return new List>(); + return new IndexerPageableRequestChain(); } - public IList> GetSearchRequests(SpecialEpisodeSearchCriteria searchCriteria) + public virtual IndexerPageableRequestChain GetSearchRequests(SpecialEpisodeSearchCriteria searchCriteria) { - return new List>(); + return new IndexerPageableRequestChain(); } private IEnumerable GetPagedRequests(int maxPages, int? series_id = null, string episode = null, string season = null, DateTime? air_date = null) diff --git a/src/NzbDrone.Core/Indexers/TorrentRss/TorrentRssIndexerRequestGenerator.cs b/src/NzbDrone.Core/Indexers/TorrentRss/TorrentRssIndexerRequestGenerator.cs index b288a5acd..ea5526cf9 100644 --- a/src/NzbDrone.Core/Indexers/TorrentRss/TorrentRssIndexerRequestGenerator.cs +++ b/src/NzbDrone.Core/Indexers/TorrentRss/TorrentRssIndexerRequestGenerator.cs @@ -10,38 +10,38 @@ namespace NzbDrone.Core.Indexers.TorrentRss { public TorrentRssIndexerSettings Settings { get; set; } - public virtual IList> GetRecentRequests() + public virtual IndexerPageableRequestChain GetRecentRequests() { - var pageableRequests = new List>(); + var pageableRequests = new IndexerPageableRequestChain(); - pageableRequests.AddIfNotNull(GetRssRequests(null)); + pageableRequests.Add(GetRssRequests(null)); return pageableRequests; } - public virtual IList> GetSearchRequests(SingleEpisodeSearchCriteria searchCriteria) + public virtual IndexerPageableRequestChain GetSearchRequests(SingleEpisodeSearchCriteria searchCriteria) { - return new List>(); + return new IndexerPageableRequestChain(); } - public virtual IList> GetSearchRequests(SeasonSearchCriteria searchCriteria) + public virtual IndexerPageableRequestChain GetSearchRequests(SeasonSearchCriteria searchCriteria) { - return new List>(); + return new IndexerPageableRequestChain(); } - public virtual IList> GetSearchRequests(DailyEpisodeSearchCriteria searchCriteria) + public virtual IndexerPageableRequestChain GetSearchRequests(DailyEpisodeSearchCriteria searchCriteria) { - return new List>(); + return new IndexerPageableRequestChain(); } - public virtual IList> GetSearchRequests(AnimeEpisodeSearchCriteria searchCriteria) + public virtual IndexerPageableRequestChain GetSearchRequests(AnimeEpisodeSearchCriteria searchCriteria) { - return new List>(); + return new IndexerPageableRequestChain(); } - public virtual IList> GetSearchRequests(SpecialEpisodeSearchCriteria searchCriteria) + public virtual IndexerPageableRequestChain GetSearchRequests(SpecialEpisodeSearchCriteria searchCriteria) { - return new List>(); + return new IndexerPageableRequestChain(); } private IEnumerable GetRssRequests(string searchParameters) diff --git a/src/NzbDrone.Core/Indexers/TorrentRss/TorrentRssSettingsDetector.cs b/src/NzbDrone.Core/Indexers/TorrentRss/TorrentRssSettingsDetector.cs index fb98b7b46..1b58b83bf 100644 --- a/src/NzbDrone.Core/Indexers/TorrentRss/TorrentRssSettingsDetector.cs +++ b/src/NzbDrone.Core/Indexers/TorrentRss/TorrentRssSettingsDetector.cs @@ -41,7 +41,7 @@ namespace NzbDrone.Core.Indexers.TorrentRss _logger.Debug("Evaluating TorrentRss feed '{0}'", indexerSettings.BaseUrl); var requestGenerator = new TorrentRssIndexerRequestGenerator { Settings = indexerSettings }; - var request = requestGenerator.GetRecentRequests().First().First(); + var request = requestGenerator.GetRecentRequests().GetAllTiers().First().First(); HttpResponse httpResponse = null; try diff --git a/src/NzbDrone.Core/Indexers/Torrentleech/TorrentleechRequestGenerator.cs b/src/NzbDrone.Core/Indexers/Torrentleech/TorrentleechRequestGenerator.cs index dc6e6c72f..699f163a6 100644 --- a/src/NzbDrone.Core/Indexers/Torrentleech/TorrentleechRequestGenerator.cs +++ b/src/NzbDrone.Core/Indexers/Torrentleech/TorrentleechRequestGenerator.cs @@ -10,38 +10,38 @@ namespace NzbDrone.Core.Indexers.Torrentleech { public TorrentleechSettings Settings { get; set; } - public virtual IList> GetRecentRequests() + public virtual IndexerPageableRequestChain GetRecentRequests() { - var pageableRequests = new List>(); + var pageableRequests = new IndexerPageableRequestChain(); - pageableRequests.AddIfNotNull(GetRssRequests(null)); + pageableRequests.Add(GetRssRequests(null)); return pageableRequests; } - public virtual IList> GetSearchRequests(SingleEpisodeSearchCriteria searchCriteria) + public virtual IndexerPageableRequestChain GetSearchRequests(SingleEpisodeSearchCriteria searchCriteria) { - return new List>(); + return new IndexerPageableRequestChain(); } - public virtual IList> GetSearchRequests(SeasonSearchCriteria searchCriteria) + public virtual IndexerPageableRequestChain GetSearchRequests(SeasonSearchCriteria searchCriteria) { - return new List>(); + return new IndexerPageableRequestChain(); } - public virtual IList> GetSearchRequests(DailyEpisodeSearchCriteria searchCriteria) + public virtual IndexerPageableRequestChain GetSearchRequests(DailyEpisodeSearchCriteria searchCriteria) { - return new List>(); + return new IndexerPageableRequestChain(); } - public virtual IList> GetSearchRequests(AnimeEpisodeSearchCriteria searchCriteria) + public virtual IndexerPageableRequestChain GetSearchRequests(AnimeEpisodeSearchCriteria searchCriteria) { - return new List>(); + return new IndexerPageableRequestChain(); } - public virtual IList> GetSearchRequests(SpecialEpisodeSearchCriteria searchCriteria) + public virtual IndexerPageableRequestChain GetSearchRequests(SpecialEpisodeSearchCriteria searchCriteria) { - return new List>(); + return new IndexerPageableRequestChain(); } private IEnumerable GetRssRequests(string searchParameters) diff --git a/src/NzbDrone.Core/NzbDrone.Core.csproj b/src/NzbDrone.Core/NzbDrone.Core.csproj index 620ae5dc8..b5f216998 100644 --- a/src/NzbDrone.Core/NzbDrone.Core.csproj +++ b/src/NzbDrone.Core/NzbDrone.Core.csproj @@ -503,6 +503,8 @@ + + From 9162e97dd57a4af2686f064097f85afae6bbdf14 Mon Sep 17 00:00:00 2001 From: Taloth Saldono Date: Fri, 9 Oct 2015 20:57:38 +0200 Subject: [PATCH 4/5] Added support for querying newznab with multiple ids in one query. --- .../Indexers/Newznab/NewznabCapabilities.cs | 2 ++ .../Newznab/NewznabCapabilitiesProvider.cs | 1 + .../Newznab/NewznabRequestGenerator.cs | 27 +++++++++++++++++++ 3 files changed, 30 insertions(+) diff --git a/src/NzbDrone.Core/Indexers/Newznab/NewznabCapabilities.cs b/src/NzbDrone.Core/Indexers/Newznab/NewznabCapabilities.cs index 0c25c7802..a1c30231d 100644 --- a/src/NzbDrone.Core/Indexers/Newznab/NewznabCapabilities.cs +++ b/src/NzbDrone.Core/Indexers/Newznab/NewznabCapabilities.cs @@ -7,12 +7,14 @@ namespace NzbDrone.Core.Indexers.Newznab { public string[] SupportedSearchParameters { get; set; } public string[] SupportedTvSearchParameters { get; set; } + public bool SupportsAggregateIdSearch { get; set; } public List Categories { get; set; } public NewznabCapabilities() { SupportedSearchParameters = new[] { "q" }; SupportedTvSearchParameters = new[] { "q", "rid", "season", "ep" }; // This should remain 'rid' for older newznab installs. + SupportsAggregateIdSearch = false; Categories = new List(); } } diff --git a/src/NzbDrone.Core/Indexers/Newznab/NewznabCapabilitiesProvider.cs b/src/NzbDrone.Core/Indexers/Newznab/NewznabCapabilitiesProvider.cs index d415074a4..550764f24 100644 --- a/src/NzbDrone.Core/Indexers/Newznab/NewznabCapabilitiesProvider.cs +++ b/src/NzbDrone.Core/Indexers/Newznab/NewznabCapabilitiesProvider.cs @@ -89,6 +89,7 @@ namespace NzbDrone.Core.Indexers.Newznab else if (xmlTvSearch.Attribute("supportedParams") != null) { capabilities.SupportedTvSearchParameters = xmlTvSearch.Attribute("supportedParams").Value.Split(','); + capabilities.SupportsAggregateIdSearch = true; } } diff --git a/src/NzbDrone.Core/Indexers/Newznab/NewznabRequestGenerator.cs b/src/NzbDrone.Core/Indexers/Newznab/NewznabRequestGenerator.cs index c88a1b79f..5a9dc825c 100644 --- a/src/NzbDrone.Core/Indexers/Newznab/NewznabRequestGenerator.cs +++ b/src/NzbDrone.Core/Indexers/Newznab/NewznabRequestGenerator.cs @@ -72,6 +72,16 @@ namespace NzbDrone.Core.Indexers.Newznab } } + private bool SupportsAggregatedIdSearch + { + get + { + var capabilities = _capabilitiesProvider.GetCapabilities(Settings); + + return capabilities.SupportsAggregateIdSearch; + } + } + public virtual IndexerPageableRequestChain GetRecentRequests() { var pageableRequests = new IndexerPageableRequestChain(); @@ -160,6 +170,23 @@ namespace NzbDrone.Core.Indexers.Newznab private void AddTvIdPageableRequests(IndexerPageableRequestChain chain, int maxPages, IEnumerable categories, SearchCriteriaBase searchCriteria, string parameters) { + if (SupportsAggregatedIdSearch) + { + var ids = ""; + + if (searchCriteria.Series.TvdbId > 0 && SupportsTvdbSearch) + { + ids += "&tvdbid=" + searchCriteria.Series.TvdbId; + } + + if (searchCriteria.Series.TvRageId > 0 && SupportsTvRageSearch) + { + ids += "&rid=" + searchCriteria.Series.TvRageId; + } + + chain.Add(GetPagedRequests(maxPages, categories, "tvsearch", ids + parameters)); + } + else { if (searchCriteria.Series.TvdbId > 0 && SupportsTvdbSearch) { From 84c7f4cd8ccadedb5166710cdc6af41afab7948e Mon Sep 17 00:00:00 2001 From: Taloth Saldono Date: Fri, 9 Oct 2015 22:22:28 +0200 Subject: [PATCH 5/5] Added support for tvmaze. --- src/NzbDrone.Api/Series/SeriesResource.cs | 1 + .../NewznabRequestGeneratorFixture.cs | 15 +++++++++++- .../TvTests/RefreshSeriesServiceFixture.cs | 14 +++++++++++ .../Datastore/Migration/094_add_tvmazeid.cs | 15 ++++++++++++ .../Newznab/NewznabRequestGenerator.cs | 24 +++++++++++++++++++ .../SkyHook/Resource/ShowResource.cs | 1 + .../MetadataSource/SkyHook/SkyHookProxy.cs | 5 ++++ src/NzbDrone.Core/NzbDrone.Core.csproj | 1 + src/NzbDrone.Core/Tv/RefreshSeriesService.cs | 1 + src/NzbDrone.Core/Tv/Series.cs | 1 + src/UI/Handlebars/Helpers/Series.js | 4 ++++ src/UI/Series/Details/InfoViewTemplate.hbs | 4 ++++ 12 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 src/NzbDrone.Core/Datastore/Migration/094_add_tvmazeid.cs diff --git a/src/NzbDrone.Api/Series/SeriesResource.cs b/src/NzbDrone.Api/Series/SeriesResource.cs index a68deaab2..2dbcfd977 100644 --- a/src/NzbDrone.Api/Series/SeriesResource.cs +++ b/src/NzbDrone.Api/Series/SeriesResource.cs @@ -57,6 +57,7 @@ namespace NzbDrone.Api.Series public int Runtime { get; set; } public int TvdbId { get; set; } public int TvRageId { get; set; } + public int TvMazeId { get; set; } public DateTime? FirstAired { get; set; } public DateTime? LastInfoSync { get; set; } public SeriesTypes SeriesType { get; set; } diff --git a/src/NzbDrone.Core.Test/IndexerTests/NewznabTests/NewznabRequestGeneratorFixture.cs b/src/NzbDrone.Core.Test/IndexerTests/NewznabTests/NewznabRequestGeneratorFixture.cs index 20f7f70ea..1c874e991 100644 --- a/src/NzbDrone.Core.Test/IndexerTests/NewznabTests/NewznabRequestGeneratorFixture.cs +++ b/src/NzbDrone.Core.Test/IndexerTests/NewznabTests/NewznabRequestGeneratorFixture.cs @@ -29,7 +29,7 @@ namespace NzbDrone.Core.Test.IndexerTests.NewznabTests _singleEpisodeSearchCriteria = new SingleEpisodeSearchCriteria { - Series = new Tv.Series { TvRageId = 10, TvdbId = 20 }, + Series = new Tv.Series { TvRageId = 10, TvdbId = 20, TvMazeId = 30 }, SceneTitles = new List { "Monkey Island" }, SeasonNumber = 1, EpisodeNumber = 2 @@ -177,6 +177,19 @@ namespace NzbDrone.Core.Test.IndexerTests.NewznabTests page.Url.Query.Should().Contain("tvdbid=20"); } + [Test] + public void should_search_by_tvmaze_if_supported() + { + _capabilities.SupportedTvSearchParameters = new[] { "q", "tvmazeid", "season", "ep" }; + + var results = Subject.GetSearchRequests(_singleEpisodeSearchCriteria); + results.GetTier(0).Should().HaveCount(1); + + var page = results.GetAllTiers().First().First(); + + page.Url.Query.Should().Contain("tvmazeid=30"); + } + [Test] public void should_prefer_search_by_tvdbid_if_rid_supported() { diff --git a/src/NzbDrone.Core.Test/TvTests/RefreshSeriesServiceFixture.cs b/src/NzbDrone.Core.Test/TvTests/RefreshSeriesServiceFixture.cs index aed900762..cd3bfc3b1 100644 --- a/src/NzbDrone.Core.Test/TvTests/RefreshSeriesServiceFixture.cs +++ b/src/NzbDrone.Core.Test/TvTests/RefreshSeriesServiceFixture.cs @@ -95,6 +95,20 @@ namespace NzbDrone.Core.Test.TvTests .Verify(v => v.UpdateSeries(It.Is(s => s.TvRageId == newSeriesInfo.TvRageId))); } + [Test] + public void should_update_tvmaze_id_if_changed() + { + var newSeriesInfo = _series.JsonClone(); + newSeriesInfo.TvMazeId = _series.TvMazeId + 1; + + GivenNewSeriesInfo(newSeriesInfo); + + Subject.Execute(new RefreshSeriesCommand(_series.Id)); + + Mocker.GetMock() + .Verify(v => v.UpdateSeries(It.Is(s => s.TvMazeId == newSeriesInfo.TvMazeId))); + } + [Test] public void should_log_error_if_tvdb_id_not_found() { diff --git a/src/NzbDrone.Core/Datastore/Migration/094_add_tvmazeid.cs b/src/NzbDrone.Core/Datastore/Migration/094_add_tvmazeid.cs new file mode 100644 index 000000000..007716bfc --- /dev/null +++ b/src/NzbDrone.Core/Datastore/Migration/094_add_tvmazeid.cs @@ -0,0 +1,15 @@ +using FluentMigrator; +using NzbDrone.Core.Datastore.Migration.Framework; + +namespace NzbDrone.Core.Datastore.Migration +{ + [Migration(94)] + public class add_tvmazeid : NzbDroneMigrationBase + { + protected override void MainDbUpgrade() + { + Alter.Table("Series").AddColumn("TvMazeId").AsInt32().WithDefaultValue(0); + Create.Index().OnTable("Series").OnColumn("TvMazeId"); + } + } +} diff --git a/src/NzbDrone.Core/Indexers/Newznab/NewznabRequestGenerator.cs b/src/NzbDrone.Core/Indexers/Newznab/NewznabRequestGenerator.cs index 5a9dc825c..8b4844ca5 100644 --- a/src/NzbDrone.Core/Indexers/Newznab/NewznabRequestGenerator.cs +++ b/src/NzbDrone.Core/Indexers/Newznab/NewznabRequestGenerator.cs @@ -72,6 +72,19 @@ namespace NzbDrone.Core.Indexers.Newznab } } + private bool SupportsTvMazeSearch + { + get + { + var capabilities = _capabilitiesProvider.GetCapabilities(Settings); + + return capabilities.SupportedTvSearchParameters != null && + capabilities.SupportedTvSearchParameters.Contains("tvmazeid") && + capabilities.SupportedTvSearchParameters.Contains("season") && + capabilities.SupportedTvSearchParameters.Contains("ep"); + } + } + private bool SupportsAggregatedIdSearch { get @@ -184,6 +197,11 @@ namespace NzbDrone.Core.Indexers.Newznab ids += "&rid=" + searchCriteria.Series.TvRageId; } + if (searchCriteria.Series.TvMazeId > 0 && SupportsTvMazeSearch) + { + ids += "&tvmazeid=" + searchCriteria.Series.TvMazeId; + } + chain.Add(GetPagedRequests(maxPages, categories, "tvsearch", ids + parameters)); } else @@ -198,6 +216,12 @@ namespace NzbDrone.Core.Indexers.Newznab chain.Add(GetPagedRequests(maxPages, categories, "tvsearch", string.Format("&rid={0}{1}", searchCriteria.Series.TvRageId, parameters))); } + + else if (searchCriteria.Series.TvMazeId > 0 && SupportsTvMazeSearch) + { + chain.Add(GetPagedRequests(maxPages, categories, "tvsearch", + string.Format("&tvmazeid={0}{1}", searchCriteria.Series.TvMazeId, parameters))); + } } if (SupportsTvSearch) diff --git a/src/NzbDrone.Core/MetadataSource/SkyHook/Resource/ShowResource.cs b/src/NzbDrone.Core/MetadataSource/SkyHook/Resource/ShowResource.cs index 36b1caa5e..fd442100d 100644 --- a/src/NzbDrone.Core/MetadataSource/SkyHook/Resource/ShowResource.cs +++ b/src/NzbDrone.Core/MetadataSource/SkyHook/Resource/ShowResource.cs @@ -20,6 +20,7 @@ namespace NzbDrone.Core.MetadataSource.SkyHook.Resource public string Slug { get; set; } public string FirstAired { get; set; } public int? TvRageId { get; set; } + public int? TvMazeId { get; set; } public string Status { get; set; } public int? Runtime { get; set; } diff --git a/src/NzbDrone.Core/MetadataSource/SkyHook/SkyHookProxy.cs b/src/NzbDrone.Core/MetadataSource/SkyHook/SkyHookProxy.cs index 7efdfe207..532d996ac 100644 --- a/src/NzbDrone.Core/MetadataSource/SkyHook/SkyHookProxy.cs +++ b/src/NzbDrone.Core/MetadataSource/SkyHook/SkyHookProxy.cs @@ -110,6 +110,11 @@ namespace NzbDrone.Core.MetadataSource.SkyHook series.TvRageId = show.TvRageId.Value; } + if (show.TvMazeId.HasValue) + { + series.TvMazeId = show.TvMazeId.Value; + } + series.ImdbId = show.ImdbId; series.Title = show.Title; series.CleanTitle = Parser.Parser.CleanSeriesTitle(show.Title); diff --git a/src/NzbDrone.Core/NzbDrone.Core.csproj b/src/NzbDrone.Core/NzbDrone.Core.csproj index b5f216998..7117f823a 100644 --- a/src/NzbDrone.Core/NzbDrone.Core.csproj +++ b/src/NzbDrone.Core/NzbDrone.Core.csproj @@ -272,6 +272,7 @@ + diff --git a/src/NzbDrone.Core/Tv/RefreshSeriesService.cs b/src/NzbDrone.Core/Tv/RefreshSeriesService.cs index ec7af2fe9..c59cee64f 100644 --- a/src/NzbDrone.Core/Tv/RefreshSeriesService.cs +++ b/src/NzbDrone.Core/Tv/RefreshSeriesService.cs @@ -73,6 +73,7 @@ namespace NzbDrone.Core.Tv series.Title = seriesInfo.Title; series.TitleSlug = seriesInfo.TitleSlug; series.TvRageId = seriesInfo.TvRageId; + series.TvMazeId = seriesInfo.TvMazeId; series.ImdbId = seriesInfo.ImdbId; series.AirTime = seriesInfo.AirTime; series.Overview = seriesInfo.Overview; diff --git a/src/NzbDrone.Core/Tv/Series.cs b/src/NzbDrone.Core/Tv/Series.cs index 61046df5c..a3fdb986f 100644 --- a/src/NzbDrone.Core/Tv/Series.cs +++ b/src/NzbDrone.Core/Tv/Series.cs @@ -20,6 +20,7 @@ namespace NzbDrone.Core.Tv public int TvdbId { get; set; } public int TvRageId { get; set; } + public int TvMazeId { get; set; } public string ImdbId { get; set; } public string Title { get; set; } public string CleanTitle { get; set; } diff --git a/src/UI/Handlebars/Helpers/Series.js b/src/UI/Handlebars/Helpers/Series.js index 30a198b07..1fd5a14dc 100644 --- a/src/UI/Handlebars/Helpers/Series.js +++ b/src/UI/Handlebars/Helpers/Series.js @@ -35,6 +35,10 @@ Handlebars.registerHelper('tvRageUrl', function() { return 'http://www.tvrage.com/shows/id-' + this.tvRageId; }); +Handlebars.registerHelper('tvMazeUrl', function() { + return 'http://www.tvmaze.com/shows/' + this.tvMazeId + '/_'; +}); + Handlebars.registerHelper('route', function() { return StatusModel.get('urlBase') + '/series/' + this.titleSlug; }); diff --git a/src/UI/Series/Details/InfoViewTemplate.hbs b/src/UI/Series/Details/InfoViewTemplate.hbs index e76980a43..21add05e4 100644 --- a/src/UI/Series/Details/InfoViewTemplate.hbs +++ b/src/UI/Series/Details/InfoViewTemplate.hbs @@ -40,6 +40,10 @@ {{#if tvRageId}} TV Rage {{/if}} + + {{#if tvMazeId}} + TV Maze + {{/if}}