mirror of
https://github.com/lidarr/Lidarr
synced 2025-02-24 23:02:44 +00:00
Fixed: Cleanup First Character in Name when using 'NameFirstCharacter'
(cherry picked from commit b3c691859a0841cde9bb2655c01c240cc5279d74) Closes #4179
This commit is contained in:
parent
86f311a23b
commit
2e91a61ccf
2 changed files with 23 additions and 1 deletions
|
@ -37,6 +37,11 @@ public void Setup()
|
|||
[TestCase("The Mist", "M", "The Mist")]
|
||||
[TestCase("A", "A", "A")]
|
||||
[TestCase("30 Rock", "3", "30 Rock")]
|
||||
[TestCase("The '80s Greatest", "8", "The '80s Greatest")]
|
||||
[TestCase("좀비버스", "좀", "좀비버스")]
|
||||
[TestCase("¡Mucha Lucha!", "M", "¡Mucha Lucha!")]
|
||||
[TestCase(".hack", "H", "hack")]
|
||||
[TestCase("Ütopya", "U", "Ütopya")]
|
||||
public void should_get_expected_folder_name_back(string title, string parent, string child)
|
||||
{
|
||||
_artist.Name = title;
|
||||
|
|
|
@ -264,6 +264,23 @@ public static string TitleThe(string title)
|
|||
return TitlePrefixRegex.Replace(title, "$2, $1$3");
|
||||
}
|
||||
|
||||
public static string TitleFirstCharacter(string title)
|
||||
{
|
||||
if (char.IsLetterOrDigit(title[0]))
|
||||
{
|
||||
return title.Substring(0, 1).ToUpper().RemoveAccent();
|
||||
}
|
||||
|
||||
// Try the second character if the first was non alphanumeric
|
||||
if (char.IsLetterOrDigit(title[1]))
|
||||
{
|
||||
return title.Substring(1, 1).ToUpper().RemoveAccent();
|
||||
}
|
||||
|
||||
// Default to "_" if no alphanumeric character can be found in the first 2 positions
|
||||
return "_";
|
||||
}
|
||||
|
||||
public static string CleanFileName(string name)
|
||||
{
|
||||
return CleanFileName(name, NamingConfig.Default);
|
||||
|
@ -282,7 +299,7 @@ private void AddArtistTokens(Dictionary<string, Func<TokenMatch, string>> tokenH
|
|||
tokenHandlers["{Artist CleanName}"] = m => CleanTitle(artist.Name);
|
||||
tokenHandlers["{Artist NameThe}"] = m => TitleThe(artist.Name);
|
||||
tokenHandlers["{Artist Genre}"] = m => artist.Metadata.Value.Genres?.FirstOrDefault() ?? string.Empty;
|
||||
tokenHandlers["{Artist NameFirstCharacter}"] = m => TitleThe(artist.Name).Substring(0, 1).FirstCharToUpper();
|
||||
tokenHandlers["{Artist NameFirstCharacter}"] = m => TitleFirstCharacter(TitleThe(artist.Name));
|
||||
tokenHandlers["{Artist MbId}"] = m => artist.ForeignArtistId ?? string.Empty;
|
||||
|
||||
if (artist.Metadata.Value.Disambiguation != null)
|
||||
|
|
Loading…
Reference in a new issue