From 4036654f3f4394ee424f17d1398e2c2f1113604e Mon Sep 17 00:00:00 2001 From: Taloth Saldono Date: Tue, 3 Mar 2015 01:10:37 +0100 Subject: [PATCH] New: Fanzub url can now be modified (to be used only with alternative sites implementing the same api) --- .../Migration/082_add_fanzub_settings.cs | 20 +++++++++++ src/NzbDrone.Core/Indexers/Fanzub/Fanzub.cs | 4 +-- .../Indexers/Fanzub/FanzubRequestGenerator.cs | 5 ++- .../Indexers/Fanzub/FanzubSettings.cs | 35 +++++++++++++++++++ src/NzbDrone.Core/NzbDrone.Core.csproj | 2 ++ 5 files changed, 61 insertions(+), 5 deletions(-) create mode 100644 src/NzbDrone.Core/Datastore/Migration/082_add_fanzub_settings.cs create mode 100644 src/NzbDrone.Core/Indexers/Fanzub/FanzubSettings.cs diff --git a/src/NzbDrone.Core/Datastore/Migration/082_add_fanzub_settings.cs b/src/NzbDrone.Core/Datastore/Migration/082_add_fanzub_settings.cs new file mode 100644 index 000000000..df83b386e --- /dev/null +++ b/src/NzbDrone.Core/Datastore/Migration/082_add_fanzub_settings.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Data; +using System.Linq; +using FluentMigrator; +using NzbDrone.Common.Extensions; +using NzbDrone.Common.Serializer; +using NzbDrone.Core.Datastore.Migration.Framework; + +namespace NzbDrone.Core.Datastore.Migration +{ + [Migration(82)] + public class add_fanzub_settings : NzbDroneMigrationBase + { + protected override void MainDbUpgrade() + { + Execute.Sql("UPDATE Indexers SET ConfigContract = 'FanzubSettings' WHERE Implementation = 'Fanzub' AND ConfigContract = 'NullConfig'"); + } + } +} diff --git a/src/NzbDrone.Core/Indexers/Fanzub/Fanzub.cs b/src/NzbDrone.Core/Indexers/Fanzub/Fanzub.cs index 62adc4a0b..8c98d4f3f 100644 --- a/src/NzbDrone.Core/Indexers/Fanzub/Fanzub.cs +++ b/src/NzbDrone.Core/Indexers/Fanzub/Fanzub.cs @@ -6,7 +6,7 @@ using NzbDrone.Core.ThingiProvider; namespace NzbDrone.Core.Indexers.Fanzub { - public class Fanzub : HttpIndexerBase + public class Fanzub : HttpIndexerBase { public override DownloadProtocol Protocol { get { return DownloadProtocol.Usenet; } } @@ -18,7 +18,7 @@ namespace NzbDrone.Core.Indexers.Fanzub public override IIndexerRequestGenerator GetRequestGenerator() { - return new FanzubRequestGenerator(); + return new FanzubRequestGenerator() { Settings = Settings }; } public override IParseIndexerResponse GetParser() diff --git a/src/NzbDrone.Core/Indexers/Fanzub/FanzubRequestGenerator.cs b/src/NzbDrone.Core/Indexers/Fanzub/FanzubRequestGenerator.cs index 5490baa20..a04364004 100644 --- a/src/NzbDrone.Core/Indexers/Fanzub/FanzubRequestGenerator.cs +++ b/src/NzbDrone.Core/Indexers/Fanzub/FanzubRequestGenerator.cs @@ -13,12 +13,11 @@ namespace NzbDrone.Core.Indexers.Fanzub { private static readonly Regex RemoveCharactersRegex = new Regex(@"[!?`]", RegexOptions.Compiled); - public String BaseUrl { get; set; } + public FanzubSettings Settings { get; set; } public Int32 PageSize { get; set; } public FanzubRequestGenerator() { - BaseUrl = "http://fanzub.com/rss/?cat=anime"; PageSize = 100; } @@ -65,7 +64,7 @@ namespace NzbDrone.Core.Indexers.Fanzub private IEnumerable GetPagedRequests(String query) { var url = new StringBuilder(); - url.AppendFormat("{0}&max={1}", BaseUrl, PageSize); + url.AppendFormat("{0}?cat=anime&max={1}", Settings.BaseUrl, PageSize); if (query.IsNotNullOrWhiteSpace()) { diff --git a/src/NzbDrone.Core/Indexers/Fanzub/FanzubSettings.cs b/src/NzbDrone.Core/Indexers/Fanzub/FanzubSettings.cs new file mode 100644 index 000000000..40b58291a --- /dev/null +++ b/src/NzbDrone.Core/Indexers/Fanzub/FanzubSettings.cs @@ -0,0 +1,35 @@ +using System; +using FluentValidation; +using FluentValidation.Results; +using NzbDrone.Core.Annotations; +using NzbDrone.Core.ThingiProvider; +using NzbDrone.Core.Validation; + +namespace NzbDrone.Core.Indexers.Fanzub +{ + public class FanzubSettingsValidator : AbstractValidator + { + public FanzubSettingsValidator() + { + RuleFor(c => c.BaseUrl).ValidRootUrl(); + } + } + + public class FanzubSettings : IProviderConfig + { + private static readonly FanzubSettingsValidator validator = new FanzubSettingsValidator(); + + public FanzubSettings() + { + BaseUrl = "http://fanzub.com/rss/"; + } + + [FieldDefinition(0, Label = "Rss URL", HelpText = "Enter to URL to an Fanzub compatible RSS feed")] + public String BaseUrl { get; set; } + + public ValidationResult Validate() + { + return validator.Validate(this); + } + } +} diff --git a/src/NzbDrone.Core/NzbDrone.Core.csproj b/src/NzbDrone.Core/NzbDrone.Core.csproj index 017edcc36..a1d4633bd 100644 --- a/src/NzbDrone.Core/NzbDrone.Core.csproj +++ b/src/NzbDrone.Core/NzbDrone.Core.csproj @@ -248,6 +248,7 @@ + @@ -455,6 +456,7 @@ +