Skip to content

Commit

Permalink
Add title without umlauts as base variation
Browse files Browse the repository at this point in the history
  • Loading branch information
PCJones committed Feb 19, 2024
1 parent b2e4dbb commit f804dd7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
20 changes: 14 additions & 6 deletions UmlautAdaptarr/Models/SearchItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,17 @@ private void GenerateVariationsForBooksAndAudio(string expectedTitle, string med
TitleSearchVariations = GenerateVariations($"{expectedAuthor} {expectedTitle}", mediaType).ToArray();
AuthorMatchVariations = GenerateVariations(expectedAuthor, mediaType).ToArray();

if (mediaType == "book" && (expectedAuthor?.Contains(' ') ?? false))
if (mediaType == "book")
{
var nameParts = expectedAuthor.Split(' ', StringSplitOptions.RemoveEmptyEntries);
var lastName = nameParts.Last();
var firstNames = nameParts.Take(nameParts.Length - 1);
if (expectedAuthor?.Contains(' ') ?? false)
{
var nameParts = expectedAuthor.Split(' ', StringSplitOptions.RemoveEmptyEntries);
var lastName = nameParts.Last();
var firstNames = nameParts.Take(nameParts.Length - 1);

var alternativeExpectedAuthor = $"{lastName}, {string.Join(" ", firstNames)}";
AuthorMatchVariations = [.. AuthorMatchVariations, .. GenerateVariations(alternativeExpectedAuthor, mediaType)];
var alternativeExpectedAuthor = $"{lastName}, {string.Join(" ", firstNames)}";
AuthorMatchVariations = [.. AuthorMatchVariations, .. GenerateVariations(alternativeExpectedAuthor, mediaType)];
}
}
}

Expand All @@ -135,6 +138,11 @@ private IEnumerable<string> GenerateVariations(string? title, string mediaType)
cleanTitle.RemoveGermanUmlautDots()
};

if (mediaType == "book" || mediaType == "audio")
{
baseVariations.Add(cleanTitle.RemoveGermanUmlauts());
}

// TODO: determine if this is really needed
// Additional variations to accommodate titles with "-"
if (cleanTitle.Contains('-'))
Expand Down
12 changes: 12 additions & 0 deletions UmlautAdaptarr/Utilities/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,18 @@ public static string RemoveGermanUmlautDots(this string text)
.Replace("ß", "ss");
}

public static string RemoveGermanUmlauts(this string text)
{
return text
.Replace("ö", "")
.Replace("ü", "")
.Replace("ä", "")
.Replace("Ö", "")
.Replace("Ü", "")
.Replace("Ä", "")
.Replace("ß", "");
}

public static string RemoveExtraWhitespaces(this string text)
{
return MultipleWhitespaceRegex().Replace(text, " ");
Expand Down

0 comments on commit f804dd7

Please sign in to comment.