mirror of
https://github.com/Radarr/Radarr.git
synced 2024-11-20 01:42:35 +01:00
Add 'always lowercase' and 'always uppercase' formatters to edition tags
- Always lowercase ordinals (1st, 2nd, 10th, etc.) - Always uppercase special words (IMAX, 3D, SDR, HDR) in edition tags
This commit is contained in:
parent
d0a10379f9
commit
e89de12a48
@ -63,5 +63,71 @@ public void should_conditional_hide_edition_tags_in_plex_format(string movieForm
|
||||
Subject.BuildFileName(_movie, _movieFile)
|
||||
.Should().Be("South Park");
|
||||
}
|
||||
|
||||
[Test]
|
||||
[TestCase("10th anniversary edition", "{Movie Title} [{edition tags}]", "South Park [10th anniversary edition]")]
|
||||
[TestCase("10TH anniversary edition", "{Movie Title} [{edition tags}]", "South Park [10th anniversary edition]")]
|
||||
[TestCase("10Th anniversary edition", "{Movie Title} [{edition tags}]", "South Park [10th anniversary edition]")]
|
||||
[TestCase("10th anniversary edition", "{Movie Title} [{Edition Tags}]", "South Park [10th Anniversary Edition]")]
|
||||
[TestCase("10TH anniversary edition", "{Movie Title} [{Edition Tags}]", "South Park [10th Anniversary Edition]")]
|
||||
[TestCase("10Th anniversary edition", "{Movie Title} [{Edition Tags}]", "South Park [10th Anniversary Edition]")]
|
||||
[TestCase("10th anniversary edition", "{Movie Title} [{EDITION TAGS}]", "South Park [10TH ANNIVERSARY EDITION]")]
|
||||
[TestCase("10TH anniversary edition", "{Movie Title} [{EDITION TAGS}]", "South Park [10TH ANNIVERSARY EDITION]")]
|
||||
[TestCase("10Th anniversary edition", "{Movie Title} [{EDITION TAGS}]", "South Park [10TH ANNIVERSARY EDITION]")]
|
||||
public void should_always_lowercase_ordinals(string edition, string movieFormat, string expected)
|
||||
{
|
||||
_movieFile.Edition = edition;
|
||||
_namingConfig.StandardMovieFormat = movieFormat;
|
||||
|
||||
Subject.BuildFileName(_movie, _movieFile)
|
||||
.Should().Be(expected);
|
||||
}
|
||||
|
||||
[Test]
|
||||
[TestCase("imax", "{Movie Title} [{edition tags}]", "South Park [imax]")]
|
||||
[TestCase("IMAX", "{Movie Title} [{edition tags}]", "South Park [imax]")]
|
||||
[TestCase("Imax", "{Movie Title} [{edition tags}]", "South Park [imax]")]
|
||||
[TestCase("imax", "{Movie Title} [{Edition Tags}]", "South Park [IMAX]")]
|
||||
[TestCase("IMAX", "{Movie Title} [{Edition Tags}]", "South Park [IMAX]")]
|
||||
[TestCase("Imax", "{Movie Title} [{Edition Tags}]", "South Park [IMAX]")]
|
||||
[TestCase("imax", "{Movie Title} [{EDITION TAGS}]", "South Park [IMAX]")]
|
||||
[TestCase("IMAX", "{Movie Title} [{EDITION TAGS}]", "South Park [IMAX]")]
|
||||
[TestCase("Imax", "{Movie Title} [{EDITION TAGS}]", "South Park [IMAX]")]
|
||||
|
||||
[TestCase("3d", "{Movie Title} [{edition tags}]", "South Park [3d]")]
|
||||
[TestCase("3D", "{Movie Title} [{edition tags}]", "South Park [3d]")]
|
||||
[TestCase("3d", "{Movie Title} [{Edition Tags}]", "South Park [3D]")]
|
||||
[TestCase("3D", "{Movie Title} [{Edition Tags}]", "South Park [3D]")]
|
||||
[TestCase("3d", "{Movie Title} [{EDITION TAGS}]", "South Park [3D]")]
|
||||
[TestCase("3D", "{Movie Title} [{EDITION TAGS}]", "South Park [3D]")]
|
||||
|
||||
[TestCase("hdr", "{Movie Title} [{edition tags}]", "South Park [hdr]")]
|
||||
[TestCase("HDR", "{Movie Title} [{edition tags}]", "South Park [hdr]")]
|
||||
[TestCase("Hdr", "{Movie Title} [{edition tags}]", "South Park [hdr]")]
|
||||
[TestCase("hdr", "{Movie Title} [{Edition Tags}]", "South Park [HDR]")]
|
||||
[TestCase("HDR", "{Movie Title} [{Edition Tags}]", "South Park [HDR]")]
|
||||
[TestCase("Hdr", "{Movie Title} [{Edition Tags}]", "South Park [HDR]")]
|
||||
[TestCase("hdr", "{Movie Title} [{EDITION TAGS}]", "South Park [HDR]")]
|
||||
[TestCase("HDR", "{Movie Title} [{EDITION TAGS}]", "South Park [HDR]")]
|
||||
[TestCase("Hdr", "{Movie Title} [{EDITION TAGS}]", "South Park [HDR]")]
|
||||
|
||||
[TestCase("sdr", "{Movie Title} [{edition tags}]", "South Park [sdr]")]
|
||||
[TestCase("SDR", "{Movie Title} [{edition tags}]", "South Park [sdr]")]
|
||||
[TestCase("Sdr", "{Movie Title} [{edition tags}]", "South Park [sdr]")]
|
||||
[TestCase("sdr", "{Movie Title} [{Edition Tags}]", "South Park [SDR]")]
|
||||
[TestCase("SDR", "{Movie Title} [{Edition Tags}]", "South Park [SDR]")]
|
||||
[TestCase("Sdr", "{Movie Title} [{Edition Tags}]", "South Park [SDR]")]
|
||||
[TestCase("sdr", "{Movie Title} [{EDITION TAGS}]", "South Park [SDR]")]
|
||||
[TestCase("SDR", "{Movie Title} [{EDITION TAGS}]", "South Park [SDR]")]
|
||||
[TestCase("Sdr", "{Movie Title} [{EDITION TAGS}]", "South Park [SDR]")]
|
||||
|
||||
public void should_always_uppercase_special_strings(string edition, string movieFormat, string expected)
|
||||
{
|
||||
_movieFile.Edition = edition;
|
||||
_namingConfig.StandardMovieFormat = movieFormat;
|
||||
|
||||
Subject.BuildFileName(_movie, _movieFile)
|
||||
.Should().Be(expected);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -298,11 +298,27 @@ private string GetLanguageTitle(Movie movie, string isoCodes)
|
||||
return movie.Title;
|
||||
}
|
||||
|
||||
private string ToTitleCaseIgnoreOrdinals(string text)
|
||||
{
|
||||
return Regex.Replace(text, @"\b([0-9]{1,3}(?:st|th|rd|nd))\b", new MatchEvaluator((m) => m.Captures[0].Value.ToLower()), RegexOptions.IgnoreCase);
|
||||
}
|
||||
|
||||
private string ToTitleCaseAlwaysUpper(string text)
|
||||
{
|
||||
return Regex.Replace(text, @"\b(imax|3d|sdr|hdr)\b", new MatchEvaluator((m) => m.Captures[0].Value.ToUpper()), RegexOptions.IgnoreCase);
|
||||
}
|
||||
|
||||
private string ToEditionTitleCase(MovieFile movieFile)
|
||||
{
|
||||
var titleCase = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(movieFile.Edition.ToLower());
|
||||
return ToTitleCaseAlwaysUpper(ToTitleCaseIgnoreOrdinals(titleCase));
|
||||
}
|
||||
|
||||
private void AddEditionTagsTokens(Dictionary<string, Func<TokenMatch, string>> tokenHandlers, MovieFile movieFile)
|
||||
{
|
||||
if (movieFile.Edition.IsNotNullOrWhiteSpace())
|
||||
{
|
||||
tokenHandlers["{Edition Tags}"] = m => Truncate(CultureInfo.CurrentCulture.TextInfo.ToTitleCase(movieFile.Edition.ToLower()), m.CustomFormat);
|
||||
tokenHandlers["{Edition Tags}"] = m => Truncate(ToEditionTitleCase(movieFile), m.CustomFormat);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user