Merge branch 'nn-tvdbid' into develop

pull/6/head
Taloth Saldono 9 years ago
commit e13c89521d

@ -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<string> Rejections { get; set; }
public DateTime PublishDate { get; set; }

@ -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)
{

@ -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; }

@ -54,7 +54,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
};
Mocker.GetMock<IParsingService>()
.Setup(c => c.Map(It.IsAny<ParsedEpisodeInfo>(), It.IsAny<int>(), It.IsAny<SearchCriteriaBase>()))
.Setup(c => c.Map(It.IsAny<ParsedEpisodeInfo>(), It.IsAny<int>(), It.IsAny<int>(), It.IsAny<SearchCriteriaBase>()))
.Returns(_remoteEpisode);
}
@ -125,7 +125,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
var results = Subject.GetRssDecision(_reports).ToList();
Mocker.GetMock<IParsingService>().Verify(c => c.Map(It.IsAny<ParsedEpisodeInfo>(), It.IsAny<int>(), It.IsAny<SearchCriteriaBase>()), Times.Never());
Mocker.GetMock<IParsingService>().Verify(c => c.Map(It.IsAny<ParsedEpisodeInfo>(), It.IsAny<int>(), It.IsAny<int>(), It.IsAny<SearchCriteriaBase>()), Times.Never());
_pass1.Verify(c => c.IsSatisfiedBy(It.IsAny<RemoteEpisode>(), null), Times.Never());
_pass2.Verify(c => c.IsSatisfiedBy(It.IsAny<RemoteEpisode>(), null), Times.Never());
@ -142,7 +142,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
var results = Subject.GetRssDecision(_reports).ToList();
Mocker.GetMock<IParsingService>().Verify(c => c.Map(It.IsAny<ParsedEpisodeInfo>(), It.IsAny<int>(), It.IsAny<SearchCriteriaBase>()), Times.Never());
Mocker.GetMock<IParsingService>().Verify(c => c.Map(It.IsAny<ParsedEpisodeInfo>(), It.IsAny<int>(), It.IsAny<int>(), It.IsAny<SearchCriteriaBase>()), Times.Never());
_pass1.Verify(c => c.IsSatisfiedBy(It.IsAny<RemoteEpisode>(), null), Times.Never());
_pass2.Verify(c => c.IsSatisfiedBy(It.IsAny<RemoteEpisode>(), null), Times.Never());
@ -170,7 +170,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
{
GivenSpecifications(_pass1);
Mocker.GetMock<IParsingService>().Setup(c => c.Map(It.IsAny<ParsedEpisodeInfo>(), It.IsAny<int>(), It.IsAny<SearchCriteriaBase>()))
Mocker.GetMock<IParsingService>().Setup(c => c.Map(It.IsAny<ParsedEpisodeInfo>(), It.IsAny<int>(), It.IsAny<int>(), It.IsAny<SearchCriteriaBase>()))
.Throws<TestException>();
_reports = new List<ReleaseInfo>
@ -182,7 +182,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
Subject.GetRssDecision(_reports);
Mocker.GetMock<IParsingService>().Verify(c => c.Map(It.IsAny<ParsedEpisodeInfo>(), It.IsAny<int>(), It.IsAny<SearchCriteriaBase>()), Times.Exactly(_reports.Count));
Mocker.GetMock<IParsingService>().Verify(c => c.Map(It.IsAny<ParsedEpisodeInfo>(), It.IsAny<int>(), It.IsAny<int>(), It.IsAny<SearchCriteriaBase>()), Times.Exactly(_reports.Count));
ExceptionVerification.ExpectedErrors(3);
}
@ -221,8 +221,8 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
}).ToList();
Mocker.GetMock<IParsingService>()
.Setup(v => v.Map(It.IsAny<ParsedEpisodeInfo>(), It.IsAny<int>(), It.IsAny<SearchCriteriaBase>()))
.Returns<ParsedEpisodeInfo, int, SearchCriteriaBase>((p,id,c) =>
.Setup(v => v.Map(It.IsAny<ParsedEpisodeInfo>(), It.IsAny<int>(), It.IsAny<int>(), It.IsAny<SearchCriteriaBase>()))
.Returns<ParsedEpisodeInfo, int, int, SearchCriteriaBase>((p,tvdbid,tvrageid,c) =>
new RemoteEpisode
{
DownloadAllowed = true,

@ -30,7 +30,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests
.Returns(30);
Mocker.GetMock<IParsingService>()
.Setup(s => s.Map(It.IsAny<ParsedEpisodeInfo>(), It.IsAny<int>(), (SearchCriteriaBase)null))
.Setup(s => s.Map(It.IsAny<ParsedEpisodeInfo>(), It.IsAny<int>(), It.IsAny<int>(), (SearchCriteriaBase)null))
.Returns(() => CreateRemoteEpisode());
Mocker.GetMock<IHttpClient>()

@ -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);

@ -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<INewznabCapabilitiesProvider>()
.Setup(v => v.GetCapabilities(It.IsAny<NewznabSettings>()))
.Returns(new NewznabCapabilities());
}
[Test]

@ -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<NewznabRequestGenerator>
{
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, TvMazeId = 30 },
SceneTitles = new List<string> { "Monkey Island" },
SeasonNumber = 1,
EpisodeNumber = 2
};
_animeSearchCriteria = new AnimeEpisodeSearchCriteria()
{
SceneTitles = new List<string>() { "Monkey+Island" },
AbsoluteEpisodeNumber = 100
};
_capabilities = new NewznabCapabilities();
Mocker.GetMock<INewznabCapabilitiesProvider>()
.Setup(v => v.GetCapabilities(It.IsAny<NewznabSettings>()))
.Returns(_capabilities);
}
[Test]
@ -36,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&");
}
@ -50,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&");
}
@ -62,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&");
}
@ -74,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&");
}
@ -86,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&");
@ -100,11 +117,122 @@ 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);
}
[Test]
public void should_not_search_by_rid_if_not_supported()
{
_capabilities.SupportedTvSearchParameters = new[] { "q", "season", "ep" };
var results = Subject.GetSearchRequests(_singleEpisodeSearchCriteria);
results.GetAllTiers().Should().HaveCount(1);
var page = results.GetAllTiers().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.GetTier(0).Should().HaveCount(1);
var page = results.GetAllTiers().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.GetTier(0).Should().HaveCount(1);
var page = results.GetAllTiers().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.GetTier(0).Should().HaveCount(1);
var page = results.GetAllTiers().First().First();
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()
{
_capabilities.SupportedTvSearchParameters = new[] { "q", "tvdbid", "rid", "season", "ep" };
var results = Subject.GetSearchRequests(_singleEpisodeSearchCriteria);
results.GetTier(0).Should().HaveCount(1);
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=");
}
}
}

@ -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);
}

@ -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<SeasonSearchCriteria>()))
.Returns(new List<IEnumerable<IndexerRequest>> { requests });
.Returns(pageable);
var parser = Mocker.GetMock<IParseIndexerResponse>();
Subject._parser = parser.Object;

@ -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);

@ -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<ITorznabCapabilitiesProvider>()
.Setup(v => v.GetCapabilities(It.IsAny<TorznabSettings>()))
.Returns(new TorznabCapabilities());
Mocker.GetMock<INewznabCapabilitiesProvider>()
.Setup(v => v.GetCapabilities(It.IsAny<NewznabSettings>()))
.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);

@ -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<TorznabRequestGenerator>
{
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<string> { "Monkey Island" },
SeasonNumber = 1,
EpisodeNumber = 2
};
_animeSearchCriteria = new AnimeEpisodeSearchCriteria()
{
SceneTitles = new List<String>() { "Monkey+Island" },
AbsoluteEpisodeNumber = 100
};
_capabilities = new TorznabCapabilities();
Mocker.GetMock<ITorznabCapabilitiesProvider>()
.Setup(v => v.GetCapabilities(It.IsAny<TorznabSettings>()))
.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");
}
}
}

@ -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();
}
}
}

