2 Commits

Author SHA1 Message Date
pcjones
6932c4b2f8 Add hyphen title matching if title contains colon 2024-02-23 14:09:20 +01:00
pcjones
ff051569ca Fix separator being added twice 2024-02-23 14:08:56 +01:00
2 changed files with 41 additions and 2 deletions

View File

@@ -43,7 +43,30 @@ namespace UmlautAdaptarr.Models
} }
else else
{ {
GenerateVariationsForTV(germanTitle, mediaType, aliases); // if mediatype is movie/tv and the Expected Title ends with a year but the german title doesn't then append the year to the german title and to aliases
// example: https://thetvdb.com/series/385925-avatar-the-last-airbender -> german Title is without 2024
var yearAtEndOfTitleMatch = YearAtEndOfTitleRegex().Match(expectedTitle);
if (yearAtEndOfTitleMatch.Success)
{
string year = yearAtEndOfTitleMatch.Value[1..^1];
if (GermanTitle != null && !GermanTitle.Contains(year))
{
GermanTitle = $"{germanTitle} {year}";
}
if (aliases != null)
{
for (int i = 0; i < aliases.Length; i++)
{
if (!aliases[i].Contains(year))
{
aliases[i] = $"{aliases[i]} {year}";
}
}
}
}
GenerateVariationsForTV(GermanTitle, mediaType, aliases);
} }
} }
@@ -60,6 +83,12 @@ namespace UmlautAdaptarr.Models
foreach (var alias in aliases) foreach (var alias in aliases)
{ {
allTitleVariations.AddRange(GenerateVariations(alias, mediaType)); allTitleVariations.AddRange(GenerateVariations(alias, mediaType));
// If title contains ":" also match for "-"
if (alias.Contains(':'))
{
allTitleVariations.Add(alias.Replace(":", " -"));
}
} }
} }
@@ -79,6 +108,12 @@ namespace UmlautAdaptarr.Models
} }
// If title contains ":" also match for "-"
if (germanTitle?.Contains(':') ?? false)
{
allTitleVariations.Add(germanTitle.Replace(":", " -"));
}
TitleMatchVariations = allTitleVariations.Distinct(StringComparer.InvariantCultureIgnoreCase).ToArray(); TitleMatchVariations = allTitleVariations.Distinct(StringComparer.InvariantCultureIgnoreCase).ToArray();
} }
@@ -123,6 +158,7 @@ namespace UmlautAdaptarr.Models
{ {
return []; return [];
} }
var cleanTitle = title.GetCleanTitle(); var cleanTitle = title.GetCleanTitle();
if (cleanTitle?.Length == 0) if (cleanTitle?.Length == 0)
@@ -180,5 +216,8 @@ namespace UmlautAdaptarr.Models
return cleanedVariations.Distinct(); return cleanedVariations.Distinct();
} }
[GeneratedRegex(@"\(\d{4}\)$")]
private static partial Regex YearAtEndOfTitleRegex();
} }
} }

View File

@@ -221,7 +221,7 @@ namespace UmlautAdaptarr.Services
*/ */
// Construct the new title with the original suffix // Construct the new title with the original suffix
var newTitle = newTitlePrefix + (string.IsNullOrEmpty(suffix) ? "" : separator + suffix); var newTitle = newTitlePrefix + (string.IsNullOrEmpty(suffix) ? "" : suffix.StartsWith(separator) ? suffix : $"{separator}{suffix}");
// Update the title element's value with the new title // Update the title element's value with the new title
//titleElement.Value = newTitle + $"({originalTitle.Substring(0, variationLength)})"; //titleElement.Value = newTitle + $"({originalTitle.Substring(0, variationLength)})";