New: VIP Expiration notifications on Newznab

pull/25/head
Qstick 3 years ago
parent 6d9b028814
commit fa7647135b

@ -1,4 +1,4 @@
using System;
using System;
namespace NzbDrone.Common.Extensions
{
@ -34,6 +34,20 @@ namespace NzbDrone.Common.Extensions
return dateTime >= afterDateTime;
}
public static bool IsValidDate(this string dateTime)
{
DateTime.TryParse(dateTime, out DateTime result);
return !result.Equals(default(DateTime));
}
public static bool IsFutureDate(this string dateTime)
{
DateTime.TryParse(dateTime, out DateTime result);
return !result.Equals(default(DateTime)) && result.After(DateTime.Now);
}
public static bool Between(this DateTime dateTime, DateTime afterDateTime, DateTime beforeDateTime)
{
return dateTime >= afterDateTime && dateTime <= beforeDateTime;

@ -0,0 +1,73 @@
using System;
using System.Collections.Generic;
using System.Linq;
using NzbDrone.Common.Extensions;
using NzbDrone.Core.Indexers;
using NzbDrone.Core.Indexers.Newznab;
using NzbDrone.Core.Localization;
using NzbDrone.Core.ThingiProvider.Events;
namespace NzbDrone.Core.HealthCheck.Checks
{
[CheckOn(typeof(ProviderAddedEvent<IIndexer>))]
[CheckOn(typeof(ProviderUpdatedEvent<IIndexer>))]
[CheckOn(typeof(ProviderDeletedEvent<IIndexer>))]
public class NewznabVIPCheck : HealthCheckBase
{
private readonly IIndexerFactory _indexerFactory;
public NewznabVIPCheck(IIndexerFactory indexerFactory, ILocalizationService localizationService)
: base(localizationService)
{
_indexerFactory = indexerFactory;
}
public override HealthCheck Check()
{
var enabled = _indexerFactory.Enabled(false);
var newznabProviders = enabled.Where(i => i.Definition.Implementation == typeof(Newznab).Name);
var expiringProviders = new List<IIndexer>();
var expiredProviders = new List<IIndexer>();
foreach (var provider in newznabProviders)
{
var expiration = ((NewznabSettings)provider.Definition.Settings).VipExpiration;
if (expiration.IsNullOrWhiteSpace())
{
continue;
}
if (DateTime.Parse(expiration).Before(DateTime.Now))
{
expiredProviders.Add(provider);
}
if (DateTime.Parse(expiration).Between(DateTime.Now, DateTime.Now.AddDays(7)))
{
expiringProviders.Add(provider);
}
}
if (!expiringProviders.Empty())
{
return new HealthCheck(GetType(),
HealthCheckResult.Warning,
string.Format(_localizationService.GetLocalizedString("NewznabVipCheckExpiringClientMessage"),
string.Join(", ", expiringProviders.Select(v => v.Definition.Name))),
"#newznab-vip-expiring");
}
if (!expiredProviders.Empty())
{
return new HealthCheck(GetType(),
HealthCheckResult.Warning,
string.Format(_localizationService.GetLocalizedString("NewznabVipCheckExpiredClientMessage"),
string.Join(", ", expiredProviders.Select(v => v.Definition.Name))),
"#newznab-vip-expired");
}
return new HealthCheck(GetType());
}
}
}

@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
@ -41,6 +42,14 @@ namespace NzbDrone.Core.Indexers.Newznab
RuleFor(c => c.ApiKey).NotEmpty().When(ShouldHaveApiKey);
RuleFor(c => c.AdditionalParameters).Matches(AdditionalParametersRegex)
.When(c => !c.AdditionalParameters.IsNullOrWhiteSpace());
RuleFor(c => c.VipExpiration).Must(c => c.IsValidDate())
.When(c => c.VipExpiration.IsNotNullOrWhiteSpace())
.WithMessage("Correctly formatted date is required");
RuleFor(c => c.VipExpiration).Must(c => c.IsFutureDate())
.When(c => c.VipExpiration.IsNotNullOrWhiteSpace())
.WithMessage("Must be a future date");
}
}
@ -51,6 +60,7 @@ namespace NzbDrone.Core.Indexers.Newznab
public NewznabSettings()
{
ApiPath = "/api";
VipExpiration = "";
}
[FieldDefinition(0, Label = "URL")]
@ -65,6 +75,9 @@ namespace NzbDrone.Core.Indexers.Newznab
[FieldDefinition(5, Label = "Additional Parameters", HelpText = "Additional Newznab parameters", Advanced = true)]
public string AdditionalParameters { get; set; }
[FieldDefinition(6, Label = "VIP Expiration", HelpText = "Enter date (yyyy-mm-dd) for VIP Expiration or blank, Prowlarr will notify 1 week from expiration of VIP")]
public string VipExpiration { get; set; }
public List<IndexerCategory> Categories { get; set; }
// Field 8 is used by TorznabSettings MinimumSeeders

@ -97,6 +97,8 @@
"EnableSSL": "Enable SSL",
"EnableSslHelpText": " Requires restart running as administrator to take effect",
"Error": "Error",
"NewznabVipCheckExpiringClientMessage": "Indexer VIP benefits expiring soon: {0}",
"NewznabVipCheckExpiredClientMessage": "Indexer VIP benefits have expired: {0}",
"ErrorLoadingContents": "Error loading contents",
"Events": "Events",
"EventType": "Event Type",

Loading…
Cancel
Save