Fixed: Validation for Track File Naming, Add Album Type Token

#241
pull/6/head
Qstick 7 years ago
parent c7ef370060
commit 8ad38fe3af

@ -123,7 +123,9 @@ class NamingModal extends Component {
{ token: '{Album CleanTitle}', example: 'Album Title' },
{ token: '{Album.CleanTitle}', example: 'Album.Title' },
{ token: '{Album_CleanTitle}', example: 'Album_Title' }
{ token: '{Album_CleanTitle}', example: 'Album_Title' },
{ token: '{Album Type}', example: 'Album Type' }
];
const mediumTokens = [

@ -36,7 +36,7 @@ namespace NzbDrone.Core.Organizer
private static readonly Regex TitleRegex = new Regex(@"\{(?<prefix>[- ._\[(]*)(?<token>(?:[a-z0-9]+)(?:(?<separator>[- ._]+)(?:[a-z0-9]+))?)(?::(?<customFormat>[a-z0-9]+))?(?<suffix>[- ._)\]]*)\}",
RegexOptions.Compiled | RegexOptions.IgnoreCase);
private static readonly Regex TrackRegex = new Regex(@"(?<track>\{track(?:\:0+)?})",
public static readonly Regex TrackRegex = new Regex(@"(?<track>\{track(?:\:0+)?})",
RegexOptions.Compiled | RegexOptions.IgnoreCase);
private static readonly Regex MediumRegex = new Regex(@"(?<medium>\{medium(?:\:0+)?})",
@ -45,7 +45,7 @@ namespace NzbDrone.Core.Organizer
public static readonly Regex SeasonEpisodePatternRegex = new Regex(@"(?<separator>(?<=})[- ._]+?)?(?<seasonEpisode>s?{season(?:\:0+)?}(?<episodeSeparator>[- ._]?[ex])(?<episode>{episode(?:\:0+)?}))(?<separator>[- ._]+?(?={))?",
RegexOptions.Compiled | RegexOptions.IgnoreCase);
public static readonly Regex AirDateRegex = new Regex(@"\{Air(\s|\W|_)Date\}", RegexOptions.Compiled | RegexOptions.IgnoreCase);
public static readonly Regex ReleaseDateRegex = new Regex(@"\{Release(\s|\W|_)Year\}", RegexOptions.Compiled | RegexOptions.IgnoreCase);
public static readonly Regex ArtistNameRegex = new Regex(@"(?<token>\{(?:Artist)(?<separator>[- ._])(Clean)?Name(The)?\})",
RegexOptions.Compiled | RegexOptions.IgnoreCase);
@ -53,6 +53,9 @@ namespace NzbDrone.Core.Organizer
public static readonly Regex AlbumTitleRegex = new Regex(@"(?<token>\{(?:Album)(?<separator>[- ._])(Clean)?Title(The)?\})",
RegexOptions.Compiled | RegexOptions.IgnoreCase);
public static readonly Regex TrackTitleRegex = new Regex(@"(?<token>\{(?:Track)(?<separator>[- ._])(Clean)?Title(The)?\})",
RegexOptions.Compiled | RegexOptions.IgnoreCase);
private static readonly Regex FileNameCleanupRegex = new Regex(@"([- ._])(\1)+", RegexOptions.Compiled);
private static readonly Regex TrimSeparatorsRegex = new Regex(@"[- ._]$", RegexOptions.Compiled);
@ -265,6 +268,7 @@ namespace NzbDrone.Core.Organizer
tokenHandlers["{Album Title}"] = m => album.Title;
tokenHandlers["{Album CleanTitle}"] = m => CleanTitle(album.Title);
tokenHandlers["{Album TitleThe}"] = m => TitleThe(album.Title);
tokenHandlers["{Album Type}"] = m => album.AlbumType;
if (album.ReleaseDate.HasValue)
{
tokenHandlers["{Release Year}"] = m => album.ReleaseDate.Value.Year.ToString();

@ -37,6 +37,7 @@ namespace NzbDrone.Core.Organizer
{
Title = "The Album Title",
ReleaseDate = System.DateTime.Today,
AlbumType = "Album",
Media = new List<Medium>
{
new Medium

@ -24,22 +24,31 @@ namespace NzbDrone.Core.Organizer
public static IRuleBuilderOptions<T, string> ValidAlbumFolderFormat<T>(this IRuleBuilder<T, string> ruleBuilder)
{
ruleBuilder.SetValidator(new NotEmptyValidator(null));
return ruleBuilder.SetValidator(new RegularExpressionValidator(FileNameBuilder.AlbumTitleRegex)).WithMessage("Must contain Album title");
return ruleBuilder.SetValidator(new RegularExpressionValidator(FileNameBuilder.AlbumTitleRegex)).WithMessage("Must contain Album title")
.SetValidator(new RegularExpressionValidator(FileNameBuilder.ReleaseDateRegex)).WithMessage("Must contain Release year");
}
}
public class ValidStandardTrackFormatValidator : PropertyValidator
{
public ValidStandardTrackFormatValidator()
: base("Must contain Album Title and Track numbers OR Original Title")
: base("Must contain Track Title and Track numbers OR Original Title")
{
}
protected override bool IsValid(PropertyValidatorContext context)
{
var value = context.PropertyValue as string;
return true; //TODO Add Logic here
if (!(FileNameBuilder.TrackTitleRegex.IsMatch(value) &&
FileNameBuilder.TrackRegex.IsMatch(value)) &&
!FileNameValidation.OriginalTokenRegex.IsMatch(value))
{
return false;
}
return true;
}
}
}

Loading…
Cancel
Save