Handle generational suffixes
This commit is contained in:
@@ -27,6 +27,9 @@ namespace MediaBrowser.Providers.Plugins.Omdb
|
||||
/// <summary>Provider for OMDB service.</summary>
|
||||
public class OmdbProvider
|
||||
{
|
||||
/// <summary>Generational suffixes that OMDb separates from the name with a comma.</summary>
|
||||
private static readonly string[] NameSuffixes = ["Jr", "Jnr", "Sr", "Snr", "II", "III", "IV", "V"];
|
||||
|
||||
private readonly IFileSystem _fileSystem;
|
||||
private readonly IServerConfigurationManager _configurationManager;
|
||||
private readonly IHttpClientFactory _httpClientFactory;
|
||||
@@ -425,6 +428,11 @@ namespace MediaBrowser.Providers.Plugins.Omdb
|
||||
AddPeople(itemResult, result.Actors, PersonKind.Actor);
|
||||
}
|
||||
|
||||
/// <summary>Adds the people from a comma separated OMDb credit list.</summary>
|
||||
/// <typeparam name="T">The item type.</typeparam>
|
||||
/// <param name="itemResult">The metadata result to add the people to.</param>
|
||||
/// <param name="credits">The comma separated OMDb credit list.</param>
|
||||
/// <param name="type">The kind of person each credit describes.</param>
|
||||
internal static void AddPeople<T>(MetadataResult<T> itemResult, string credits, PersonKind type)
|
||||
where T : BaseItem
|
||||
{
|
||||
@@ -433,6 +441,8 @@ namespace MediaBrowser.Providers.Plugins.Omdb
|
||||
return;
|
||||
}
|
||||
|
||||
var names = new List<string>();
|
||||
|
||||
foreach (var credit in credits.Split(',', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries))
|
||||
{
|
||||
// OMDb annotates the credited role in parentheses, e.g. "Mari Okada (screenplay)". The same
|
||||
@@ -444,11 +454,24 @@ namespace MediaBrowser.Providers.Plugins.Omdb
|
||||
name = name[..annotation].TrimEnd();
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(name))
|
||||
if (name.Length == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// A generational suffix is separated from the name it belongs to by the same comma the list
|
||||
// uses, e.g. "Jack Salvatore, Jr.", so it has to be joined back instead of becoming a credit.
|
||||
if (names.Count > 0 && IsNameSuffix(name))
|
||||
{
|
||||
names[^1] = names[^1] + ", " + name;
|
||||
continue;
|
||||
}
|
||||
|
||||
names.Add(name);
|
||||
}
|
||||
|
||||
foreach (var name in names)
|
||||
{
|
||||
itemResult.AddPerson(new PersonInfo
|
||||
{
|
||||
Name = name,
|
||||
@@ -457,6 +480,13 @@ namespace MediaBrowser.Providers.Plugins.Omdb
|
||||
}
|
||||
}
|
||||
|
||||
private static bool IsNameSuffix(string value)
|
||||
{
|
||||
var suffix = value.EndsWith('.') ? value[..^1] : value;
|
||||
|
||||
return NameSuffixes.Contains(suffix, StringComparer.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
private static bool IsConfiguredForEnglish(BaseItem item, string language)
|
||||
{
|
||||
if (string.IsNullOrEmpty(language))
|
||||
|
||||
@@ -34,6 +34,22 @@ namespace Jellyfin.Providers.Tests.Omdb
|
||||
result.People!.Select(p => p.Name));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("Jack Salvatore, Jr.", "Jack Salvatore, Jr.")]
|
||||
[InlineData("Efrem Zimbalist, Jr., Tom Hanks", "Efrem Zimbalist, Jr.|Tom Hanks")]
|
||||
[InlineData("Tom Hanks, Sammy Davis, Jr", "Tom Hanks|Sammy Davis, Jr")]
|
||||
[InlineData("Harold Ramis, Ken Griffey, III (voice)", "Harold Ramis|Ken Griffey, III")]
|
||||
[InlineData("Robert Downey Jr., Gwyneth Paltrow", "Robert Downey Jr.|Gwyneth Paltrow")]
|
||||
[InlineData("Jr., Tom Hanks", "Jr.|Tom Hanks")]
|
||||
public void AddPeople_GenerationalSuffix_StaysWithItsName(string credits, string expected)
|
||||
{
|
||||
var result = new MetadataResult<Movie>();
|
||||
|
||||
OmdbProvider.AddPeople(result, credits, PersonKind.Actor);
|
||||
|
||||
Assert.Equal(expected.Split('|'), result.People!.Select(p => p.Name));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(null)]
|
||||
[InlineData("")]
|
||||
|
||||
Reference in New Issue
Block a user