From ebf0dbc1d0f5336444b71683d97e5da63907a37c Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Sun, 17 Aug 2014 19:25:00 -0700 Subject: [PATCH] New: Enable/Disable RSS Sync/Searching on a per indexer basis --- .../MappingTests/ResourceMappingFixture.cs | 3 +- src/NzbDrone.Api/Indexers/IndexerResource.cs | 5 +- src/NzbDrone.Api/Mapping/MappingValidation.cs | 5 - src/NzbDrone.Api/ProviderModuleBase.cs | 10 +- .../HealthCheck/Checks/IndexerCheckFixture.cs | 88 ++++++++++++++--- .../NzbSearchServiceFixture.cs | 5 +- .../059_add_enable_options_to_indexers.cs | 19 ++++ .../060_remove_enable_from_indexers.cs | 15 +++ src/NzbDrone.Core/Datastore/TableMapping.cs | 10 +- .../Download/DownloadClientFactory.cs | 2 +- .../HealthCheck/Checks/IndexerCheck.cs | 22 ++++- .../IndexerSearch/NzbSearchService.cs | 2 +- src/NzbDrone.Core/Indexers/Animezb/Animezb.cs | 2 +- src/NzbDrone.Core/Indexers/Fanzub/Fanzub.cs | 2 +- .../Indexers/FetchAndParseRssService.cs | 2 +- src/NzbDrone.Core/Indexers/IIndexer.cs | 3 +- src/NzbDrone.Core/Indexers/IndexerBase.cs | 7 +- .../Indexers/IndexerDefinition.cs | 15 ++- src/NzbDrone.Core/Indexers/IndexerFactory.cs | 23 +++-- src/NzbDrone.Core/Indexers/Newznab/Newznab.cs | 94 +++++++------------ src/NzbDrone.Core/Indexers/Wombles/Wombles.cs | 3 +- src/NzbDrone.Core/NzbDrone.Core.csproj | 2 + .../ThingiProvider/IProviderFactory.cs | 2 + .../ThingiProvider/ProviderFactory.cs | 4 +- .../IndexerIntegrationFixture.cs | 2 +- .../IntegrationTest.cs | 2 +- .../Indexers/Add/IndexerAddItemView.js | 18 ++-- .../Edit/IndexerEditViewTemplate.html | 26 ++++- .../Indexers/IndexerItemViewTemplate.html | 18 +++- 29 files changed, 279 insertions(+), 132 deletions(-) create mode 100644 src/NzbDrone.Core/Datastore/Migration/059_add_enable_options_to_indexers.cs create mode 100644 src/NzbDrone.Core/Datastore/Migration/060_remove_enable_from_indexers.cs diff --git a/src/NzbDrone.Api.Test/MappingTests/ResourceMappingFixture.cs b/src/NzbDrone.Api.Test/MappingTests/ResourceMappingFixture.cs index 1e02507f0..8181d46a7 100644 --- a/src/NzbDrone.Api.Test/MappingTests/ResourceMappingFixture.cs +++ b/src/NzbDrone.Api.Test/MappingTests/ResourceMappingFixture.cs @@ -37,7 +37,7 @@ namespace NzbDrone.Api.Test.MappingTests [TestCase(typeof(Episode), typeof(EpisodeResource))] [TestCase(typeof(RootFolder), typeof(RootFolderResource))] [TestCase(typeof(NamingConfig), typeof(NamingConfigResource))] - [TestCase(typeof(IndexerDefinition), typeof(IndexerResource))] +// [TestCase(typeof(IndexerDefinition), typeof(IndexerResource))] //TODO: Ignoring because we don't have a good way to ignore properties with value injector [TestCase(typeof(ReleaseInfo), typeof(ReleaseResource))] [TestCase(typeof(ParsedEpisodeInfo), typeof(ReleaseResource))] [TestCase(typeof(DownloadDecision), typeof(ReleaseResource))] @@ -64,7 +64,6 @@ namespace NzbDrone.Api.Test.MappingTests modelWithLazy.Guid.IsLoaded.Should().BeFalse(); } - [Test] public void should_map_lay_loaded_values_should_be_inject_if_loaded() { diff --git a/src/NzbDrone.Api/Indexers/IndexerResource.cs b/src/NzbDrone.Api/Indexers/IndexerResource.cs index 651d57ccf..246910765 100644 --- a/src/NzbDrone.Api/Indexers/IndexerResource.cs +++ b/src/NzbDrone.Api/Indexers/IndexerResource.cs @@ -5,7 +5,10 @@ namespace NzbDrone.Api.Indexers { public class IndexerResource : ProviderResource { - public Boolean Enable { get; set; } + public Boolean EnableRss { get; set; } + public Boolean EnableSearch { get; set; } + public Boolean SupportsRss { get; set; } + public Boolean SupportsSearch { get; set; } public DownloadProtocol Protocol { get; set; } } } \ No newline at end of file diff --git a/src/NzbDrone.Api/Mapping/MappingValidation.cs b/src/NzbDrone.Api/Mapping/MappingValidation.cs index 13e657b13..29596c155 100644 --- a/src/NzbDrone.Api/Mapping/MappingValidation.cs +++ b/src/NzbDrone.Api/Mapping/MappingValidation.cs @@ -18,10 +18,8 @@ namespace NzbDrone.Api.Mapping } PrintExtraProperties(modelType, resourceType); - } - private static void PrintExtraProperties(Type modelType, Type resourceType) { var resourceBaseProperties = typeof(RestResource).GetProperties().Select(c => c.Name); @@ -34,8 +32,6 @@ namespace NzbDrone.Api.Mapping { Console.WriteLine("Extra: [{0}]", extraProp); } - - } private static string GetError(Type resourceType, PropertyInfo modelProperty) @@ -54,6 +50,5 @@ namespace NzbDrone.Api.Mapping return null; } - } } \ No newline at end of file diff --git a/src/NzbDrone.Api/ProviderModuleBase.cs b/src/NzbDrone.Api/ProviderModuleBase.cs index a35858633..28a475718 100644 --- a/src/NzbDrone.Api/ProviderModuleBase.cs +++ b/src/NzbDrone.Api/ProviderModuleBase.cs @@ -43,7 +43,12 @@ namespace NzbDrone.Api private TProviderResource GetProviderById(int id) { - return _providerFactory.Get(id).InjectTo(); + var definition = _providerFactory.Get(id); + var resource = definition.InjectTo(); + + resource.InjectFrom(_providerFactory.GetProviderCharacteristics(_providerFactory.GetInstance(definition), definition)); + + return resource; } private List GetAll() @@ -56,6 +61,7 @@ namespace NzbDrone.Api { var providerResource = new TProviderResource(); providerResource.InjectFrom(definition); + providerResource.InjectFrom(_providerFactory.GetProviderCharacteristics(_providerFactory.GetInstance(definition), definition)); providerResource.Fields = SchemaBuilder.ToSchema(definition.Settings); result.Add(providerResource); @@ -116,7 +122,7 @@ namespace NzbDrone.Api private Response GetTemplates() { - var defaultDefinitions = _providerFactory.GetDefaultDefinitions(); + var defaultDefinitions = _providerFactory.GetDefaultDefinitions().ToList(); var result = new List(defaultDefinitions.Count()); diff --git a/src/NzbDrone.Core.Test/HealthCheck/Checks/IndexerCheckFixture.cs b/src/NzbDrone.Core.Test/HealthCheck/Checks/IndexerCheckFixture.cs index 574b8dd99..15e7754ad 100644 --- a/src/NzbDrone.Core.Test/HealthCheck/Checks/IndexerCheckFixture.cs +++ b/src/NzbDrone.Core.Test/HealthCheck/Checks/IndexerCheckFixture.cs @@ -15,6 +15,41 @@ namespace NzbDrone.Core.Test.HealthCheck.Checks [TestFixture] public class IndexerCheckFixture : CoreTest { + private IIndexer _indexer; + + private void GivenIndexer(Boolean supportsRss, Boolean supportsSearch) + { + var _indexer = Mocker.GetMock(); + _indexer.SetupGet(s => s.SupportsRss).Returns(supportsRss); + _indexer.SetupGet(s => s.SupportsSearch).Returns(supportsSearch); + + Mocker.GetMock() + .Setup(s => s.GetAvailableProviders()) + .Returns(new List { _indexer.Object }); + + Mocker.GetMock() + .Setup(s => s.RssEnabled()) + .Returns(new List()); + + Mocker.GetMock() + .Setup(s => s.SearchEnabled()) + .Returns(new List()); + } + + private void GivenRssEnabled() + { + Mocker.GetMock() + .Setup(s => s.RssEnabled()) + .Returns(new List { _indexer }); + } + + private void GivenSearchEnabled() + { + Mocker.GetMock() + .Setup(s => s.SearchEnabled()) + .Returns(new List { _indexer }); + } + [Test] public void should_return_error_when_not_indexers_are_enabled() { @@ -26,14 +61,17 @@ namespace NzbDrone.Core.Test.HealthCheck.Checks } [Test] - public void should_return_warning_when_only_enabled_indexer_is_wombles() + public void should_return_warning_when_only_enabled_indexer_doesnt_support_search() { - var indexer = Mocker.GetMock(); - indexer.SetupGet(s => s.SupportsSearching).Returns(false); + GivenIndexer(true, false); - Mocker.GetMock() - .Setup(s => s.GetAvailableProviders()) - .Returns(new List{indexer.Object}); + Subject.Check().ShouldBeWarning(); + } + + [Test] + public void should_return_warning_when_only_enabled_indexer_doesnt_support_rss() + { + GivenIndexer(false, true); Subject.Check().ShouldBeWarning(); } @@ -41,11 +79,16 @@ namespace NzbDrone.Core.Test.HealthCheck.Checks [Test] public void should_return_ok_when_multiple_indexers_are_enabled() { + GivenRssEnabled(); + GivenSearchEnabled(); + var indexer1 = Mocker.GetMock(); - indexer1.SetupGet(s => s.SupportsSearching).Returns(true); + indexer1.SetupGet(s => s.SupportsRss).Returns(true); + indexer1.SetupGet(s => s.SupportsSearch).Returns(true); var indexer2 = Mocker.GetMock(); - indexer2.SetupGet(s => s.SupportsSearching).Returns(false); + indexer2.SetupGet(s => s.SupportsRss).Returns(true); + indexer2.SetupGet(s => s.SupportsSearch).Returns(false); Mocker.GetMock() .Setup(s => s.GetAvailableProviders()) @@ -55,16 +98,31 @@ namespace NzbDrone.Core.Test.HealthCheck.Checks } [Test] - public void should_return_ok_when_indexer_supports_searching() + public void should_return_ok_when_indexer_supports_rss_and_search() { - var indexer1 = Mocker.GetMock(); - indexer1.SetupGet(s => s.SupportsSearching).Returns(true); - - Mocker.GetMock() - .Setup(s => s.GetAvailableProviders()) - .Returns(new List { indexer1.Object }); + GivenIndexer(true, true); + GivenRssEnabled(); + GivenSearchEnabled(); Subject.Check().ShouldBeOk(); } + + [Test] + public void should_return_warning_if_rss_is_supported_but_disabled() + { + GivenIndexer(true, true); + GivenSearchEnabled(); + + Subject.Check().ShouldBeWarning(); + } + + [Test] + public void should_return_warning_if_search_is_supported_but_disabled() + { + GivenIndexer(true, true); + GivenRssEnabled(); + + Subject.Check().ShouldBeWarning(); + } } } diff --git a/src/NzbDrone.Core.Test/IndexerSearchTests/NzbSearchServiceFixture.cs b/src/NzbDrone.Core.Test/IndexerSearchTests/NzbSearchServiceFixture.cs index 9570fbfc4..7780caa21 100644 --- a/src/NzbDrone.Core.Test/IndexerSearchTests/NzbSearchServiceFixture.cs +++ b/src/NzbDrone.Core.Test/IndexerSearchTests/NzbSearchServiceFixture.cs @@ -6,7 +6,6 @@ using FizzWare.NBuilder; using System; using System.Collections.Generic; using System.Linq; -using System.Text; using FluentAssertions; using Moq; using NUnit.Framework; @@ -25,10 +24,10 @@ namespace NzbDrone.Core.Test.IndexerSearchTests public void SetUp() { var indexer = Mocker.GetMock(); - indexer.SetupGet(s => s.SupportsSearching).Returns(true); + indexer.SetupGet(s => s.SupportsSearch).Returns(true); Mocker.GetMock() - .Setup(s => s.GetAvailableProviders()) + .Setup(s => s.SearchEnabled()) .Returns(new List { indexer.Object }); Mocker.GetMock() diff --git a/src/NzbDrone.Core/Datastore/Migration/059_add_enable_options_to_indexers.cs b/src/NzbDrone.Core/Datastore/Migration/059_add_enable_options_to_indexers.cs new file mode 100644 index 000000000..0905578c5 --- /dev/null +++ b/src/NzbDrone.Core/Datastore/Migration/059_add_enable_options_to_indexers.cs @@ -0,0 +1,19 @@ +using FluentMigrator; +using NzbDrone.Core.Datastore.Migration.Framework; + +namespace NzbDrone.Core.Datastore.Migration +{ + [Migration(59)] + public class add_enable_options_to_indexers : NzbDroneMigrationBase + { + protected override void MainDbUpgrade() + { + Alter.Table("Indexers") + .AddColumn("EnableRss").AsBoolean().Nullable() + .AddColumn("EnableSearch").AsBoolean().Nullable(); + + Execute.Sql("UPDATE Indexers SET EnableRss = Enable, EnableSearch = Enable"); + Execute.Sql("UPDATE Indexers SET EnableSearch = 0 WHERE Implementation = 'Wombles'"); + } + } +} diff --git a/src/NzbDrone.Core/Datastore/Migration/060_remove_enable_from_indexers.cs b/src/NzbDrone.Core/Datastore/Migration/060_remove_enable_from_indexers.cs new file mode 100644 index 000000000..4977cf901 --- /dev/null +++ b/src/NzbDrone.Core/Datastore/Migration/060_remove_enable_from_indexers.cs @@ -0,0 +1,15 @@ +using FluentMigrator; +using NzbDrone.Core.Datastore.Migration.Framework; + +namespace NzbDrone.Core.Datastore.Migration +{ + [Migration(60)] + public class remove_enable_from_indexers : NzbDroneMigrationBase + { + protected override void MainDbUpgrade() + { + SqLiteAlter.DropColumns("Indexers", new[] { "Enable" }); + SqLiteAlter.DropColumns("DownloadClients", new[] { "Protocol" }); + } + } +} diff --git a/src/NzbDrone.Core/Datastore/TableMapping.cs b/src/NzbDrone.Core/Datastore/TableMapping.cs index 3c04658ae..128574cb7 100644 --- a/src/NzbDrone.Core/Datastore/TableMapping.cs +++ b/src/NzbDrone.Core/Datastore/TableMapping.cs @@ -40,11 +40,17 @@ namespace NzbDrone.Core.Datastore Mapper.Entity().RegisterModel("RootFolders").Ignore(r => r.FreeSpace); Mapper.Entity().RegisterModel("Indexers") - .Ignore(s => s.Protocol); + .Ignore(i => i.Enable) + .Ignore(i => i.Protocol) + .Ignore(i => i.SupportsRss) + .Ignore(i => i.SupportsSearch); + Mapper.Entity().RegisterModel("ScheduledTasks"); Mapper.Entity().RegisterModel("Notifications"); Mapper.Entity().RegisterModel("Metadata"); - Mapper.Entity().RegisterModel("DownloadClients"); + + Mapper.Entity().RegisterModel("DownloadClients") + .Ignore(d => d.Protocol); Mapper.Entity().RegisterModel("SceneMappings"); diff --git a/src/NzbDrone.Core/Download/DownloadClientFactory.cs b/src/NzbDrone.Core/Download/DownloadClientFactory.cs index d48d6d456..08fe2ffe3 100644 --- a/src/NzbDrone.Core/Download/DownloadClientFactory.cs +++ b/src/NzbDrone.Core/Download/DownloadClientFactory.cs @@ -27,7 +27,7 @@ namespace NzbDrone.Core.Download return base.Active().Where(c => c.Enable).ToList(); } - protected override DownloadClientDefinition GetProviderCharacteristics(IDownloadClient provider, DownloadClientDefinition definition) + public override DownloadClientDefinition GetProviderCharacteristics(IDownloadClient provider, DownloadClientDefinition definition) { definition = base.GetProviderCharacteristics(provider, definition); diff --git a/src/NzbDrone.Core/HealthCheck/Checks/IndexerCheck.cs b/src/NzbDrone.Core/HealthCheck/Checks/IndexerCheck.cs index 077307b99..6ae5323aa 100644 --- a/src/NzbDrone.Core/HealthCheck/Checks/IndexerCheck.cs +++ b/src/NzbDrone.Core/HealthCheck/Checks/IndexerCheck.cs @@ -1,4 +1,5 @@ using System.Linq; +using NzbDrone.Common; using NzbDrone.Core.Indexers; namespace NzbDrone.Core.HealthCheck.Checks @@ -15,17 +16,34 @@ namespace NzbDrone.Core.HealthCheck.Checks public override HealthCheck Check() { var enabled = _indexerFactory.GetAvailableProviders(); + var rssEnabled = _indexerFactory.RssEnabled(); + var searchEnabled = _indexerFactory.SearchEnabled(); - if (!enabled.Any()) + if (enabled.Empty()) { return new HealthCheck(GetType(), HealthCheckResult.Error, "No indexers are enabled"); } - if (enabled.All(i => i.SupportsSearching == false)) + if (enabled.All(i => i.SupportsRss == false)) + { + return new HealthCheck(GetType(), HealthCheckResult.Warning, "Enabled indexers do not support RSS sync"); + } + + if (enabled.All(i => i.SupportsSearch == false)) { return new HealthCheck(GetType(), HealthCheckResult.Warning, "Enabled indexers do not support searching"); } + if (rssEnabled.Empty()) + { + return new HealthCheck(GetType(), HealthCheckResult.Warning, "Enabled indexers do not have RSS sync enabled"); + } + + if (searchEnabled.Empty()) + { + return new HealthCheck(GetType(), HealthCheckResult.Warning, "Enabled indexers do not have searching enabled"); + } + return new HealthCheck(GetType()); } } diff --git a/src/NzbDrone.Core/IndexerSearch/NzbSearchService.cs b/src/NzbDrone.Core/IndexerSearch/NzbSearchService.cs index ec9665ad9..b0e8115d9 100644 --- a/src/NzbDrone.Core/IndexerSearch/NzbSearchService.cs +++ b/src/NzbDrone.Core/IndexerSearch/NzbSearchService.cs @@ -247,7 +247,7 @@ namespace NzbDrone.Core.IndexerSearch private List Dispatch(Func> searchAction, SearchCriteriaBase criteriaBase) { - var indexers = _indexerFactory.GetAvailableProviders().ToList(); + var indexers = _indexerFactory.SearchEnabled().ToList(); var reports = new List(); _logger.ProgressInfo("Searching {0} indexers for {1}", indexers.Count, criteriaBase); diff --git a/src/NzbDrone.Core/Indexers/Animezb/Animezb.cs b/src/NzbDrone.Core/Indexers/Animezb/Animezb.cs index b465c6df3..aa5030cb3 100644 --- a/src/NzbDrone.Core/Indexers/Animezb/Animezb.cs +++ b/src/NzbDrone.Core/Indexers/Animezb/Animezb.cs @@ -21,7 +21,7 @@ namespace NzbDrone.Core.Indexers.Animezb } } - public override bool SupportsSearching + public override bool SupportsSearch { get { diff --git a/src/NzbDrone.Core/Indexers/Fanzub/Fanzub.cs b/src/NzbDrone.Core/Indexers/Fanzub/Fanzub.cs index 848811f29..a440db4cf 100644 --- a/src/NzbDrone.Core/Indexers/Fanzub/Fanzub.cs +++ b/src/NzbDrone.Core/Indexers/Fanzub/Fanzub.cs @@ -19,7 +19,7 @@ namespace NzbDrone.Core.Indexers.Fanzub } } - public override bool SupportsSearching + public override bool SupportsSearch { get { diff --git a/src/NzbDrone.Core/Indexers/FetchAndParseRssService.cs b/src/NzbDrone.Core/Indexers/FetchAndParseRssService.cs index 899714e67..69e498783 100644 --- a/src/NzbDrone.Core/Indexers/FetchAndParseRssService.cs +++ b/src/NzbDrone.Core/Indexers/FetchAndParseRssService.cs @@ -29,7 +29,7 @@ namespace NzbDrone.Core.Indexers { var result = new List(); - var indexers = _indexerFactory.GetAvailableProviders().ToList(); + var indexers = _indexerFactory.RssEnabled().ToList(); if (!indexers.Any()) { diff --git a/src/NzbDrone.Core/Indexers/IIndexer.cs b/src/NzbDrone.Core/Indexers/IIndexer.cs index d183ef7a3..da67c45d1 100644 --- a/src/NzbDrone.Core/Indexers/IIndexer.cs +++ b/src/NzbDrone.Core/Indexers/IIndexer.cs @@ -10,7 +10,8 @@ namespace NzbDrone.Core.Indexers DownloadProtocol Protocol { get; } Int32 SupportedPageSize { get; } Boolean SupportsPaging { get; } - Boolean SupportsSearching { get; } + Boolean SupportsRss { get; } + Boolean SupportsSearch { get; } IEnumerable RecentFeed { get; } IEnumerable GetEpisodeSearchUrls(List titles, int tvRageId, int seasonNumber, int episodeNumber); diff --git a/src/NzbDrone.Core/Indexers/IndexerBase.cs b/src/NzbDrone.Core/Indexers/IndexerBase.cs index 21754cd44..2dfc0d7d1 100644 --- a/src/NzbDrone.Core/Indexers/IndexerBase.cs +++ b/src/NzbDrone.Core/Indexers/IndexerBase.cs @@ -24,7 +24,8 @@ namespace NzbDrone.Core.Indexers yield return new IndexerDefinition { Name = GetType().Name, - Enable = config.Validate().IsValid, + EnableRss = config.Validate().IsValid, + EnableSearch = config.Validate().IsValid && SupportsSearch, Implementation = GetType().Name, Settings = config }; @@ -36,10 +37,10 @@ namespace NzbDrone.Core.Indexers public abstract ValidationResult Test(); public abstract DownloadProtocol Protocol { get; } - public virtual Boolean SupportsFeed { get { return true; } } + public virtual Boolean SupportsRss { get { return true; } } + public virtual Boolean SupportsSearch { get { return true; } } public virtual Int32 SupportedPageSize { get { return 0; } } public bool SupportsPaging { get { return SupportedPageSize > 0; } } - public virtual Boolean SupportsSearching { get { return true; } } protected TSettings Settings { diff --git a/src/NzbDrone.Core/Indexers/IndexerDefinition.cs b/src/NzbDrone.Core/Indexers/IndexerDefinition.cs index 03d82ae49..026939dab 100644 --- a/src/NzbDrone.Core/Indexers/IndexerDefinition.cs +++ b/src/NzbDrone.Core/Indexers/IndexerDefinition.cs @@ -1,9 +1,22 @@ -using NzbDrone.Core.ThingiProvider; +using System; +using NzbDrone.Core.ThingiProvider; namespace NzbDrone.Core.Indexers { public class IndexerDefinition : ProviderDefinition { + public Boolean EnableRss { get; set; } + public Boolean EnableSearch { get; set; } public DownloadProtocol Protocol { get; set; } + public Boolean SupportsRss { get; set; } + public Boolean SupportsSearch { get; set; } + + public override Boolean Enable + { + get + { + return EnableRss || EnableSearch; + } + } } } diff --git a/src/NzbDrone.Core/Indexers/IndexerFactory.cs b/src/NzbDrone.Core/Indexers/IndexerFactory.cs index 45bb0b705..eab2e8cb8 100644 --- a/src/NzbDrone.Core/Indexers/IndexerFactory.cs +++ b/src/NzbDrone.Core/Indexers/IndexerFactory.cs @@ -9,22 +9,19 @@ namespace NzbDrone.Core.Indexers { public interface IIndexerFactory : IProviderFactory { - + List RssEnabled(); + List SearchEnabled(); } public class IndexerFactory : ProviderFactory, IIndexerFactory { - private readonly INewznabTestService _newznabTestService; - public IndexerFactory(IIndexerRepository providerRepository, IEnumerable providers, IContainer container, - IEventAggregator eventAggregator, - INewznabTestService newznabTestService, + IEventAggregator eventAggregator, Logger logger) : base(providerRepository, providers, container, eventAggregator, logger) { - _newznabTestService = newznabTestService; } protected override void InitializeProviders() @@ -37,13 +34,25 @@ namespace NzbDrone.Core.Indexers return base.Active().Where(c => c.Enable).ToList(); } - protected override IndexerDefinition GetProviderCharacteristics(IIndexer provider, IndexerDefinition definition) + public override IndexerDefinition GetProviderCharacteristics(IIndexer provider, IndexerDefinition definition) { definition = base.GetProviderCharacteristics(provider, definition); definition.Protocol = provider.Protocol; + definition.SupportsRss = provider.SupportsRss; + definition.SupportsSearch = provider.SupportsSearch; return definition; } + + public List RssEnabled() + { + return GetAvailableProviders().Where(n => ((IndexerDefinition)n.Definition).EnableRss).ToList(); + } + + public List SearchEnabled() + { + return GetAvailableProviders().Where(n => ((IndexerDefinition)n.Definition).EnableSearch).ToList(); + } } } \ No newline at end of file diff --git a/src/NzbDrone.Core/Indexers/Newznab/Newznab.cs b/src/NzbDrone.Core/Indexers/Newznab/Newznab.cs index f46858a45..f2797d695 100644 --- a/src/NzbDrone.Core/Indexers/Newznab/Newznab.cs +++ b/src/NzbDrone.Core/Indexers/Newznab/Newznab.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Linq; -using FluentValidation; using FluentValidation.Results; using NLog; using NzbDrone.Common; @@ -47,54 +46,12 @@ namespace NzbDrone.Core.Indexers.Newznab { var list = new List(); - list.Add(new IndexerDefinition - { - Enable = false, - Name = "Nzbs.org", - Implementation = GetType().Name, - Settings = GetSettings("http://nzbs.org", new List { 5000 }) - }); - - - list.Add(new IndexerDefinition - { - Enable = false, - Name = "Nzb.su", - Implementation = GetType().Name, - Settings = GetSettings("https://api.nzb.su", new List()) - }); - - list.Add(new IndexerDefinition - { - Enable = false, - Name = "Dognzb.cr", - Implementation = GetType().Name, - Settings = GetSettings("https://api.dognzb.cr", new List()) - }); - - list.Add(new IndexerDefinition - { - Enable = false, - Name = "OZnzb.com", - Implementation = GetType().Name, - Settings = GetSettings("https://www.oznzb.com", new List()) - }); - - list.Add(new IndexerDefinition - { - Enable = false, - Name = "nzbplanet.net", - Implementation = GetType().Name, - Settings = GetSettings("https://nzbplanet.net", new List()) - }); - - list.Add(new IndexerDefinition - { - Enable = false, - Name = "NZBgeek", - Implementation = GetType().Name, - Settings = GetSettings("https://api.nzbgeek.info", new List()) - }); + list.Add(GetDefinition("Nzbs.org", GetSettings("http://nzbs.org", 5000))); + list.Add(GetDefinition("Nzb.su", GetSettings("https://api.nzb.su"))); + list.Add(GetDefinition("Dognzb.cr", GetSettings("https://api.dognzb.cr"))); + list.Add(GetDefinition("OZnzb.com", GetSettings("https://www.oznzb.com"))); + list.Add(GetDefinition("nzbplanet.net", GetSettings("https://nzbplanet.net"))); + list.Add(GetDefinition("NZBgeek", GetSettings("https://api.nzbgeek.info"))); return list; } @@ -102,18 +59,6 @@ namespace NzbDrone.Core.Indexers.Newznab public override ProviderDefinition Definition { get; set; } - private NewznabSettings GetSettings(string url, List categories) - { - var settings = new NewznabSettings { Url = url }; - - if (categories.Any()) - { - settings.Categories = categories; - } - - return settings; - } - public override IEnumerable RecentFeed { get @@ -241,6 +186,33 @@ namespace NzbDrone.Core.Indexers.Newznab return new ValidationResult(); } + private IndexerDefinition GetDefinition(String name, NewznabSettings settings) + { + return new IndexerDefinition + { + EnableRss = false, + EnableSearch = false, + Name = name, + Implementation = GetType().Name, + Settings = settings, + Protocol = DownloadProtocol.Usenet, + SupportsRss = SupportsRss, + SupportsSearch = SupportsSearch + }; + } + + private NewznabSettings GetSettings(String url, params int[] categories) + { + var settings = new NewznabSettings { Url = url }; + + if (categories.Any()) + { + settings.Categories = categories; + } + + return settings; + } + private static string NewsnabifyTitle(string title) { return title.Replace("+", "%20"); diff --git a/src/NzbDrone.Core/Indexers/Wombles/Wombles.cs b/src/NzbDrone.Core/Indexers/Wombles/Wombles.cs index ebb9dac40..ebf1d123b 100644 --- a/src/NzbDrone.Core/Indexers/Wombles/Wombles.cs +++ b/src/NzbDrone.Core/Indexers/Wombles/Wombles.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Linq; using FluentValidation.Results; using NzbDrone.Core.ThingiProvider; @@ -9,7 +8,7 @@ namespace NzbDrone.Core.Indexers.Wombles public class Wombles : IndexerBase { public override DownloadProtocol Protocol { get { return DownloadProtocol.Usenet; } } - public override bool SupportsSearching { get { return false; } } + public override bool SupportsSearch { get { return false; } } public override IParseFeed Parser { diff --git a/src/NzbDrone.Core/NzbDrone.Core.csproj b/src/NzbDrone.Core/NzbDrone.Core.csproj index cf2ec257e..990e8d655 100644 --- a/src/NzbDrone.Core/NzbDrone.Core.csproj +++ b/src/NzbDrone.Core/NzbDrone.Core.csproj @@ -221,6 +221,8 @@ + + diff --git a/src/NzbDrone.Core/ThingiProvider/IProviderFactory.cs b/src/NzbDrone.Core/ThingiProvider/IProviderFactory.cs index eb960f26a..459d25074 100644 --- a/src/NzbDrone.Core/ThingiProvider/IProviderFactory.cs +++ b/src/NzbDrone.Core/ThingiProvider/IProviderFactory.cs @@ -15,6 +15,8 @@ namespace NzbDrone.Core.ThingiProvider void Delete(int id); IEnumerable GetDefaultDefinitions(); IEnumerable GetPresetDefinitions(TProviderDefinition providerDefinition); + TProviderDefinition GetProviderCharacteristics(TProvider provider, TProviderDefinition definition); + TProvider GetInstance(TProviderDefinition definition); ValidationResult Test(TProviderDefinition definition); } } \ No newline at end of file diff --git a/src/NzbDrone.Core/ThingiProvider/ProviderFactory.cs b/src/NzbDrone.Core/ThingiProvider/ProviderFactory.cs index a8dda0bec..7ba72778f 100644 --- a/src/NzbDrone.Core/ThingiProvider/ProviderFactory.cs +++ b/src/NzbDrone.Core/ThingiProvider/ProviderFactory.cs @@ -107,7 +107,7 @@ namespace NzbDrone.Core.ThingiProvider _providerRepository.Delete(id); } - protected TProvider GetInstance(TProviderDefinition definition) + public TProvider GetInstance(TProviderDefinition definition) { var type = GetImplementation(definition); var instance = (TProvider)_container.Resolve(type); @@ -138,7 +138,7 @@ namespace NzbDrone.Core.ThingiProvider return All().Where(c => c.Settings.Validate().IsValid).ToList(); } - protected virtual TProviderDefinition GetProviderCharacteristics(TProvider provider, TProviderDefinition definition) + public virtual TProviderDefinition GetProviderCharacteristics(TProvider provider, TProviderDefinition definition) { return definition; } diff --git a/src/NzbDrone.Integration.Test/IndexerIntegrationFixture.cs b/src/NzbDrone.Integration.Test/IndexerIntegrationFixture.cs index 96003762b..13ac0d897 100644 --- a/src/NzbDrone.Integration.Test/IndexerIntegrationFixture.cs +++ b/src/NzbDrone.Integration.Test/IndexerIntegrationFixture.cs @@ -15,7 +15,7 @@ namespace NzbDrone.Integration.Test indexers.Should().NotBeEmpty(); indexers.Should().NotContain(c => string.IsNullOrWhiteSpace(c.Name)); - indexers.Where(c => c.ConfigContract == typeof(NullConfig).Name).Should().OnlyContain(c => c.Enable); + indexers.Where(c => c.ConfigContract == typeof(NullConfig).Name).Should().OnlyContain(c => c.EnableRss); } } } \ No newline at end of file diff --git a/src/NzbDrone.Integration.Test/IntegrationTest.cs b/src/NzbDrone.Integration.Test/IntegrationTest.cs index c51816d43..3fc5ec27c 100644 --- a/src/NzbDrone.Integration.Test/IntegrationTest.cs +++ b/src/NzbDrone.Integration.Test/IntegrationTest.cs @@ -72,7 +72,7 @@ namespace NzbDrone.Integration.Test // Add Wombles var wombles = Indexers.Post(new Api.Indexers.IndexerResource { - Enable = true, + EnableRss = true, ConfigContract = "NullConfig", Implementation = "Wombles", Name = "Wombles", diff --git a/src/UI/Settings/Indexers/Add/IndexerAddItemView.js b/src/UI/Settings/Indexers/Add/IndexerAddItemView.js index c28f40bfb..576845440 100644 --- a/src/UI/Settings/Indexers/Add/IndexerAddItemView.js +++ b/src/UI/Settings/Indexers/Add/IndexerAddItemView.js @@ -25,18 +25,11 @@ define([ _addPreset: function (e) { var presetName = $(e.target).closest('.x-preset').attr('data-id'); - var presetData = _.where(this.model.get('presets'), {name: presetName})[0]; this.model.set(presetData); - - this.model.set({ - id : undefined, - enable : true - }); - var editView = new EditView({ model: this.model, targetCollection: this.targetCollection }); - AppLayout.modalRegion.show(editView); + this._openEdit(); }, _add: function (e) { @@ -44,9 +37,14 @@ define([ return; } + this._openEdit(); + }, + + _openEdit: function () { this.model.set({ - id : undefined, - enable : true + id : undefined, + enableRss : this.model.get('supportsRss'), + enableSearch : this.model.get('supportsSearch') }); var editView = new EditView({ model: this.model, targetCollection: this.targetCollection }); diff --git a/src/UI/Settings/Indexers/Edit/IndexerEditViewTemplate.html b/src/UI/Settings/Indexers/Edit/IndexerEditViewTemplate.html index d9f1682f3..dd31e0994 100644 --- a/src/UI/Settings/Indexers/Edit/IndexerEditViewTemplate.html +++ b/src/UI/Settings/Indexers/Edit/IndexerEditViewTemplate.html @@ -17,13 +17,14 @@ + {{#if supportsRss}}
- +
+ {{/if}} + + {{#if supportsSearch}} +
+ + +
+
+
+
+ {{/if}} {{formBuilder}}
diff --git a/src/UI/Settings/Indexers/IndexerItemViewTemplate.html b/src/UI/Settings/Indexers/IndexerItemViewTemplate.html index d1b3cf807..2f0632ade 100644 --- a/src/UI/Settings/Indexers/IndexerItemViewTemplate.html +++ b/src/UI/Settings/Indexers/IndexerItemViewTemplate.html @@ -4,10 +4,20 @@
- {{#if enable}} - Enabled - {{else}} - Not Enabled + {{#if supportsRss}} + {{#if enableRss}} + RSS + {{else}} + RSS + {{/if}} + {{/if}} + + {{#if supportsSearch}} + {{#if enableSearch}} + Search + {{else}} + Search + {{/if}} {{/if}}