diff --git a/src/NzbDrone.Core.Test/OrganizerTests/FileNameBuilderTests/MovieTitleFirstCharacterFixture.cs b/src/NzbDrone.Core.Test/OrganizerTests/FileNameBuilderTests/MovieTitleFirstCharacterFixture.cs index 6e936063a6..99b1bec7ed 100644 --- a/src/NzbDrone.Core.Test/OrganizerTests/FileNameBuilderTests/MovieTitleFirstCharacterFixture.cs +++ b/src/NzbDrone.Core.Test/OrganizerTests/FileNameBuilderTests/MovieTitleFirstCharacterFixture.cs @@ -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)); + } } } diff --git a/src/NzbDrone.Core/Organizer/FileNameBuilder.cs b/src/NzbDrone.Core/Organizer/FileNameBuilder.cs index e8aa4b99e9..1959a7a9dc 100644 --- a/src/NzbDrone.Core/Organizer/FileNameBuilder.cs +++ b/src/NzbDrone.Core/Organizer/FileNameBuilder.cs @@ -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> 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);