2023-06-29 15:06:04 +00:00
|
|
|
using System;
|
2018-11-23 07:03:32 +00:00
|
|
|
using System.Collections.Generic;
|
2018-02-01 13:18:52 +00:00
|
|
|
using System.Linq;
|
2015-03-12 20:01:54 +00:00
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
using FluentValidation;
|
|
|
|
using NzbDrone.Common.Extensions;
|
2017-06-12 12:47:05 +00:00
|
|
|
using NzbDrone.Core.Annotations;
|
2015-09-26 08:45:13 +00:00
|
|
|
using NzbDrone.Core.Indexers.Newznab;
|
2020-01-07 04:31:33 +00:00
|
|
|
using NzbDrone.Core.Parser.Model;
|
2015-03-12 20:01:54 +00:00
|
|
|
using NzbDrone.Core.Validation;
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Indexers.Torznab
|
|
|
|
{
|
|
|
|
public class TorznabSettingsValidator : AbstractValidator<TorznabSettings>
|
|
|
|
{
|
2023-06-29 15:06:04 +00:00
|
|
|
private static readonly string[] ApiKeyWhiteList = Array.Empty<string>();
|
2015-03-12 20:01:54 +00:00
|
|
|
|
|
|
|
private static bool ShouldHaveApiKey(TorznabSettings settings)
|
|
|
|
{
|
2023-05-26 15:32:35 +00:00
|
|
|
return settings.BaseUrl != null && ApiKeyWhiteList.Any(c => settings.BaseUrl.ToLowerInvariant().Contains(c));
|
2015-03-12 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
2023-06-29 15:06:04 +00:00
|
|
|
private static readonly Regex AdditionalParametersRegex = new (@"(&.+?\=.+?)+", RegexOptions.Compiled);
|
2015-03-12 20:01:54 +00:00
|
|
|
|
|
|
|
public TorznabSettingsValidator()
|
|
|
|
{
|
2019-09-02 20:27:49 +00:00
|
|
|
RuleFor(c => c).Custom((c, context) =>
|
2015-09-26 08:45:13 +00:00
|
|
|
{
|
2020-06-20 19:55:31 +00:00
|
|
|
if (c.Categories.Empty())
|
2015-09-26 08:45:13 +00:00
|
|
|
{
|
2020-06-20 19:55:31 +00:00
|
|
|
context.AddFailure("'Categories' must be provided");
|
2015-09-26 08:45:13 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-06-12 12:47:05 +00:00
|
|
|
RuleFor(c => c.BaseUrl).ValidRootUrl();
|
2019-06-14 03:54:25 +00:00
|
|
|
RuleFor(c => c.ApiPath).ValidUrlBase("/api");
|
2015-03-12 20:01:54 +00:00
|
|
|
RuleFor(c => c.ApiKey).NotEmpty().When(ShouldHaveApiKey);
|
2015-09-26 08:45:13 +00:00
|
|
|
RuleFor(c => c.AdditionalParameters).Matches(AdditionalParametersRegex)
|
|
|
|
.When(c => !c.AdditionalParameters.IsNullOrWhiteSpace());
|
2019-06-14 03:54:25 +00:00
|
|
|
|
|
|
|
RuleFor(c => c.SeedCriteria).SetValidator(_ => new SeedCriteriaSettingsValidator());
|
2015-03-12 20:01:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-12 12:47:05 +00:00
|
|
|
public class TorznabSettings : NewznabSettings, ITorrentIndexerSettings
|
2015-03-12 20:01:54 +00:00
|
|
|
{
|
2023-06-29 15:06:04 +00:00
|
|
|
private static readonly TorznabSettingsValidator Validator = new ();
|
2015-03-12 20:01:54 +00:00
|
|
|
|
2017-06-12 12:47:05 +00:00
|
|
|
public TorznabSettings()
|
|
|
|
{
|
|
|
|
MinimumSeeders = IndexerDefaults.MINIMUM_SEEDERS;
|
2023-06-29 15:06:04 +00:00
|
|
|
RequiredFlags = Array.Empty<int>();
|
2017-06-12 12:47:05 +00:00
|
|
|
}
|
|
|
|
|
2018-11-23 07:03:32 +00:00
|
|
|
[FieldDefinition(8, Type = FieldType.Number, Label = "Minimum Seeders", HelpText = "Minimum number of seeders required.", Advanced = true)]
|
2017-06-12 12:47:05 +00:00
|
|
|
public int MinimumSeeders { get; set; }
|
2019-12-22 21:24:11 +00:00
|
|
|
|
2019-06-14 03:54:25 +00:00
|
|
|
[FieldDefinition(9)]
|
2023-06-29 15:06:04 +00:00
|
|
|
public SeedCriteriaSettings SeedCriteria { get; set; } = new ();
|
2018-05-27 09:05:23 +00:00
|
|
|
|
2024-04-16 03:24:05 +00:00
|
|
|
[FieldDefinition(10, Type = FieldType.Checkbox, Label = "IndexerSettingsRejectBlocklistedTorrentHashes", HelpText = "IndexerSettingsRejectBlocklistedTorrentHashesHelpText", Advanced = true)]
|
2023-10-29 18:23:23 +00:00
|
|
|
public bool RejectBlocklistedTorrentHashesWhileGrabbing { get; set; }
|
|
|
|
|
2024-04-16 03:24:05 +00:00
|
|
|
[FieldDefinition(11, Type = FieldType.Select, SelectOptions = typeof(IndexerFlags), Label = "Required Flags", HelpText = "What indexer flags are required?", HelpLink = "https://wiki.servarr.com/radarr/settings#indexer-flags", Advanced = true)]
|
|
|
|
public IEnumerable<int> RequiredFlags { get; set; }
|
|
|
|
|
2016-02-11 20:49:22 +00:00
|
|
|
public override NzbDroneValidationResult Validate()
|
2015-03-12 20:01:54 +00:00
|
|
|
{
|
2015-03-17 04:33:34 +00:00
|
|
|
return new NzbDroneValidationResult(Validator.Validate(this));
|
2015-03-12 20:01:54 +00:00
|
|
|
}
|
|
|
|
}
|
2018-05-27 09:05:23 +00:00
|
|
|
}
|