Add Octothorpe Parent for Movies starting with numbers

This commit is contained in:
sharinganthief 2025-11-07 15:28:03 -05:00
parent 7d8444c435
commit de88ad9c72
2 changed files with 48 additions and 0 deletions

View file

@ -59,5 +59,25 @@ public void should_be_able_to_use_lower_case_first_character()
Subject.GetMovieFolder(_movie).Should().Be(Path.Combine("w", "westworld"));
}
[TestCase("The Mist", "M", "The Mist")]
[TestCase("30 Rock", "#", "30 Rock")]
public void should_get_expected_folder_name_back_octo(string title, string parent, string child)
{
_movie.Title = title;
_namingConfig.MovieFolderFormat = "{Movie TitleFirstCharacterOctothorpe}\\{Movie Title}";
Subject.GetMovieFolder(_movie).Should().Be(Path.Combine(parent, child));
}
[TestCase("The Mist", "m", "the mist")]
[TestCase("30 Rock", "#", "30 rock")]
public void should_be_able_to_use_lower_case_first_character_octo(string title, string parent, string child)
{
_movie.Title = title;
_namingConfig.MovieFolderFormat = "{movie titlefirstcharacteroctothorpe}\\{movie title}";
Subject.GetMovieFolder(_movie).Should().Be(Path.Combine(parent, child));
}
}
}

View file

@ -227,6 +227,33 @@ public static string CleanTitleThe(string title)
return CleanTitle(title);
}
public static string TitleFirstCharacterOctothorpe(string title)
{
if (char.IsLetter(title[0]))
{
return title.Substring(0, 1).ToUpper().RemoveDiacritics()[0].ToString();
}
if (char.IsDigit(title[0]))
{
return "#";
}
// Try the second character if the first was non alphanumeric
if (char.IsLetter(title[1]))
{
return title.Substring(1, 1).ToUpper().RemoveDiacritics()[0].ToString();
}
if (char.IsDigit(title[1]))
{
return "#";
}
// Default to "_" if no alphanumeric character can be found in the first 2 positions
return "_";
}
public static string TitleFirstCharacter(string title)
{
if (char.IsLetterOrDigit(title[0]))
@ -263,6 +290,7 @@ private void AddMovieTokens(Dictionary<string, Func<TokenMatch, string>> tokenHa
tokenHandlers["{Movie TitleThe}"] = m => Truncate(TitleThe(movie.Title), m.CustomFormat);
tokenHandlers["{Movie CleanTitleThe}"] = m => Truncate(CleanTitleThe(movie.Title), m.CustomFormat);
tokenHandlers["{Movie TitleFirstCharacter}"] = m => TitleFirstCharacter(TitleThe(GetLanguageTitle(movie, m.CustomFormat)));
tokenHandlers["{Movie TitleFirstCharacterOctothorpe}"] = m => TitleFirstCharacterOctothorpe(TitleThe(GetLanguageTitle(movie, m.CustomFormat)));
tokenHandlers["{Movie OriginalTitle}"] = m => Truncate(movie.MovieMetadata.Value.OriginalTitle, m.CustomFormat) ?? string.Empty;
tokenHandlers["{Movie CleanOriginalTitle}"] = m => Truncate(CleanTitle(movie.MovieMetadata.Value.OriginalTitle ?? string.Empty), m.CustomFormat);