Skip to content

Commit

Permalink
Add lowercasing ordinals (1st, 10th) and uppercase special words (IMA…
Browse files Browse the repository at this point in the history
…X) in edition tags
  • Loading branch information
brandonscript committed Mar 11, 2024
1 parent ada326e commit 5582e8b
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,49 @@ 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]")]
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);
}
}
}
18 changes: 17 additions & 1 deletion src/NzbDrone.Core/Organizer/FileNameBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)\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);
}
}

Expand Down

2 comments on commit 5582e8b

@andy-reeves
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't these still be all uppercase:

[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]")
```]

Like:
      ```
  [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]")]

and similar for these too?

@brandonscript
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@andy-reeves I presumed that if someone explicitly wanted lowercase naming, they should still be able to get that result.

Please sign in to comment.