|
|
|
@ -1,6 +1,10 @@
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
|
using FluentValidation;
|
|
|
|
|
using FluentValidation.Validators;
|
|
|
|
|
using NzbDrone.Common.Extensions;
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Organizer
|
|
|
|
|
{
|
|
|
|
@ -12,18 +16,23 @@ namespace NzbDrone.Core.Organizer
|
|
|
|
|
public static IRuleBuilderOptions<T, string> ValidTrackFormat<T>(this IRuleBuilder<T, string> ruleBuilder)
|
|
|
|
|
{
|
|
|
|
|
ruleBuilder.SetValidator(new NotEmptyValidator(null));
|
|
|
|
|
ruleBuilder.SetValidator(new IllegalCharactersValidator());
|
|
|
|
|
|
|
|
|
|
return ruleBuilder.SetValidator(new ValidStandardTrackFormatValidator());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static IRuleBuilderOptions<T, string> ValidArtistFolderFormat<T>(this IRuleBuilder<T, string> ruleBuilder)
|
|
|
|
|
{
|
|
|
|
|
ruleBuilder.SetValidator(new NotEmptyValidator(null));
|
|
|
|
|
ruleBuilder.SetValidator(new IllegalCharactersValidator());
|
|
|
|
|
|
|
|
|
|
return ruleBuilder.SetValidator(new RegularExpressionValidator(FileNameBuilder.ArtistNameRegex)).WithMessage("Must contain Artist name");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static IRuleBuilderOptions<T, string> ValidAlbumFolderFormat<T>(this IRuleBuilder<T, string> ruleBuilder)
|
|
|
|
|
{
|
|
|
|
|
ruleBuilder.SetValidator(new NotEmptyValidator(null));
|
|
|
|
|
ruleBuilder.SetValidator(new IllegalCharactersValidator());
|
|
|
|
|
return ruleBuilder.SetValidator(new RegularExpressionValidator(FileNameBuilder.AlbumTitleRegex)).WithMessage("Must contain Album title");
|
|
|
|
|
|
|
|
|
|
//.SetValidator(new RegularExpressionValidator(FileNameBuilder.ReleaseDateRegex)).WithMessage("Must contain Release year");
|
|
|
|
@ -51,4 +60,42 @@ namespace NzbDrone.Core.Organizer
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class IllegalCharactersValidator : PropertyValidator
|
|
|
|
|
{
|
|
|
|
|
private readonly char[] _invalidPathChars = Path.GetInvalidPathChars();
|
|
|
|
|
|
|
|
|
|
public IllegalCharactersValidator()
|
|
|
|
|
: base("Contains illegal characters: {InvalidCharacters}")
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool IsValid(PropertyValidatorContext context)
|
|
|
|
|
{
|
|
|
|
|
var value = context.PropertyValue as string;
|
|
|
|
|
var invalidCharacters = new List<char>();
|
|
|
|
|
|
|
|
|
|
if (value.IsNullOrWhiteSpace())
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (var i in _invalidPathChars)
|
|
|
|
|
{
|
|
|
|
|
if (value.IndexOf(i) >= 0)
|
|
|
|
|
{
|
|
|
|
|
invalidCharacters.Add(i);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (invalidCharacters.Any())
|
|
|
|
|
{
|
|
|
|
|
context.MessageFormatter.AppendArgument("InvalidCharacters", string.Join("", invalidCharacters));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|