@ -226,8 +226,6 @@
<Compile Include="IndexerTests\TorrentRssIndexerTests\TorrentRssParserFactoryFixture.cs" />
<Compile Include="IndexerTests\TorrentRssIndexerTests\TorrentRssSettingsDetectorFixture.cs" />
<Compile Include="IndexerTests\TorznabTests\TorznabFixture.cs" />
<Compile Include="IndexerTests\TorznabTests\TorznabRequestGeneratorFixture.cs" />
<Compile Include="IndexerTests\TorznabTests\TorznabSettingFixture.cs" />
<Compile Include="IndexerTests\NewznabTests\NewznabFixture.cs" />
<Compile Include="IndexerTests\NewznabTests\NewznabRequestGeneratorFixture.cs" />
<Compile Include="IndexerTests\NewznabTests\NewznabSettingFixture.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<IEpisodeService>()
.Verify(v => v.FindEpisode(It.IsAny<int>(), It.IsAny<string>()), 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<IEpisodeService>()
.Verify(v => v.FindEpisode(It.IsAny<int>(), It.IsAny<string>()), 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<IEpisodeService>()
.Verify(v => v.FindEpisode(It.IsAny<int>(), It.IsAny<string>()), 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<IEpisodeService>()
.Verify(v => v.FindEpisode(It.IsAny<int>(), It.IsAny<string>()), 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<IEpisodeService>()
.Verify(v => v.FindEpisodesBySceneNumbering(It.IsAny<int>(), It.IsAny<int>(), It.IsAny<int>()), 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<IEpisodeService>()
.Verify(v => v.FindEpisodesBySceneNumbering(It.IsAny<int>(), It.IsAny<int>(), It.IsAny<int>()), 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<IEpisodeService>()
.Verify(v => v.FindEpisodesBySceneNumbering(It.IsAny<int>(), It.IsAny<int>(), It.IsAny<int>()), 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<IEpisodeService>()
.Verify(v => v.FindEpisode(It.IsAny<int>(), It.IsAny<int>(), It.IsAny<int>()), 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<IEpisodeService>()
.Verify(v => v.FindEpisode(It.IsAny<int>(), It.IsAny<int>(), It.IsAny<int>()), 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<IEpisodeService>()
.Verify(v => v.FindEpisode(It.IsAny<int>(), It.IsAny<int>(), It.IsAny<int>()), Times.Once());

@ -59,6 +59,13 @@ namespace NzbDrone.Core.Test.ParserTests.ParsingServiceTests
.Returns(_series);
}
private void GivenMatchByTvdbId()
{
Mocker.GetMock<ISeriesService>()
.Setup(s => s.FindByTvdbId(It.IsAny<Int32>()))
.Returns(_series);
}
private void GivenMatchByTvRageId()
{
Mocker.GetMock<ISeriesService>()
@ -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<ISeriesService>()
.Verify(v => v.FindByTitle(It.IsAny<string>()), Times.Once());
}
[Test]
public void should_use_tvdbid_when_series_title_lookup_fails()
{
GivenMatchByTvdbId();
Subject.Map(_parsedEpisodeInfo, _series.TvdbId, _series.TvRageId);
Mocker.GetMock<ISeriesService>()
.Verify(v => v.FindByTvdbId(It.IsAny<Int32>()), 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<ISeriesService>()
.Verify(v => v.FindByTvRageId(It.IsAny<int>()), Times.Once());
@ -102,7 +120,7 @@ namespace NzbDrone.Core.Test.ParserTests.ParsingServiceTests
.Setup(v => v.FindTvdbId(It.IsAny<string>()))
.Returns(10);
var result = Subject.Map(_parsedEpisodeInfo, _series.TvRageId);
var result = Subject.Map(_parsedEpisodeInfo, _series.TvdbId, _series.TvRageId);
Mocker.GetMock<ISeriesService>()
.Verify(v => v.FindByTvRageId(It.IsAny<int>()), 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<ISeriesService>()
.Verify(v => v.FindByTitle(It.IsAny<string>()), 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<ISeriesService>()
.Verify(v => v.FindByTitle(It.IsAny<string>()), Times.Once());
}
[Test]
public void should_FindByTvdbId_when_search_criteria_and_FindByTitle_matching_fails()
{
GivenParseResultSeriesDoesntMatchSearchCriteria();
Subject.Map(_parsedEpisodeInfo, 10, 10, _singleEpisodeSearchCriteria);
Mocker.GetMock<ISeriesService>()
.Verify(v => v.FindByTvdbId(It.IsAny<Int32>()), 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<ISeriesService>()
.Verify(v => v.FindByTvRageId(It.IsAny<int>()), Times.Once());
@ -150,7 +179,7 @@ namespace NzbDrone.Core.Test.ParserTests.ParsingServiceTests
.Setup(s => s.FindTvdbId(It.IsAny<string>()))
.Returns(_series.TvdbId);
Subject.Map(_parsedEpisodeInfo, _series.TvRageId, _singleEpisodeSearchCriteria);
Subject.Map(_parsedEpisodeInfo, _series.TvdbId, _series.TvRageId, _singleEpisodeSearchCriteria);
Mocker.GetMock<ISeriesService>()
.Verify(v => v.FindByTitle(It.IsAny<string>()), 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<ISeriesService>()
.Verify(v => v.FindByTitle(It.IsAny<string>()), Times.Never());

@ -95,6 +95,20 @@ namespace NzbDrone.Core.Test.TvTests
.Verify(v => v.UpdateSeries(It.Is<Series>(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<ISeriesService>()
.Verify(v => v.UpdateSeries(It.Is<Series>(s => s.TvMazeId == newSeriesInfo.TvMazeId)));
}
[Test]
public void should_log_error_if_tvdb_id_not_found()
{

@ -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");
}
}
}

@ -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)

@ -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())

@ -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());

@ -10,38 +10,38 @@ namespace NzbDrone.Core.Indexers.BitMeTv
{
public BitMeTvSettings Settings { get; set; }
public virtual IList<IEnumerable<IndexerRequest>> GetRecentRequests()
public virtual IndexerPageableRequestChain GetRecentRequests()
{
var pageableRequests = new List<IEnumerable<IndexerRequest>>();
var pageableRequests = new IndexerPageableRequestChain();
pageableRequests.AddIfNotNull(GetRssRequests());
pageableRequests.Add(GetRssRequests());
return pageableRequests;
}
public virtual IList<IEnumerable<IndexerRequest>> GetSearchRequests(SingleEpisodeSearchCriteria searchCriteria)
public virtual IndexerPageableRequestChain GetSearchRequests(SingleEpisodeSearchCriteria searchCriteria)
{
return new List<IEnumerable<IndexerRequest>>();
return new IndexerPageableRequestChain();
}
public virtual IList<IEnumerable<IndexerRequest>> GetSearchRequests(SeasonSearchCriteria searchCriteria)
public virtual IndexerPageableRequestChain GetSearchRequests(SeasonSearchCriteria searchCriteria)
{
return new List<IEnumerable<IndexerRequest>>();
return new IndexerPageableRequestChain();
}
public virtual IList<IEnumerable<IndexerRequest>> GetSearchRequests(DailyEpisodeSearchCriteria searchCriteria)
public virtual IndexerPageableRequestChain GetSearchRequests(DailyEpisodeSearchCriteria searchCriteria)
{
return new List<IEnumerable<IndexerRequest>>();
return new IndexerPageableRequestChain();
}
public virtual IList<IEnumerable<IndexerRequest>> GetSearchRequests(AnimeEpisodeSearchCriteria searchCriteria)
public virtual IndexerPageableRequestChain GetSearchRequests(AnimeEpisodeSearchCriteria searchCriteria)
{
return new List<IEnumerable<IndexerRequest>>();
return new IndexerPageableRequestChain();
}
public virtual IList<IEnumerable<IndexerRequest>> GetSearchRequests(SpecialEpisodeSearchCriteria searchCriteria)
public virtual IndexerPageableRequestChain GetSearchRequests(SpecialEpisodeSearchCriteria searchCriteria)
{
return new List<IEnumerable<IndexerRequest>>();
return new IndexerPageableRequestChain();
}
private IEnumerable<IndexerRequest> GetRssRequests()

@ -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;

@ -19,18 +19,18 @@ namespace NzbDrone.Core.Indexers.BroadcastheNet
PageSize = 100;
}
public virtual IList<IEnumerable<IndexerRequest>> GetRecentRequests()
public virtual IndexerPageableRequestChain GetRecentRequests()
{
var pageableRequests = new List<IEnumerable<IndexerRequest>>();
var pageableRequests = new IndexerPageableRequestChain();
pageableRequests.AddIfNotNull(GetPagedRequests(MaxPages, null));
pageableRequests.Add(GetPagedRequests(MaxPages, null));
return pageableRequests;
}
public virtual IList<IEnumerable<IndexerRequest>> GetSearchRequests(SingleEpisodeSearchCriteria searchCriteria)
public virtual IndexerPageableRequestChain GetSearchRequests(SingleEpisodeSearchCriteria searchCriteria)
{
var pageableRequest = new List<IEnumerable<IndexerRequest>>();
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<IEnumerable<IndexerRequest>> GetSearchRequests(SeasonSearchCriteria searchCriteria)
public virtual IndexerPageableRequestChain GetSearchRequests(SeasonSearchCriteria searchCriteria)
{
var pageableRequest = new List<IEnumerable<IndexerRequest>>();
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<IEnumerable<IndexerRequest>> GetSearchRequests(DailyEpisodeSearchCriteria searchCriteria)
public virtual IndexerPageableRequestChain GetSearchRequests(DailyEpisodeSearchCriteria searchCriteria)
{
var pageableRequest = new List<IEnumerable<IndexerRequest>>();
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<IEnumerable<IndexerRequest>> GetSearchRequests(AnimeEpisodeSearchCriteria searchCriteria)
public virtual IndexerPageableRequestChain GetSearchRequests(AnimeEpisodeSearchCriteria searchCriteria)
{
var pageableRequest = new List<IEnumerable<IndexerRequest>>();
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<IEnumerable<IndexerRequest>> GetSearchRequests(SpecialEpisodeSearchCriteria searchCriteria)
public virtual IndexerPageableRequestChain GetSearchRequests(SpecialEpisodeSearchCriteria searchCriteria)
{
return new List<IEnumerable<IndexerRequest>>();
return new IndexerPageableRequestChain();
}
private bool AddSeriesSearchParameters(BroadcastheNetTorrentQuery parameters, SearchCriteriaBase searchCriteria)

@ -21,33 +21,33 @@ namespace NzbDrone.Core.Indexers.Fanzub
PageSize = 100;
}
public virtual IList<IEnumerable<IndexerRequest>> GetRecentRequests()
public virtual IndexerPageableRequestChain GetRecentRequests()
{
var pageableRequests = new List<IEnumerable<IndexerRequest>>();
var pageableRequests = new IndexerPageableRequestChain();
pageableRequests.AddIfNotNull(GetPagedRequests(null));
pageableRequests.Add(GetPagedRequests(null));
return pageableRequests;
}
public virtual IList<IEnumerable<IndexerRequest>> GetSearchRequests(SingleEpisodeSearchCriteria searchCriteria)
public virtual IndexerPageableRequestChain GetSearchRequests(SingleEpisodeSearchCriteria searchCriteria)
{
return new List<IEnumerable<IndexerRequest>>();
return new IndexerPageableRequestChain();
}
public virtual IList<IEnumerable<IndexerRequest>> GetSearchRequests(SeasonSearchCriteria searchCriteria)
public virtual IndexerPageableRequestChain GetSearchRequests(SeasonSearchCriteria searchCriteria)
{
return new List<IEnumerable<IndexerRequest>>();
return new IndexerPageableRequestChain();
}
public virtual IList<IEnumerable<IndexerRequest>> GetSearchRequests(DailyEpisodeSearchCriteria searchCriteria)
public virtual IndexerPageableRequestChain GetSearchRequests(DailyEpisodeSearchCriteria searchCriteria)
{
return new List<IEnumerable<IndexerRequest>>();
return new IndexerPageableRequestChain();
}
public virtual IList<IEnumerable<IndexerRequest>> GetSearchRequests(AnimeEpisodeSearchCriteria searchCriteria)
public virtual IndexerPageableRequestChain GetSearchRequests(AnimeEpisodeSearchCriteria searchCriteria)
{
var pageableRequests = new List<IEnumerable<IndexerRequest>>();
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<IEnumerable<IndexerRequest>> GetSearchRequests(SpecialEpisodeSearchCriteria searchCriteria)
public virtual IndexerPageableRequestChain GetSearchRequests(SpecialEpisodeSearchCriteria searchCriteria)
{
return new List<IEnumerable<IndexerRequest>>();
return new IndexerPageableRequestChain();
}
private IEnumerable<IndexerRequest> GetPagedRequests(string query)

@ -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<IEnumerable<IndexerRequest>> GetRecentRequests()
public virtual IndexerPageableRequestChain GetRecentRequests()
{
var pageableRequests = new List<IEnumerable<IndexerRequest>>();
var pageableRequests = new IndexerPageableRequestChain();
pageableRequests.Add(GetRequest(new TorrentQuery()));
return pageableRequests;
}
public IList<IEnumerable<IndexerRequest>> GetSearchRequests(AnimeEpisodeSearchCriteria searchCriteria)
public virtual IndexerPageableRequestChain GetSearchRequests(AnimeEpisodeSearchCriteria searchCriteria)
{
var requests = new List<IEnumerable<IndexerRequest>>();
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<IEnumerable<IndexerRequest>> GetSearchRequests(SpecialEpisodeSearchCriteria searchCriteria)
public virtual IndexerPageableRequestChain GetSearchRequests(SpecialEpisodeSearchCriteria searchCriteria)
{
return new List<IEnumerable<IndexerRequest>>();
return new IndexerPageableRequestChain();
}
public IList<IEnumerable<IndexerRequest>> GetSearchRequests(DailyEpisodeSearchCriteria searchCriteria)
public virtual IndexerPageableRequestChain GetSearchRequests(DailyEpisodeSearchCriteria searchCriteria)
{
var requests = new List<IEnumerable<IndexerRequest>>();
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<IEnumerable<IndexerRequest>> GetSearchRequests(SeasonSearchCriteria searchCriteria)
public virtual IndexerPageableRequestChain GetSearchRequests(SeasonSearchCriteria searchCriteria)
{
var requests = new List<IEnumerable<IndexerRequest>>();
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<IEnumerable<IndexerRequest>> GetSearchRequests(SingleEpisodeSearchCriteria searchCriteria)
public virtual IndexerPageableRequestChain GetSearchRequests(SingleEpisodeSearchCriteria searchCriteria)
{
var requests = new List<IEnumerable<IndexerRequest>>();
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)

@ -111,7 +111,7 @@ namespace NzbDrone.Core.Indexers
return FetchReleases(generator.GetSearchRequests(searchCriteria));
}
protected virtual IList<ReleaseInfo> FetchReleases(IList<IEnumerable<IndexerRequest>> pageableRequests, bool isRecent = false)
protected virtual IList<ReleaseInfo> FetchReleases(IndexerPageableRequestChain pageableRequestChain, bool isRecent = false)
{
var releases = new List<ReleaseInfo>();
var url = string.Empty;
@ -127,6 +127,10 @@ namespace NzbDrone.Core.Indexers
lastReleaseInfo = _indexerStatusService.GetLastRssSyncReleaseInfo(Definition.Id);
}
for (int i = 0; i < pageableRequestChain.Tiers; i++)
{
var pageableRequests = pageableRequestChain.GetTier(i);
foreach (var pageableRequest in pageableRequests)
{
var pagedReleases = new List<ReleaseInfo>();
@ -174,6 +178,12 @@ namespace NzbDrone.Core.Indexers
releases.AddRange(pagedReleases);
}
if (releases.Any())
{
break;
}
}
if (isRecent && !releases.Empty())
{
var ordered = releases.OrderByDescending(v => v.PublishDate).ToList();
@ -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())
{

@ -5,11 +5,11 @@ namespace NzbDrone.Core.Indexers
{
public interface IIndexerRequestGenerator
{
IList<IEnumerable<IndexerRequest>> GetRecentRequests();
IList<IEnumerable<IndexerRequest>> GetSearchRequests(SingleEpisodeSearchCriteria searchCriteria);
IList<IEnumerable<IndexerRequest>> GetSearchRequests(SeasonSearchCriteria searchCriteria);
IList<IEnumerable<IndexerRequest>> GetSearchRequests(DailyEpisodeSearchCriteria searchCriteria);
IList<IEnumerable<IndexerRequest>> GetSearchRequests(AnimeEpisodeSearchCriteria searchCriteria);
IList<IEnumerable<IndexerRequest>> 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);
}
}

@ -9,38 +9,38 @@ namespace NzbDrone.Core.Indexers.IPTorrents
{
public IPTorrentsSettings Settings { get; set; }
public virtual IList<IEnumerable<IndexerRequest>> GetRecentRequests()
public virtual IndexerPageableRequestChain GetRecentRequests()
{
var pageableRequests = new List<IEnumerable<IndexerRequest>>();
var pageableRequests = new IndexerPageableRequestChain();
pageableRequests.AddIfNotNull(GetRssRequests());
pageableRequests.Add(GetRssRequests());
return pageableRequests;
}
public virtual IList<IEnumerable<IndexerRequest>> GetSearchRequests(SingleEpisodeSearchCriteria searchCriteria)
public virtual IndexerPageableRequestChain GetSearchRequests(SingleEpisodeSearchCriteria searchCriteria)
{
return new List<IEnumerable<IndexerRequest>>();
return new IndexerPageableRequestChain();
}
public virtual IList<IEnumerable<IndexerRequest>> GetSearchRequests(SeasonSearchCriteria searchCriteria)
public virtual IndexerPageableRequestChain GetSearchRequests(SeasonSearchCriteria searchCriteria)
{
return new List<IEnumerable<IndexerRequest>>();
return new IndexerPageableRequestChain();
}
public virtual IList<IEnumerable<IndexerRequest>> GetSearchRequests(DailyEpisodeSearchCriteria searchCriteria)
public virtual IndexerPageableRequestChain GetSearchRequests(DailyEpisodeSearchCriteria searchCriteria)
{
return new List<IEnumerable<IndexerRequest>>();
return new IndexerPageableRequestChain();
}
public virtual IList<IEnumerable<IndexerRequest>> GetSearchRequests(AnimeEpisodeSearchCriteria searchCriteria)
public virtual IndexerPageableRequestChain GetSearchRequests(AnimeEpisodeSearchCriteria searchCriteria)
{
return new List<IEnumerable<IndexerRequest>>();
return new IndexerPageableRequestChain();
}
public virtual IList<IEnumerable<IndexerRequest>> GetSearchRequests(SpecialEpisodeSearchCriteria searchCriteria)
public virtual IndexerPageableRequestChain GetSearchRequests(SpecialEpisodeSearchCriteria searchCriteria)
{
return new List<IEnumerable<IndexerRequest>>();
return new IndexerPageableRequestChain();
}
private IEnumerable<IndexerRequest> GetRssRequests()

@ -0,0 +1,25 @@
using System.Collections;
using System.Collections.Generic;
namespace NzbDrone.Core.Indexers
{
public class IndexerPageableRequest : IEnumerable<IndexerRequest>
{
private readonly IEnumerable<IndexerRequest> _enumerable;
public IndexerPageableRequest(IEnumerable<IndexerRequest> enumerable)
{
_enumerable = enumerable;
}
public IEnumerator<IndexerRequest> GetEnumerator()
{
return _enumerable.GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return _enumerable.GetEnumerator();
}
}
}

@ -0,0 +1,51 @@
using System.Collections.Generic;
using System.Linq;
namespace NzbDrone.Core.Indexers
{
public class IndexerPageableRequestChain
{
private List<List<IndexerPageableRequest>> _chains;
public IndexerPageableRequestChain()
{
_chains = new List<List<IndexerPageableRequest>>();
_chains.Add(new List<IndexerPageableRequest>());
}
public int Tiers
{
get { return _chains.Count; }
}
public IEnumerable<IndexerPageableRequest> GetAllTiers()
{
return _chains.SelectMany(v => v);
}
public IEnumerable<IndexerPageableRequest> GetTier(int index)
{
return _chains[index];
}
public void Add(IEnumerable<IndexerRequest> request)
{
if (request == null) return;
_chains.Last().Add(new IndexerPageableRequest(request));
}
public void AddTier(IEnumerable<IndexerRequest> request)
{
AddTier();
Add(request);
}
public void AddTier()
{
if (_chains.Last().Count == 0) return;
_chains.Add(new List<IndexerPageableRequest>());
}
}
}

@ -20,28 +20,28 @@ namespace NzbDrone.Core.Indexers.KickassTorrents
PageSize = 25;
}
public virtual IList<IEnumerable<IndexerRequest>> GetRecentRequests()
public virtual IndexerPageableRequestChain GetRecentRequests()
{
var pageableRequests = new List<IEnumerable<IndexerRequest>>();
var pageableRequests = new IndexerPageableRequestChain();
pageableRequests.AddIfNotNull(GetPagedRequests(MaxPages, "tv"));
pageableRequests.Add(GetPagedRequests(MaxPages, "tv"));
return pageableRequests;
}
public virtual IList<IEnumerable<IndexerRequest>> GetSearchRequests(SingleEpisodeSearchCriteria searchCriteria)
public virtual IndexerPageableRequestChain GetSearchRequests(SingleEpisodeSearchCriteria searchCriteria)
{
var pageableRequests = new List<IEnumerable<IndexerRequest>>();
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<IEnumerable<IndexerRequest>> GetSearchRequests(SeasonSearchCriteria searchCriteria)
public virtual IndexerPageableRequestChain GetSearchRequests(SeasonSearchCriteria searchCriteria)
{
var pageableRequests = new List<IEnumerable<IndexerRequest>>();
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<IEnumerable<IndexerRequest>> GetSearchRequests(DailyEpisodeSearchCriteria searchCriteria)
public virtual IndexerPageableRequestChain GetSearchRequests(DailyEpisodeSearchCriteria searchCriteria)
{
var pageableRequests = new List<IEnumerable<IndexerRequest>>();
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<IEnumerable<IndexerRequest>> GetSearchRequests(AnimeEpisodeSearchCriteria searchCriteria)
public virtual IndexerPageableRequestChain GetSearchRequests(AnimeEpisodeSearchCriteria searchCriteria)
{
return new List<IEnumerable<IndexerRequest>>();
return new IndexerPageableRequestChain();
}
public virtual IList<IEnumerable<IndexerRequest>> GetSearchRequests(SpecialEpisodeSearchCriteria searchCriteria)
public virtual IndexerPageableRequestChain GetSearchRequests(SpecialEpisodeSearchCriteria searchCriteria)
{
var pageableRequests = new List<IEnumerable<IndexerRequest>>();
var pageableRequests = new IndexerPageableRequestChain();
foreach (var queryTitle in searchCriteria.EpisodeQueryTitles)
{
pageableRequests.AddIfNotNull(GetPagedRequests(MaxPages, "usearch",
pageableRequests.Add(GetPagedRequests(MaxPages, "usearch",
PrepareQuery(queryTitle),
"category:tv"));
}

@ -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<NewznabSettings>
{
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<ValidationFailure> 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;
}
}
}

@ -0,0 +1,30 @@
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 bool SupportsAggregateIdSearch { get; set; }
public List<NewznabCategory> 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<NewznabCategory>();
}
}
public class NewznabCategory
{
public int Id { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public List<NewznabCategory> Subcategories { get; set; }
}
}

@ -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<TorznabCapabilities> _capabilitiesCache;
private readonly ICached<NewznabCapabilities> _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<TorznabCapabilities>(GetType());
_capabilitiesCache = cacheManager.GetCache<NewznabCapabilities>(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");
@ -89,6 +89,7 @@ namespace NzbDrone.Core.Indexers.Torznab
else if (xmlTvSearch.Attribute("supportedParams") != null)
{
capabilities.SupportedTvSearchParameters = xmlTvSearch.Attribute("supportedParams").Value.Split(',');
capabilities.SupportsAggregateIdSearch = true;
}
}
@ -97,17 +98,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<TorznabCategory>()
Subcategories = new List<NewznabCategory>()
};
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,

@ -9,144 +9,244 @@ 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;
}
public virtual IList<IEnumerable<IndexerRequest>> GetRecentRequests()
private bool SupportsSearch
{
var pageableRequests = new List<IEnumerable<IndexerRequest>>();
pageableRequests.AddIfNotNull(GetPagedRequests(MaxPages, Settings.Categories.Concat(Settings.AnimeCategories), "tvsearch", ""));
get
{
var capabilities = _capabilitiesProvider.GetCapabilities(Settings);
return pageableRequests;
return capabilities.SupportedSearchParameters != null &&
capabilities.SupportedSearchParameters.Contains("q");
}
}
public virtual IList<IEnumerable<IndexerRequest>> GetSearchRequests(SingleEpisodeSearchCriteria searchCriteria)
private bool SupportsTvSearch
{
var pageableRequests = new List<IEnumerable<IndexerRequest>>();
if (searchCriteria.Series.TvRageId > 0)
get
{
pageableRequests.AddIfNotNull(GetPagedRequests(MaxPages, Settings.Categories, "tvsearch",
String.Format("&rid={0}&season={1}&ep={2}",
searchCriteria.Series.TvRageId,
searchCriteria.SeasonNumber,
searchCriteria.EpisodeNumber)));
var capabilities = _capabilitiesProvider.GetCapabilities(Settings);
return capabilities.SupportedTvSearchParameters != null &&
capabilities.SupportedTvSearchParameters.Contains("q") &&
capabilities.SupportedTvSearchParameters.Contains("season") &&
capabilities.SupportedTvSearchParameters.Contains("ep");
}
else
}
private bool SupportsTvdbSearch
{
foreach (var queryTitle in searchCriteria.QueryTitles)
get
{
pageableRequests.AddIfNotNull(GetPagedRequests(MaxPages, Settings.Categories, "tvsearch",
String.Format("&q={0}&season={1}&ep={2}",
NewsnabifyTitle(queryTitle),
searchCriteria.SeasonNumber,
searchCriteria.EpisodeNumber)));
var capabilities = _capabilitiesProvider.GetCapabilities(Settings);
return capabilities.SupportedTvSearchParameters != null &&
capabilities.SupportedTvSearchParameters.Contains("tvdbid") &&
capabilities.SupportedTvSearchParameters.Contains("season") &&
capabilities.SupportedTvSearchParameters.Contains("ep");
}
}
return pageableRequests;
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<IEnumerable<IndexerRequest>> GetSearchRequests(SeasonSearchCriteria searchCriteria)
private bool SupportsTvMazeSearch
{
var pageableRequests = new List<IEnumerable<IndexerRequest>>();
if (searchCriteria.Series.TvRageId > 0)
get
{
pageableRequests.AddIfNotNull(GetPagedRequests(MaxPages, Settings.Categories, "tvsearch",
String.Format("&rid={0}&season={1}",
searchCriteria.Series.TvRageId,
searchCriteria.SeasonNumber)));
var capabilities = _capabilitiesProvider.GetCapabilities(Settings);
return capabilities.SupportedTvSearchParameters != null &&
capabilities.SupportedTvSearchParameters.Contains("tvmazeid") &&
capabilities.SupportedTvSearchParameters.Contains("season") &&
capabilities.SupportedTvSearchParameters.Contains("ep");
}
else
}
private bool SupportsAggregatedIdSearch
{
foreach (var queryTitle in searchCriteria.QueryTitles)
get
{
pageableRequests.AddIfNotNull(GetPagedRequests(MaxPages, Settings.Categories, "tvsearch",
String.Format("&q={0}&season={1}",
NewsnabifyTitle(queryTitle),
searchCriteria.SeasonNumber)));
var capabilities = _capabilitiesProvider.GetCapabilities(Settings);
return capabilities.SupportsAggregateIdSearch;
}
}
public virtual IndexerPageableRequestChain GetRecentRequests()
{
var pageableRequests = new IndexerPageableRequestChain();
var capabilities = _capabilitiesProvider.GetCapabilities(Settings);
if (capabilities.SupportedTvSearchParameters != null)
{
pageableRequests.Add(GetPagedRequests(MaxPages, Settings.Categories.Concat(Settings.AnimeCategories), "tvsearch", ""));
}
return pageableRequests;
}
public virtual IList<IEnumerable<IndexerRequest>> GetSearchRequests(DailyEpisodeSearchCriteria searchCriteria)
public virtual IndexerPageableRequestChain GetSearchRequests(SingleEpisodeSearchCriteria searchCriteria)
{
var pageableRequests = new List<IEnumerable<IndexerRequest>>();
var pageableRequests = new IndexerPageableRequestChain();
if (searchCriteria.Series.TvRageId > 0)
{
pageableRequests.AddIfNotNull(GetPagedRequests(MaxPages, Settings.Categories, "tvsearch",
String.Format("&rid={0}&season={1:yyyy}&ep={1:MM}/{1:dd}",
searchCriteria.Series.TvRageId,
searchCriteria.AirDate)));
AddTvIdPageableRequests(pageableRequests, MaxPages, Settings.Categories, searchCriteria,
string.Format("&season={0}&ep={1}",
searchCriteria.SeasonNumber,
searchCriteria.EpisodeNumber));
return pageableRequests;
}
else
{
foreach (var queryTitle in searchCriteria.QueryTitles)
public virtual IndexerPageableRequestChain GetSearchRequests(SeasonSearchCriteria searchCriteria)
{
pageableRequests.AddIfNotNull(GetPagedRequests(MaxPages, Settings.Categories, "tvsearch",
String.Format("&q={0}&season={1:yyyy}&ep={1:MM}/{1:dd}",
NewsnabifyTitle(queryTitle),
searchCriteria.AirDate)));
}
var pageableRequests = new IndexerPageableRequestChain();
AddTvIdPageableRequests(pageableRequests, MaxPages, Settings.Categories, searchCriteria,
string.Format("&season={0}",
searchCriteria.SeasonNumber));
return pageableRequests;
}
public virtual IndexerPageableRequestChain GetSearchRequests(DailyEpisodeSearchCriteria searchCriteria)
{
var pageableRequests = new IndexerPageableRequestChain();
AddTvIdPageableRequests(pageableRequests, MaxPages, Settings.Categories, searchCriteria,
string.Format("&season={0:yyyy}&ep={0:MM}/{0:dd}",
searchCriteria.AirDate));
return pageableRequests;
}
public virtual IList<IEnumerable<IndexerRequest>> GetSearchRequests(AnimeEpisodeSearchCriteria searchCriteria)
public virtual IndexerPageableRequestChain GetSearchRequests(AnimeEpisodeSearchCriteria searchCriteria)
{
var pageableRequests = new List<IEnumerable<IndexerRequest>>();
var pageableRequests = new IndexerPageableRequestChain();
if (SupportsSearch)
{
foreach (var queryTitle in searchCriteria.QueryTitles)
{
pageableRequests.AddIfNotNull(GetPagedRequests(MaxPages, Settings.AnimeCategories, "search",
String.Format("&q={0}+{1:00}",
pageableRequests.Add(GetPagedRequests(MaxPages, Settings.AnimeCategories, "search",
string.Format("&q={0}+{1:00}",
NewsnabifyTitle(queryTitle),
searchCriteria.AbsoluteEpisodeNumber)));
}
}
return pageableRequests;
}
public virtual IList<IEnumerable<IndexerRequest>> GetSearchRequests(SpecialEpisodeSearchCriteria searchCriteria)
public virtual IndexerPageableRequestChain GetSearchRequests(SpecialEpisodeSearchCriteria searchCriteria)
{
var pageableRequests = new List<IEnumerable<IndexerRequest>>();
var pageableRequests = new IndexerPageableRequestChain();
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}",
pageableRequests.Add(GetPagedRequests(MaxPages, Settings.Categories.Concat(Settings.AnimeCategories), "search",
string.Format("&q={0}",
query)));
}
}
return pageableRequests;
}
private IEnumerable<IndexerRequest> GetPagedRequests(Int32 maxPages, IEnumerable<Int32> categories, String searchType, String parameters)
private void AddTvIdPageableRequests(IndexerPageableRequestChain chain, int maxPages, IEnumerable<int> 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;
}
if (searchCriteria.Series.TvMazeId > 0 && SupportsTvMazeSearch)
{
ids += "&tvmazeid=" + searchCriteria.Series.TvMazeId;
}
chain.Add(GetPagedRequests(maxPages, categories, "tvsearch", ids + parameters));
}
else
{
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)));
}
else if (searchCriteria.Series.TvMazeId > 0 && SupportsTvMazeSearch)
{
chain.Add(GetPagedRequests(maxPages, categories, "tvsearch",
string.Format("&tvmazeid={0}{1}", searchCriteria.Series.TvMazeId, 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<IndexerRequest> GetPagedRequests(int maxPages, IEnumerable<int> 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 +255,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");
}

@ -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");

@ -61,24 +61,24 @@ namespace NzbDrone.Core.Indexers.Newznab
public NewznabSettings()
{
Categories = new[] {5030, 5040};
AnimeCategories = Enumerable.Empty<Int32>();
Categories = new[] { 5030, 5040 };
AnimeCategories = Enumerable.Empty<int>();
}
[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<Int32> Categories { get; set; }
public IEnumerable<int> Categories { get; set; }
[FieldDefinition(3, Label = "Anime Categories", HelpText = "Comma Separated list, leave blank to disable anime", Advanced = true)]
public IEnumerable<Int32> AnimeCategories { get; set; }
public IEnumerable<int> 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()
{

@ -19,46 +19,46 @@ namespace NzbDrone.Core.Indexers.Nyaa
PageSize = 100;
}
public virtual IList<IEnumerable<IndexerRequest>> GetRecentRequests()
public virtual IndexerPageableRequestChain GetRecentRequests()
{
var pageableRequests = new List<IEnumerable<IndexerRequest>>();
var pageableRequests = new IndexerPageableRequestChain();
pageableRequests.AddIfNotNull(GetPagedRequests(MaxPages, null));
pageableRequests.Add(GetPagedRequests(MaxPages, null));
return pageableRequests;
}
public virtual IList<IEnumerable<IndexerRequest>> GetSearchRequests(SingleEpisodeSearchCriteria searchCriteria)
public virtual IndexerPageableRequestChain GetSearchRequests(SingleEpisodeSearchCriteria searchCriteria)
{
return new List<IEnumerable<IndexerRequest>>();
return new IndexerPageableRequestChain();
}
public virtual IList<IEnumerable<IndexerRequest>> GetSearchRequests(SeasonSearchCriteria searchCriteria)
public virtual IndexerPageableRequestChain GetSearchRequests(SeasonSearchCriteria searchCriteria)
{
return new List<IEnumerable<IndexerRequest>>();
return new IndexerPageableRequestChain();
}
public virtual IList<IEnumerable<IndexerRequest>> GetSearchRequests(DailyEpisodeSearchCriteria searchCriteria)
public virtual IndexerPageableRequestChain GetSearchRequests(DailyEpisodeSearchCriteria searchCriteria)
{
return new List<IEnumerable<IndexerRequest>>();
return new IndexerPageableRequestChain();
}
public virtual IList<IEnumerable<IndexerRequest>> GetSearchRequests(AnimeEpisodeSearchCriteria searchCriteria)
public virtual IndexerPageableRequestChain GetSearchRequests(AnimeEpisodeSearchCriteria searchCriteria)
{
var pageableRequests = new List<IEnumerable<IndexerRequest>>();
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<IEnumerable<IndexerRequest>> GetSearchRequests(SpecialEpisodeSearchCriteria searchCriteria)
public virtual IndexerPageableRequestChain GetSearchRequests(SpecialEpisodeSearchCriteria searchCriteria)
{
var pageableRequests = new List<IEnumerable<IndexerRequest>>();
var pageableRequests = new IndexerPageableRequestChain();
foreach (var queryTitle in searchCriteria.EpisodeQueryTitles)
{
pageableRequests.AddIfNotNull(GetPagedRequests(MaxPages,
pageableRequests.Add(GetPagedRequests(MaxPages,
string.Format("&term={0}",
PrepareQuery(queryTitle))));
}

@ -17,22 +17,22 @@ namespace NzbDrone.Core.Indexers.Omgwtfnzbs
BaseUrl = "https://rss.omgwtfnzbs.org/rss-download.php";
}
public virtual IList<IEnumerable<IndexerRequest>> GetRecentRequests()
public virtual IndexerPageableRequestChain GetRecentRequests()
{
var pageableRequests = new List<IEnumerable<IndexerRequest>>();
var pageableRequests = new IndexerPageableRequestChain();
pageableRequests.AddIfNotNull(GetPagedRequests(null));
pageableRequests.Add(GetPagedRequests(null));
return pageableRequests;
}
public virtual IList<IEnumerable<IndexerRequest>> GetSearchRequests(SingleEpisodeSearchCriteria searchCriteria)
public virtual IndexerPageableRequestChain GetSearchRequests(SingleEpisodeSearchCriteria searchCriteria)
{
var pageableRequests = new List<IEnumerable<IndexerRequest>>();
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<IEnumerable<IndexerRequest>> GetSearchRequests(SeasonSearchCriteria searchCriteria)
public virtual IndexerPageableRequestChain GetSearchRequests(SeasonSearchCriteria searchCriteria)
{
var pageableRequests = new List<IEnumerable<IndexerRequest>>();
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<IEnumerable<IndexerRequest>> GetSearchRequests(DailyEpisodeSearchCriteria searchCriteria)
public virtual IndexerPageableRequestChain GetSearchRequests(DailyEpisodeSearchCriteria searchCriteria)
{
var pageableRequests = new List<IEnumerable<IndexerRequest>>();
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<IEnumerable<IndexerRequest>> GetSearchRequests(AnimeEpisodeSearchCriteria searchCriteria)
public virtual IndexerPageableRequestChain GetSearchRequests(AnimeEpisodeSearchCriteria searchCriteria)
{
return new List<IEnumerable<IndexerRequest>>();
return new IndexerPageableRequestChain();
}
public virtual IList<IEnumerable<IndexerRequest>> GetSearchRequests(SpecialEpisodeSearchCriteria searchCriteria)
public virtual IndexerPageableRequestChain GetSearchRequests(SpecialEpisodeSearchCriteria searchCriteria)
{
var pageableRequests = new List<IEnumerable<IndexerRequest>>();
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;

@ -58,10 +58,18 @@ namespace NzbDrone.Core.Indexers.Rarbg
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)
{
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);
}

@ -17,50 +17,50 @@ namespace NzbDrone.Core.Indexers.Rarbg
_tokenProvider = tokenProvider;
}
public virtual IList<IEnumerable<IndexerRequest>> GetRecentRequests()
public virtual IndexerPageableRequestChain GetRecentRequests()
{
var pageableRequests = new List<IEnumerable<IndexerRequest>>();
var pageableRequests = new IndexerPageableRequestChain();
pageableRequests.AddIfNotNull(GetPagedRequests("list", null, null));
pageableRequests.Add(GetPagedRequests("list", null, null));
return pageableRequests;
}
public virtual IList<IEnumerable<IndexerRequest>> GetSearchRequests(SingleEpisodeSearchCriteria searchCriteria)
public virtual IndexerPageableRequestChain GetSearchRequests(SingleEpisodeSearchCriteria searchCriteria)
{
var pageableRequests = new List<IEnumerable<IndexerRequest>>();
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<IEnumerable<IndexerRequest>> GetSearchRequests(SeasonSearchCriteria searchCriteria)
public virtual IndexerPageableRequestChain GetSearchRequests(SeasonSearchCriteria searchCriteria)
{
var pageableRequests = new List<IEnumerable<IndexerRequest>>();
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<IEnumerable<IndexerRequest>> GetSearchRequests(DailyEpisodeSearchCriteria searchCriteria)
public virtual IndexerPageableRequestChain GetSearchRequests(DailyEpisodeSearchCriteria searchCriteria)
{
var pageableRequests = new List<IEnumerable<IndexerRequest>>();
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<IEnumerable<IndexerRequest>> GetSearchRequests(AnimeEpisodeSearchCriteria searchCriteria)
public virtual IndexerPageableRequestChain GetSearchRequests(AnimeEpisodeSearchCriteria searchCriteria)
{
return new List<IEnumerable<IndexerRequest>>();
return new IndexerPageableRequestChain();
}
public virtual IList<IEnumerable<IndexerRequest>> GetSearchRequests(SpecialEpisodeSearchCriteria searchCriteria)
public virtual IndexerPageableRequestChain GetSearchRequests(SpecialEpisodeSearchCriteria searchCriteria)
{
return new List<IEnumerable<IndexerRequest>>();
return new IndexerPageableRequestChain();
}
private IEnumerable<IndexerRequest> GetPagedRequests(string mode, int? tvdbId, string query, params object[] args)

@ -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<IEnumerable<IndexerRequest>> GetRecentRequests()
public virtual IndexerPageableRequestChain GetRecentRequests()
{
var pageableRequests = new List<IEnumerable<IndexerRequest>>();
var pageableRequests = new IndexerPageableRequestChain();
pageableRequests.Add(new[] { new IndexerRequest(_baseUrl, HttpAccept.Rss) });
return pageableRequests;
}
public virtual IList<IEnumerable<IndexerRequest>> GetSearchRequests(SingleEpisodeSearchCriteria searchCriteria)
public virtual IndexerPageableRequestChain GetSearchRequests(SingleEpisodeSearchCriteria searchCriteria)
{
return new List<IEnumerable<IndexerRequest>>();
return new IndexerPageableRequestChain();
}
public virtual IList<IEnumerable<IndexerRequest>> GetSearchRequests(SeasonSearchCriteria searchCriteria)
public virtual IndexerPageableRequestChain GetSearchRequests(SeasonSearchCriteria searchCriteria)
{
return new List<IEnumerable<IndexerRequest>>();
return new IndexerPageableRequestChain();
}
public virtual IList<IEnumerable<IndexerRequest>> GetSearchRequests(DailyEpisodeSearchCriteria searchCriteria)
public virtual IndexerPageableRequestChain GetSearchRequests(DailyEpisodeSearchCriteria searchCriteria)
{
return new List<IEnumerable<IndexerRequest>>();
return new IndexerPageableRequestChain();
}
public virtual IList<IEnumerable<IndexerRequest>> GetSearchRequests(AnimeEpisodeSearchCriteria searchCriteria)
public virtual IndexerPageableRequestChain GetSearchRequests(AnimeEpisodeSearchCriteria searchCriteria)
{
return new List<IEnumerable<IndexerRequest>>();
return new IndexerPageableRequestChain();
}
public virtual IList<IEnumerable<IndexerRequest>> GetSearchRequests(SpecialEpisodeSearchCriteria searchCriteria)
public virtual IndexerPageableRequestChain GetSearchRequests(SpecialEpisodeSearchCriteria searchCriteria)
{
return new List<IEnumerable<IndexerRequest>>();
return new IndexerPageableRequestChain();
}
}
}

@ -19,62 +19,64 @@ namespace NzbDrone.Core.Indexers.TitansOfTv
PageSize = 100;
}
public IList<IEnumerable<IndexerRequest>> GetRecentRequests()
public virtual IndexerPageableRequestChain GetRecentRequests()
{
var pageableRequests = new List<IEnumerable<IndexerRequest>>();
var pageableRequests = new IndexerPageableRequestChain();
pageableRequests.AddIfNotNull(GetPagedRequests(MaxPages));
pageableRequests.Add(GetPagedRequests(MaxPages));
return pageableRequests;
}
public IList<IEnumerable<IndexerRequest>> GetSearchRequests(SingleEpisodeSearchCriteria searchCriteria)
public virtual IndexerPageableRequestChain GetSearchRequests(SingleEpisodeSearchCriteria searchCriteria)
{
var pageableRequests = new List<IEnumerable<IndexerRequest>>();
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<IEnumerable<IndexerRequest>> GetSearchRequests(SeasonSearchCriteria searchCriteria)
public virtual IndexerPageableRequestChain GetSearchRequests(SeasonSearchCriteria searchCriteria)
{
var pageableRequests = new List<IEnumerable<IndexerRequest>>();
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<IEnumerable<IndexerRequest>> GetSearchRequests(DailyEpisodeSearchCriteria searchCriteria)
public virtual IndexerPageableRequestChain GetSearchRequests(DailyEpisodeSearchCriteria searchCriteria)
{
var pageableRequests = new List<IEnumerable<IndexerRequest>>();
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<IEnumerable<IndexerRequest>> GetSearchRequests(AnimeEpisodeSearchCriteria searchCriteria)
public virtual IndexerPageableRequestChain GetSearchRequests(AnimeEpisodeSearchCriteria searchCriteria)
{
return new List<IEnumerable<IndexerRequest>>();
return new IndexerPageableRequestChain();
}
public IList<IEnumerable<IndexerRequest>> GetSearchRequests(SpecialEpisodeSearchCriteria searchCriteria)
public virtual IndexerPageableRequestChain GetSearchRequests(SpecialEpisodeSearchCriteria searchCriteria)
{
return new List<IEnumerable<IndexerRequest>>();
return new IndexerPageableRequestChain();
}
private IEnumerable<IndexerRequest> GetPagedRequests(int maxPages, int? series_id = null, string episode = null, string season = null, DateTime? air_date = null)

@ -10,38 +10,38 @@ namespace NzbDrone.Core.Indexers.TorrentRss
{
public TorrentRssIndexerSettings Settings { get; set; }
public virtual IList<IEnumerable<IndexerRequest>> GetRecentRequests()
public virtual IndexerPageableRequestChain GetRecentRequests()
{
var pageableRequests = new List<IEnumerable<IndexerRequest>>();
var pageableRequests = new IndexerPageableRequestChain();
pageableRequests.AddIfNotNull(GetRssRequests(null));
pageableRequests.Add(GetRssRequests(null));
return pageableRequests;
}
public virtual IList<IEnumerable<IndexerRequest>> GetSearchRequests(SingleEpisodeSearchCriteria searchCriteria)
public virtual IndexerPageableRequestChain GetSearchRequests(SingleEpisodeSearchCriteria searchCriteria)
{
return new List<IEnumerable<IndexerRequest>>();
return new IndexerPageableRequestChain();
}
public virtual IList<IEnumerable<IndexerRequest>> GetSearchRequests(SeasonSearchCriteria searchCriteria)
public virtual IndexerPageableRequestChain GetSearchRequests(SeasonSearchCriteria searchCriteria)
{
return new List<IEnumerable<IndexerRequest>>();
return new IndexerPageableRequestChain();
}
public virtual IList<IEnumerable<IndexerRequest>> GetSearchRequests(DailyEpisodeSearchCriteria searchCriteria)
public virtual IndexerPageableRequestChain GetSearchRequests(DailyEpisodeSearchCriteria searchCriteria)
{
return new List<IEnumerable<IndexerRequest>>();
return new IndexerPageableRequestChain();
}
public virtual IList<IEnumerable<IndexerRequest>> GetSearchRequests(AnimeEpisodeSearchCriteria searchCriteria)
public virtual IndexerPageableRequestChain GetSearchRequests(AnimeEpisodeSearchCriteria searchCriteria)
{
return new List<IEnumerable<IndexerRequest>>();
return new IndexerPageableRequestChain();
}
public virtual IList<IEnumerable<IndexerRequest>> GetSearchRequests(SpecialEpisodeSearchCriteria searchCriteria)
public virtual IndexerPageableRequestChain GetSearchRequests(SpecialEpisodeSearchCriteria searchCriteria)
{
return new List<IEnumerable<IndexerRequest>>();
return new IndexerPageableRequestChain();
}
private IEnumerable<IndexerRequest> GetRssRequests(string searchParameters)

@ -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

@ -10,38 +10,38 @@ namespace NzbDrone.Core.Indexers.Torrentleech
{
public TorrentleechSettings Settings { get; set; }
public virtual IList<IEnumerable<IndexerRequest>> GetRecentRequests()
public virtual IndexerPageableRequestChain GetRecentRequests()
{
var pageableRequests = new List<IEnumerable<IndexerRequest>>();
var pageableRequests = new IndexerPageableRequestChain();
pageableRequests.AddIfNotNull(GetRssRequests(null));
pageableRequests.Add(GetRssRequests(null));
return pageableRequests;
}
public virtual IList<IEnumerable<IndexerRequest>> GetSearchRequests(SingleEpisodeSearchCriteria searchCriteria)
public virtual IndexerPageableRequestChain GetSearchRequests(SingleEpisodeSearchCriteria searchCriteria)
{
return new List<IEnumerable<IndexerRequest>>();
return new IndexerPageableRequestChain();
}
public virtual IList<IEnumerable<IndexerRequest>> GetSearchRequests(SeasonSearchCriteria searchCriteria)
public virtual IndexerPageableRequestChain GetSearchRequests(SeasonSearchCriteria searchCriteria)
{
return new List<IEnumerable<IndexerRequest>>();
return new IndexerPageableRequestChain();
}
public virtual IList<IEnumerable<IndexerRequest>> GetSearchRequests(DailyEpisodeSearchCriteria searchCriteria)
public virtual IndexerPageableRequestChain GetSearchRequests(DailyEpisodeSearchCriteria searchCriteria)
{
return new List<IEnumerable<IndexerRequest>>();
return new IndexerPageableRequestChain();
}
public virtual IList<IEnumerable<IndexerRequest>> GetSearchRequests(AnimeEpisodeSearchCriteria searchCriteria)
public virtual IndexerPageableRequestChain GetSearchRequests(AnimeEpisodeSearchCriteria searchCriteria)
{
return new List<IEnumerable<IndexerRequest>>();
return new IndexerPageableRequestChain();
}
public virtual IList<IEnumerable<IndexerRequest>> GetSearchRequests(SpecialEpisodeSearchCriteria searchCriteria)
public virtual IndexerPageableRequestChain GetSearchRequests(SpecialEpisodeSearchCriteria searchCriteria)
{
return new List<IEnumerable<IndexerRequest>>();
return new IndexerPageableRequestChain();
}
private IEnumerable<IndexerRequest> GetRssRequests(string searchParameters)

@ -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<TorznabSettings>
{
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;
}

@ -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<TorznabCategory> Categories { get; set; }
public TorznabCapabilities()
{
SupportedSearchParameters = new[] { "q", "offset", "limit" };
SupportedTvSearchParameters = new[] { "q", "rid", "season", "ep", "offset", "limit" };
Categories = new List<TorznabCategory>();
}
}
public class TorznabCategory
{
public int Id { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public List<TorznabCategory> Subcategories { get; set; }
}
}

@ -8,8 +8,7 @@ namespace NzbDrone.Core.Indexers.Torznab
{
}
public TorznabException(string message)
: base(message)
public TorznabException(string message) : base(message)
{
}
}

@ -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<IEnumerable<IndexerRequest>> GetRecentRequests()
{
var pageableRequests = new List<IEnumerable<IndexerRequest>>();
var capabilities = _capabilitiesProvider.GetCapabilities(Settings);
if (capabilities.SupportedTvSearchParameters != null)
{
pageableRequests.AddIfNotNull(GetPagedRequests(MaxPages, Settings.Categories.Concat(Settings.AnimeCategories), "tvsearch", ""));
}
return pageableRequests;
}
public virtual IList<IEnumerable<IndexerRequest>> GetSearchRequests(SingleEpisodeSearchCriteria searchCriteria)
{
var pageableRequests = new List<IEnumerable<IndexerRequest>>();
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<IEnumerable<IndexerRequest>> GetSearchRequests(SeasonSearchCriteria searchCriteria)
{
var pageableRequests = new List<IEnumerable<IndexerRequest>>();
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<IEnumerable<IndexerRequest>> GetSearchRequests(DailyEpisodeSearchCriteria searchCriteria)
{
var pageableRequests = new List<IEnumerable<IndexerRequest>>();
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<IEnumerable<IndexerRequest>> GetSearchRequests(AnimeEpisodeSearchCriteria searchCriteria)
{
var pageableRequests = new List<IEnumerable<IndexerRequest>>();
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<IEnumerable<IndexerRequest>> GetSearchRequests(SpecialEpisodeSearchCriteria searchCriteria)
{
var pageableRequests = new List<IEnumerable<IndexerRequest>>();
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<IndexerRequest> GetPagedRequests(int maxPages, IEnumerable<int> 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");
}
}
}

@ -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);

@ -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)
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<int>();
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<int> Categories { get; set; }
[FieldDefinition(3, Label = "Anime Categories", HelpText = "Comma Separated list, leave blank to disable anime", Advanced = true)]
public IEnumerable<int> 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));

@ -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; }

@ -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);

@ -272,6 +272,7 @@
<Compile Include="Datastore\Migration\091_added_indexerstatus.cs" />
<Compile Include="Datastore\Migration\093_naming_config_replace_characters.cs" />
<Compile Include="Datastore\Migration\092_add_unverifiedscenenumbering.cs" />
<Compile Include="Datastore\Migration\094_add_tvmazeid.cs" />
<Compile Include="Datastore\Migration\Framework\MigrationContext.cs" />
<Compile Include="Datastore\Migration\Framework\MigrationController.cs" />
<Compile Include="Datastore\Migration\Framework\MigrationDbFactory.cs" />
@ -503,6 +504,8 @@
<Compile Include="Indexers\IndexerBase.cs" />
<Compile Include="Indexers\IndexerDefinition.cs" />
<Compile Include="Indexers\IndexerFactory.cs" />
<Compile Include="Indexers\IndexerPageableRequest.cs" />
<Compile Include="Indexers\IndexerPageableRequestChain.cs" />
<Compile Include="Indexers\IndexerStatusRepository.cs" />
<Compile Include="Indexers\IndexerRepository.cs" />
<Compile Include="Indexers\IndexerRequest.cs" />
@ -519,6 +522,8 @@
<Compile Include="Indexers\KickassTorrents\KickassTorrentsSettings.cs" />
<Compile Include="Indexers\KickassTorrents\KickassTorrentsRequestGenerator.cs" />
<Compile Include="Indexers\Newznab\Newznab.cs" />
<Compile Include="Indexers\Newznab\NewznabCapabilities.cs" />
<Compile Include="Indexers\Newznab\NewznabCapabilitiesProvider.cs" />
<Compile Include="Indexers\Newznab\NewznabException.cs" />
<Compile Include="Indexers\Newznab\NewznabRequestGenerator.cs" />
<Compile Include="Indexers\Newznab\NewznabRssParser.cs" />
@ -558,11 +563,8 @@
<Compile Include="Indexers\TorrentRss\TorrentRssParserFactory.cs" />
<Compile Include="Indexers\TorrentRss\TorrentRssSettingsDetector.cs" />
<Compile Include="Indexers\TorrentRssParser.cs" />
<Compile Include="Indexers\Torznab\TorznabCapabilities.cs" />
<Compile Include="Indexers\Torznab\TorznabCapabilitiesProvider.cs" />
<Compile Include="Indexers\Torznab\Torznab.cs" />
<Compile Include="Indexers\Torznab\TorznabException.cs" />
<Compile Include="Indexers\Torznab\TorznabRequestGenerator.cs" />
<Compile Include="Indexers\Torznab\TorznabRssParser.cs" />
<Compile Include="Indexers\Torznab\TorznabSettings.cs" />
<Compile Include="Indexers\Wombles\Wombles.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();

@ -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<Int32> episodeIds);
RemoteEpisode Map(ParsedEpisodeInfo parsedEpisodeInfo, int tvdbId, int tvRageId, SearchCriteriaBase searchCriteria = null);
RemoteEpisode Map(ParsedEpisodeInfo parsedEpisodeInfo, int seriesId, IEnumerable<int> episodeIds);
List<Episode> 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 (searchCriteria.Series.TvdbId == tvdbId)
if (tvdbId == 0)
tvdbId = _sceneMappingService.FindTvdbId(title) ?? 0;
if (tvdbId != 0 && tvdbId == searchCriteria.Series.TvdbId)
{
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

@ -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;

@ -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; }

@ -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;
});

@ -40,6 +40,10 @@
{{#if tvRageId}}
<a href="{{tvRageUrl}}" class="label label-info">TV Rage</a>
{{/if}}
{{#if tvMazeId}}
<a href="{{tvMazeUrl}}" class="label label-info">TV Maze</a>
{{/if}}
</span>
</div>
</div>

Loading…
Cancel
Save