Convert Person.Type to use PersonKind enum (#9487)

This commit is contained in:
Cody Robibero 2023-03-25 11:52:02 -06:00 committed by GitHub
parent 7ffe44d705
commit 89be3aa37f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
26 changed files with 235 additions and 138 deletions

View File

@ -10,6 +10,7 @@ using System.Text;
using System.Xml;
using Emby.Dlna.ContentDirectory;
using Jellyfin.Data.Entities;
using Jellyfin.Data.Enums;
using MediaBrowser.Controller.Channels;
using MediaBrowser.Controller.Drawing;
using MediaBrowser.Controller.Entities;
@ -870,11 +871,11 @@ namespace Emby.Dlna.Didl
var types = new[]
{
PersonType.Director,
PersonType.Writer,
PersonType.Producer,
PersonType.Composer,
"creator"
PersonKind.Director,
PersonKind.Writer,
PersonKind.Producer,
PersonKind.Composer,
PersonKind.Creator
};
// Seeing some LG models locking up due content with large lists of people
@ -888,10 +889,13 @@ namespace Emby.Dlna.Didl
foreach (var actor in people)
{
var type = types.FirstOrDefault(i => string.Equals(i, actor.Type, StringComparison.OrdinalIgnoreCase) || string.Equals(i, actor.Role, StringComparison.OrdinalIgnoreCase))
?? PersonType.Actor;
var type = types.FirstOrDefault(i => i == actor.Type || string.Equals(actor.Role, i.ToString(), StringComparison.OrdinalIgnoreCase));
if (type == PersonKind.Unknown)
{
type = PersonKind.Actor;
}
AddValue(writer, "upnp", type.ToLowerInvariant(), actor.Name, NsUpnp);
AddValue(writer, "upnp", type.ToString().ToLowerInvariant(), actor.Name, NsUpnp);
}
}

View File

@ -5540,7 +5540,7 @@ AND Type = @InternalPersonType)");
statement.TryBind("@Name" + index, person.Name);
statement.TryBind("@Role" + index, person.Role);
statement.TryBind("@PersonType" + index, person.Type);
statement.TryBind("@PersonType" + index, person.Type.ToString());
statement.TryBind("@SortOrder" + index, person.SortOrder);
statement.TryBind("@ListOrder" + index, listIndex);
@ -5569,9 +5569,10 @@ AND Type = @InternalPersonType)");
item.Role = role;
}
if (reader.TryGetString(3, out var type))
if (reader.TryGetString(3, out var type)
&& Enum.TryParse(type, true, out PersonKind personKind))
{
item.Type = type;
item.Type = personKind;
}
if (reader.TryGetInt32(4, out var sortOrder))

View File

@ -523,32 +523,32 @@ namespace Emby.Server.Implementations.Dto
var people = _libraryManager.GetPeople(item).OrderBy(i => i.SortOrder ?? int.MaxValue)
.ThenBy(i =>
{
if (i.IsType(PersonType.Actor))
if (i.IsType(PersonKind.Actor))
{
return 0;
}
if (i.IsType(PersonType.GuestStar))
if (i.IsType(PersonKind.GuestStar))
{
return 1;
}
if (i.IsType(PersonType.Director))
if (i.IsType(PersonKind.Director))
{
return 2;
}
if (i.IsType(PersonType.Writer))
if (i.IsType(PersonKind.Writer))
{
return 3;
}
if (i.IsType(PersonType.Producer))
if (i.IsType(PersonKind.Producer))
{
return 4;
}
if (i.IsType(PersonType.Composer))
if (i.IsType(PersonKind.Composer))
{
return 4;
}

View File

@ -2032,7 +2032,7 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
var people = item.Id.Equals(default) ? new List<PersonInfo>() : _libraryManager.GetPeople(item);
var directors = people
.Where(i => IsPersonType(i, PersonType.Director))
.Where(i => i.IsType(PersonKind.Director))
.Select(i => i.Name)
.ToList();
@ -2042,7 +2042,7 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
}
var writers = people
.Where(i => IsPersonType(i, PersonType.Writer))
.Where(i => i.IsType(PersonKind.Writer))
.Select(i => i.Name)
.Distinct(StringComparer.OrdinalIgnoreCase)
.ToList();
@ -2122,10 +2122,6 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
}
}
private static bool IsPersonType(PersonInfo person, string type)
=> string.Equals(person.Type, type, StringComparison.OrdinalIgnoreCase)
|| string.Equals(person.Role, type, StringComparison.OrdinalIgnoreCase);
private LiveTvProgram GetProgramInfoFromCache(string programId)
{
var query = new InternalItemsQuery

View File

@ -0,0 +1,97 @@
namespace Jellyfin.Data.Enums;
/// <summary>
/// The person kind.
/// </summary>
public enum PersonKind
{
/// <summary>
/// An unknown person kind.
/// </summary>
Unknown,
/// <summary>
/// A person whose profession is acting on the stage, in films, or on television.
/// </summary>
Actor,
/// <summary>
/// A person who supervises the actors and other staff in a film, play, or similar production.
/// </summary>
Director,
/// <summary>
/// A person who writes music, especially as a professional occupation.
/// </summary>
Composer,
/// <summary>
/// A writer of a book, article, or document. Can also be used as a generic term for music writer if there is a lack of specificity.
/// </summary>
Writer,
/// <summary>
/// A well-known actor or other performer who appears in a work in which they do not have a regular role.
/// </summary>
GuestStar,
/// <summary>
/// A person responsible for the financial and managerial aspects of the making of a film or broadcast or for staging a play, opera, etc.
/// </summary>
Producer,
/// <summary>
/// A person who directs the performance of an orchestra or choir.
/// </summary>
Conductor,
/// <summary>
/// A person who writes the words to a song or musical.
/// </summary>
Lyricist,
/// <summary>
/// A person who adapts a musical composition for performance.
/// </summary>
Arranger,
/// <summary>
/// An audio engineer who performed a general engineering role.
/// </summary>
Engineer,
/// <summary>
/// An engineer responsible for using a mixing console to mix a recorded track into a single piece of music suitable for release.
/// </summary>
Mixer,
/// <summary>
/// A person who remixed a recording by taking one or more other tracks, substantially altering them and mixing them together with other material.
/// </summary>
Remixer,
/// <summary>
/// A person who created the material.
/// </summary>
Creator,
/// <summary>
/// A person who was the artist.
/// </summary>
Artist,
/// <summary>
/// A person who was the album artist.
/// </summary>
AlbumArtist,
/// <summary>
/// A person who was the author.
/// </summary>
Author,
/// <summary>
/// A person who was the illustrator.
/// </summary>
Illustrator,
}

View File

@ -3,6 +3,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Jellyfin.Data.Enums;
using MediaBrowser.Model.Entities;
namespace MediaBrowser.Controller.Entities
@ -17,38 +18,38 @@ namespace MediaBrowser.Controller.Entities
// Normalize
if (string.Equals(person.Role, PersonType.GuestStar, StringComparison.OrdinalIgnoreCase))
{
person.Type = PersonType.GuestStar;
person.Type = PersonKind.GuestStar;
}
else if (string.Equals(person.Role, PersonType.Director, StringComparison.OrdinalIgnoreCase))
{
person.Type = PersonType.Director;
person.Type = PersonKind.Director;
}
else if (string.Equals(person.Role, PersonType.Producer, StringComparison.OrdinalIgnoreCase))
{
person.Type = PersonType.Producer;
person.Type = PersonKind.Producer;
}
else if (string.Equals(person.Role, PersonType.Writer, StringComparison.OrdinalIgnoreCase))
{
person.Type = PersonType.Writer;
person.Type = PersonKind.Writer;
}
// If the type is GuestStar and there's already an Actor entry, then update it to avoid dupes
if (string.Equals(person.Type, PersonType.GuestStar, StringComparison.OrdinalIgnoreCase))
if (person.Type == PersonKind.GuestStar)
{
var existing = people.FirstOrDefault(p => p.Name.Equals(person.Name, StringComparison.OrdinalIgnoreCase) && p.Type.Equals(PersonType.Actor, StringComparison.OrdinalIgnoreCase));
var existing = people.FirstOrDefault(p => p.Name.Equals(person.Name, StringComparison.OrdinalIgnoreCase) && p.Type == PersonKind.Actor);
if (existing is not null)
{
existing.Type = PersonType.GuestStar;
existing.Type = PersonKind.GuestStar;
MergeExisting(existing, person);
return;
}
}
if (string.Equals(person.Type, PersonType.Actor, StringComparison.OrdinalIgnoreCase))
if (person.Type == PersonKind.Actor)
{
// If the actor already exists without a role and we have one, fill it in
var existing = people.FirstOrDefault(p => p.Name.Equals(person.Name, StringComparison.OrdinalIgnoreCase) && (p.Type.Equals(PersonType.Actor, StringComparison.OrdinalIgnoreCase) || p.Type.Equals(PersonType.GuestStar, StringComparison.OrdinalIgnoreCase)));
var existing = people.FirstOrDefault(p => p.Name.Equals(person.Name, StringComparison.OrdinalIgnoreCase) && (p.Type == PersonKind.Actor || p.Type == PersonKind.GuestStar));
if (existing is null)
{
// Wasn't there - add it
@ -68,8 +69,8 @@ namespace MediaBrowser.Controller.Entities
else
{
var existing = people.FirstOrDefault(p =>
string.Equals(p.Name, person.Name, StringComparison.OrdinalIgnoreCase) &&
string.Equals(p.Type, person.Type, StringComparison.OrdinalIgnoreCase));
string.Equals(p.Name, person.Name, StringComparison.OrdinalIgnoreCase)
&& p.Type == person.Type);
// Check for dupes based on the combination of Name and Type
if (existing is null)

View File

@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using Jellyfin.Data.Enums;
using MediaBrowser.Model.Entities;
namespace MediaBrowser.Controller.Entities
@ -36,7 +37,7 @@ namespace MediaBrowser.Controller.Entities
/// Gets or sets the type.
/// </summary>
/// <value>The type.</value>
public string Type { get; set; }
public PersonKind Type { get; set; }
/// <summary>
/// Gets or sets the ascending sort order.
@ -57,10 +58,6 @@ namespace MediaBrowser.Controller.Entities
return Name;
}
public bool IsType(string type)
{
return string.Equals(Type, type, StringComparison.OrdinalIgnoreCase)
|| string.Equals(Role, type, StringComparison.OrdinalIgnoreCase);
}
public bool IsType(PersonKind type) => Type == type || string.Equals(type.ToString(), Role, StringComparison.OrdinalIgnoreCase);
}
}

View File

@ -6,6 +6,7 @@ using System.Linq;
using System.Text;
using System.Threading;
using System.Xml;
using Jellyfin.Data.Enums;
using Jellyfin.Extensions;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Providers;
@ -370,7 +371,7 @@ namespace MediaBrowser.LocalMetadata.Parsers
case "Director":
{
foreach (var p in SplitNames(reader.ReadElementContentAsString()).Select(v => new PersonInfo { Name = v.Trim(), Type = PersonType.Director }))
foreach (var p in SplitNames(reader.ReadElementContentAsString()).Select(v => new PersonInfo { Name = v.Trim(), Type = PersonKind.Director }))
{
if (string.IsNullOrWhiteSpace(p.Name))
{
@ -385,7 +386,7 @@ namespace MediaBrowser.LocalMetadata.Parsers
case "Writer":
{
foreach (var p in SplitNames(reader.ReadElementContentAsString()).Select(v => new PersonInfo { Name = v.Trim(), Type = PersonType.Writer }))
foreach (var p in SplitNames(reader.ReadElementContentAsString()).Select(v => new PersonInfo { Name = v.Trim(), Type = PersonKind.Writer }))
{
if (string.IsNullOrWhiteSpace(p.Name))
{
@ -412,7 +413,7 @@ namespace MediaBrowser.LocalMetadata.Parsers
else
{
// Old-style piped string
foreach (var p in SplitNames(actors).Select(v => new PersonInfo { Name = v.Trim(), Type = PersonType.Actor }))
foreach (var p in SplitNames(actors).Select(v => new PersonInfo { Name = v.Trim(), Type = PersonKind.Actor }))
{
if (string.IsNullOrWhiteSpace(p.Name))
{
@ -428,7 +429,7 @@ namespace MediaBrowser.LocalMetadata.Parsers
case "GuestStars":
{
foreach (var p in SplitNames(reader.ReadElementContentAsString()).Select(v => new PersonInfo { Name = v.Trim(), Type = PersonType.GuestStar }))
foreach (var p in SplitNames(reader.ReadElementContentAsString()).Select(v => new PersonInfo { Name = v.Trim(), Type = PersonKind.GuestStar }))
{
if (string.IsNullOrWhiteSpace(p.Name))
{
@ -1035,7 +1036,7 @@ namespace MediaBrowser.LocalMetadata.Parsers
private IEnumerable<PersonInfo> GetPersonsFromXmlNode(XmlReader reader)
{
var name = string.Empty;
var type = PersonType.Actor; // If type is not specified assume actor
var type = PersonKind.Actor; // If type is not specified assume actor
var role = string.Empty;
int? sortOrder = null;
@ -1056,11 +1057,7 @@ namespace MediaBrowser.LocalMetadata.Parsers
case "Type":
{
var val = reader.ReadElementContentAsString();
if (!string.IsNullOrWhiteSpace(val))
{
type = val;
}
_ = Enum.TryParse(val, true, out type);
break;
}

View File

@ -374,8 +374,8 @@ namespace MediaBrowser.LocalMetadata.Savers
{
await writer.WriteStartElementAsync(null, "Person", null).ConfigureAwait(false);
await writer.WriteElementStringAsync(null, "Name", null, person.Name).ConfigureAwait(false);
await writer.WriteElementStringAsync(null, "Type", null, person.Type).ConfigureAwait(false);
await writer.WriteElementStringAsync(null, "Role", null, person.Role).ConfigureAwait(false);
await writer.WriteElementStringAsync(null, "Type", null, person.Type.ToString()).ConfigureAwait(false);
await writer.WriteElementStringAsync(null, "Role", null, person.Role.ToString()).ConfigureAwait(false);
if (person.SortOrder.HasValue)
{

View File

@ -9,6 +9,7 @@ using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Xml;
using Jellyfin.Data.Enums;
using Jellyfin.Extensions;
using MediaBrowser.Controller.Library;
using MediaBrowser.Model.Dto;
@ -507,7 +508,7 @@ namespace MediaBrowser.MediaEncoding.Probing
peoples.Add(new BaseItemPerson
{
Name = pair.Value,
Type = PersonType.Writer
Type = PersonKind.Writer
});
}
}
@ -518,7 +519,7 @@ namespace MediaBrowser.MediaEncoding.Probing
peoples.Add(new BaseItemPerson
{
Name = pair.Value,
Type = PersonType.Producer
Type = PersonKind.Producer
});
}
}
@ -529,7 +530,7 @@ namespace MediaBrowser.MediaEncoding.Probing
peoples.Add(new BaseItemPerson
{
Name = pair.Value,
Type = PersonType.Director
Type = PersonKind.Director
});
}
}
@ -1163,7 +1164,7 @@ namespace MediaBrowser.MediaEncoding.Probing
{
foreach (var person in Split(composer, false))
{
people.Add(new BaseItemPerson { Name = person, Type = PersonType.Composer });
people.Add(new BaseItemPerson { Name = person, Type = PersonKind.Composer });
}
}
@ -1171,7 +1172,7 @@ namespace MediaBrowser.MediaEncoding.Probing
{
foreach (var person in Split(conductor, false))
{
people.Add(new BaseItemPerson { Name = person, Type = PersonType.Conductor });
people.Add(new BaseItemPerson { Name = person, Type = PersonKind.Conductor });
}
}
@ -1179,7 +1180,7 @@ namespace MediaBrowser.MediaEncoding.Probing
{
foreach (var person in Split(lyricist, false))
{
people.Add(new BaseItemPerson { Name = person, Type = PersonType.Lyricist });
people.Add(new BaseItemPerson { Name = person, Type = PersonKind.Lyricist });
}
}
@ -1195,7 +1196,7 @@ namespace MediaBrowser.MediaEncoding.Probing
people.Add(new BaseItemPerson
{
Name = match.Groups["name"].Value,
Type = PersonType.Actor,
Type = PersonKind.Actor,
Role = CultureInfo.InvariantCulture.TextInfo.ToTitleCase(match.Groups["instrument"].Value)
});
}
@ -1207,7 +1208,7 @@ namespace MediaBrowser.MediaEncoding.Probing
{
foreach (var person in Split(writer, false))
{
people.Add(new BaseItemPerson { Name = person, Type = PersonType.Writer });
people.Add(new BaseItemPerson { Name = person, Type = PersonKind.Writer });
}
}
@ -1215,7 +1216,7 @@ namespace MediaBrowser.MediaEncoding.Probing
{
foreach (var person in Split(arranger, false))
{
people.Add(new BaseItemPerson { Name = person, Type = PersonType.Arranger });
people.Add(new BaseItemPerson { Name = person, Type = PersonKind.Arranger });
}
}
@ -1223,7 +1224,7 @@ namespace MediaBrowser.MediaEncoding.Probing
{
foreach (var person in Split(engineer, false))
{
people.Add(new BaseItemPerson { Name = person, Type = PersonType.Engineer });
people.Add(new BaseItemPerson { Name = person, Type = PersonKind.Engineer });
}
}
@ -1231,7 +1232,7 @@ namespace MediaBrowser.MediaEncoding.Probing
{
foreach (var person in Split(mixer, false))
{
people.Add(new BaseItemPerson { Name = person, Type = PersonType.Mixer });
people.Add(new BaseItemPerson { Name = person, Type = PersonKind.Mixer });
}
}
@ -1239,7 +1240,7 @@ namespace MediaBrowser.MediaEncoding.Probing
{
foreach (var person in Split(remixer, false))
{
people.Add(new BaseItemPerson { Name = person, Type = PersonType.Remixer });
people.Add(new BaseItemPerson { Name = person, Type = PersonKind.Remixer });
}
}
@ -1491,7 +1492,7 @@ namespace MediaBrowser.MediaEncoding.Probing
{
video.People = people.Split(new[] { ';', '/' }, StringSplitOptions.RemoveEmptyEntries)
.Where(i => !string.IsNullOrWhiteSpace(i))
.Select(i => new BaseItemPerson { Name = i.Trim(), Type = PersonType.Actor })
.Select(i => new BaseItemPerson { Name = i.Trim(), Type = PersonKind.Actor })
.ToArray();
}

View File

@ -2,6 +2,7 @@
using System;
using System.Collections.Generic;
using System.Text.Json.Serialization;
using Jellyfin.Data.Enums;
using MediaBrowser.Model.Entities;
namespace MediaBrowser.Model.Dto
@ -33,7 +34,7 @@ namespace MediaBrowser.Model.Dto
/// Gets or sets the type.
/// </summary>
/// <value>The type.</value>
public string Type { get; set; }
public PersonKind Type { get; set; }
/// <summary>
/// Gets or sets the primary image tag.

View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Jellyfin.Data.Enums;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Audio;
using MediaBrowser.Controller.Library;
@ -163,7 +164,7 @@ namespace MediaBrowser.Providers.MediaInfo
PeopleHelper.AddPerson(people, new PersonInfo
{
Name = albumArtist,
Type = "AlbumArtist"
Type = PersonKind.AlbumArtist
});
}
@ -173,7 +174,7 @@ namespace MediaBrowser.Providers.MediaInfo
PeopleHelper.AddPerson(people, new PersonInfo
{
Name = performer,
Type = "Artist"
Type = PersonKind.Artist
});
}
@ -182,7 +183,7 @@ namespace MediaBrowser.Providers.MediaInfo
PeopleHelper.AddPerson(people, new PersonInfo
{
Name = composer,
Type = "Composer"
Type = PersonKind.Composer
});
}

View File

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Jellyfin.Data.Enums;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Audio;
@ -187,7 +188,7 @@ namespace MediaBrowser.Providers.Music
PeopleHelper.AddPerson(people, new PersonInfo
{
Name = albumArtist,
Type = "AlbumArtist"
Type = PersonKind.AlbumArtist
});
}
@ -196,7 +197,7 @@ namespace MediaBrowser.Providers.Music
PeopleHelper.AddPerson(people, new PersonInfo
{
Name = artist,
Type = "Artist"
Type = PersonKind.Artist
});
}

View File

@ -13,6 +13,7 @@ using System.Net.Http.Json;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
using Jellyfin.Data.Enums;
using Jellyfin.Extensions.Json;
using MediaBrowser.Common.Net;
using MediaBrowser.Controller.Configuration;
@ -424,7 +425,7 @@ namespace MediaBrowser.Providers.Plugins.Omdb
var person = new PersonInfo
{
Name = result.Director,
Type = PersonType.Director
Type = PersonKind.Director
};
itemResult.AddPerson(person);
@ -435,7 +436,7 @@ namespace MediaBrowser.Providers.Plugins.Omdb
var person = new PersonInfo
{
Name = result.Writer,
Type = PersonType.Writer
Type = PersonKind.Writer
};
itemResult.AddPerson(person);
@ -454,7 +455,7 @@ namespace MediaBrowser.Providers.Plugins.Omdb
var person = new PersonInfo
{
Name = actor,
Type = PersonType.Actor
Type = PersonKind.Actor
};
itemResult.AddPerson(person);

View File

@ -5,6 +5,7 @@ using System.Linq;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using Jellyfin.Data.Enums;
using Jellyfin.Extensions;
using MediaBrowser.Common.Net;
using MediaBrowser.Controller.Entities;
@ -258,7 +259,7 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.Movies
{
Name = actor.Name.Trim(),
Role = actor.Character,
Type = PersonType.Actor,
Type = PersonKind.Actor,
SortOrder = actor.Order
};
@ -278,20 +279,13 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.Movies
if (movieResult.Credits?.Crew is not null)
{
var keepTypes = new[]
{
PersonType.Director,
PersonType.Writer,
PersonType.Producer
};
foreach (var person in movieResult.Credits.Crew)
{
// Normalize this
var type = TmdbUtils.MapCrewToPersonType(person);
if (!keepTypes.Contains(type, StringComparison.OrdinalIgnoreCase) &&
!keepTypes.Contains(person.Job ?? string.Empty, StringComparison.OrdinalIgnoreCase))
if (!TmdbUtils.WantedCrewKinds.Contains(type)
&& !TmdbUtils.WantedCrewTypes.Contains(person.Job ?? string.Empty, StringComparison.OrdinalIgnoreCase))
{
continue;
}

View File

@ -5,6 +5,7 @@ using System.Linq;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using Jellyfin.Data.Enums;
using Jellyfin.Extensions;
using MediaBrowser.Common.Net;
using MediaBrowser.Controller.Entities;
@ -168,7 +169,7 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.TV
{
Name = actor.Name.Trim(),
Role = actor.Character,
Type = PersonType.Actor,
Type = PersonKind.Actor,
SortOrder = actor.Order
});
}
@ -182,7 +183,7 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.TV
{
Name = guest.Name.Trim(),
Role = guest.Character,
Type = PersonType.GuestStar,
Type = PersonKind.GuestStar,
SortOrder = guest.Order
});
}
@ -196,7 +197,7 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.TV
// Normalize this
var type = TmdbUtils.MapCrewToPersonType(person);
if (!TmdbUtils.WantedCrewTypes.Contains(type, StringComparison.OrdinalIgnoreCase)
if (!TmdbUtils.WantedCrewKinds.Contains(type)
&& !TmdbUtils.WantedCrewTypes.Contains(person.Job ?? string.Empty, StringComparison.OrdinalIgnoreCase))
{
continue;

View File

@ -5,6 +5,7 @@ using System.Linq;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using Jellyfin.Data.Enums;
using Jellyfin.Extensions;
using MediaBrowser.Common.Net;
using MediaBrowser.Controller.Entities;
@ -88,7 +89,7 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.TV
{
Name = cast[i].Name.Trim(),
Role = cast[i].Character,
Type = PersonType.Actor,
Type = PersonKind.Actor,
SortOrder = cast[i].Order
});
}
@ -101,7 +102,7 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.TV
// Normalize this
var type = TmdbUtils.MapCrewToPersonType(person);
if (!TmdbUtils.WantedCrewTypes.Contains(type, StringComparison.OrdinalIgnoreCase)
if (!TmdbUtils.WantedCrewKinds.Contains(type)
&& !TmdbUtils.WantedCrewTypes.Contains(person.Job ?? string.Empty, StringComparison.OrdinalIgnoreCase))
{
continue;

View File

@ -5,6 +5,7 @@ using System.Linq;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using Jellyfin.Data.Enums;
using Jellyfin.Extensions;
using MediaBrowser.Common.Net;
using MediaBrowser.Controller.Entities;
@ -352,7 +353,7 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.TV
{
Name = actor.Name.Trim(),
Role = actor.Character,
Type = PersonType.Actor,
Type = PersonKind.Actor,
SortOrder = actor.Order,
ImageUrl = _tmdbClientManager.GetPosterUrl(actor.ProfilePath)
};
@ -380,8 +381,8 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.TV
// Normalize this
var type = TmdbUtils.MapCrewToPersonType(person);
if (!keepTypes.Contains(type, StringComparison.OrdinalIgnoreCase)
&& !keepTypes.Contains(person.Job ?? string.Empty, StringComparison.OrdinalIgnoreCase))
if (!TmdbUtils.WantedCrewKinds.Contains(type)
&& !TmdbUtils.WantedCrewTypes.Contains(person.Job ?? string.Empty, StringComparison.OrdinalIgnoreCase))
{
continue;
}

View File

@ -2,6 +2,7 @@ using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Text.RegularExpressions;
using Jellyfin.Data.Enums;
using MediaBrowser.Model.Entities;
using TMDbLib.Objects.General;
@ -39,6 +40,16 @@ namespace MediaBrowser.Providers.Plugins.Tmdb
PersonType.Producer
};
/// <summary>
/// The crew kinds to keep.
/// </summary>
public static readonly PersonKind[] WantedCrewKinds =
{
PersonKind.Director,
PersonKind.Writer,
PersonKind.Producer
};
/// <summary>
/// Cleans the name according to TMDb requirements.
/// </summary>
@ -55,26 +66,26 @@ namespace MediaBrowser.Providers.Plugins.Tmdb
/// </summary>
/// <param name="crew">Crew member to map against the Jellyfin person types.</param>
/// <returns>The Jellyfin person type.</returns>
public static string MapCrewToPersonType(Crew crew)
public static PersonKind MapCrewToPersonType(Crew crew)
{
if (crew.Department.Equals("production", StringComparison.OrdinalIgnoreCase)
&& crew.Job.Contains("director", StringComparison.OrdinalIgnoreCase))
{
return PersonType.Director;
return PersonKind.Director;
}
if (crew.Department.Equals("production", StringComparison.OrdinalIgnoreCase)
&& crew.Job.Contains("producer", StringComparison.OrdinalIgnoreCase))
{
return PersonType.Producer;
return PersonKind.Producer;
}
if (crew.Department.Equals("writing", StringComparison.OrdinalIgnoreCase))
{
return PersonType.Writer;
return PersonKind.Writer;
}
return string.Empty;
return PersonKind.Unknown;
}
/// <summary>

View File

@ -6,6 +6,7 @@ using System.Linq;
using System.Text;
using System.Threading;
using System.Xml;
using Jellyfin.Data.Enums;
using Jellyfin.Extensions;
using MediaBrowser.Common.Configuration;
using MediaBrowser.Common.Providers;
@ -530,7 +531,7 @@ namespace MediaBrowser.XbmcMetadata.Parsers
case "director":
{
var val = reader.ReadElementContentAsString();
foreach (var p in SplitNames(val).Select(v => new PersonInfo { Name = v.Trim(), Type = PersonType.Director }))
foreach (var p in SplitNames(val).Select(v => new PersonInfo { Name = v.Trim(), Type = PersonKind.Director }))
{
if (string.IsNullOrWhiteSpace(p.Name))
{
@ -552,7 +553,7 @@ namespace MediaBrowser.XbmcMetadata.Parsers
var parts = val.Split('/').Select(i => i.Trim())
.Where(i => !string.IsNullOrEmpty(i));
foreach (var p in parts.Select(v => new PersonInfo { Name = v.Trim(), Type = PersonType.Writer }))
foreach (var p in parts.Select(v => new PersonInfo { Name = v.Trim(), Type = PersonKind.Writer }))
{
if (string.IsNullOrWhiteSpace(p.Name))
{
@ -569,7 +570,7 @@ namespace MediaBrowser.XbmcMetadata.Parsers
case "writer":
{
var val = reader.ReadElementContentAsString();
foreach (var p in SplitNames(val).Select(v => new PersonInfo { Name = v.Trim(), Type = PersonType.Writer }))
foreach (var p in SplitNames(val).Select(v => new PersonInfo { Name = v.Trim(), Type = PersonKind.Writer }))
{
if (string.IsNullOrWhiteSpace(p.Name))
{
@ -1206,7 +1207,7 @@ namespace MediaBrowser.XbmcMetadata.Parsers
private PersonInfo GetPersonFromXmlNode(XmlReader reader)
{
var name = string.Empty;
var type = PersonType.Actor; // If type is not specified assume actor
var type = PersonKind.Actor; // If type is not specified assume actor
var role = string.Empty;
int? sortOrder = null;
string? imageUrl = null;
@ -1240,21 +1241,9 @@ namespace MediaBrowser.XbmcMetadata.Parsers
case "type":
{
var val = reader.ReadElementContentAsString();
if (!string.IsNullOrWhiteSpace(val))
if (!Enum.TryParse(val, true, out type))
{
type = val switch
{
PersonType.Composer => PersonType.Composer,
PersonType.Conductor => PersonType.Conductor,
PersonType.Director => PersonType.Director,
PersonType.Lyricist => PersonType.Lyricist,
PersonType.Producer => PersonType.Producer,
PersonType.Writer => PersonType.Writer,
PersonType.GuestStar => PersonType.GuestStar,
// unknown type --> actor
_ => PersonType.Actor
};
type = PersonKind.Actor;
}
break;

View File

@ -10,6 +10,7 @@ using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using System.Xml;
using Jellyfin.Data.Enums;
using Jellyfin.Extensions;
using MediaBrowser.Common.Extensions;
using MediaBrowser.Controller.Configuration;
@ -485,7 +486,7 @@ namespace MediaBrowser.XbmcMetadata.Savers
var people = libraryManager.GetPeople(item);
var directors = people
.Where(i => IsPersonType(i, PersonType.Director))
.Where(i => i.IsType(PersonKind.Director))
.Select(i => i.Name)
.ToList();
@ -495,7 +496,7 @@ namespace MediaBrowser.XbmcMetadata.Savers
}
var writers = people
.Where(i => IsPersonType(i, PersonType.Writer))
.Where(i => i.IsType(PersonKind.Writer))
.Select(i => i.Name)
.Distinct(StringComparer.OrdinalIgnoreCase)
.ToList();
@ -913,7 +914,7 @@ namespace MediaBrowser.XbmcMetadata.Savers
{
foreach (var person in people)
{
if (IsPersonType(person, PersonType.Director) || IsPersonType(person, PersonType.Writer))
if (person.IsType(PersonKind.Director) || person.IsType(PersonKind.Writer))
{
continue;
}
@ -930,9 +931,9 @@ namespace MediaBrowser.XbmcMetadata.Savers
writer.WriteElementString("role", person.Role);
}
if (!string.IsNullOrWhiteSpace(person.Type))
if (person.Type != PersonKind.Unknown)
{
writer.WriteElementString("type", person.Type);
writer.WriteElementString("type", person.Type.ToString());
}
if (person.SortOrder.HasValue)
@ -969,10 +970,6 @@ namespace MediaBrowser.XbmcMetadata.Savers
return libraryManager.GetPathAfterNetworkSubstitution(image.Path);
}
private bool IsPersonType(PersonInfo person, string type)
=> string.Equals(person.Type, type, StringComparison.OrdinalIgnoreCase)
|| string.Equals(person.Role, type, StringComparison.OrdinalIgnoreCase);
private void AddCustomTags(string path, IReadOnlyCollection<string> xmlTagsUsed, XmlWriter writer, ILogger<BaseNfoSaver> logger)
{
var settings = new XmlReaderSettings()

View File

@ -2,6 +2,7 @@ using System;
using System.Globalization;
using System.IO;
using System.Text.Json;
using Jellyfin.Data.Enums;
using Jellyfin.Extensions.Json;
using Jellyfin.Extensions.Json.Converters;
using MediaBrowser.MediaEncoding.Probing;
@ -314,15 +315,15 @@ namespace Jellyfin.MediaEncoding.Tests.Probing
Assert.Equal(DateTime.Parse("2020-10-26T00:00Z", DateTimeFormatInfo.CurrentInfo, DateTimeStyles.AdjustToUniversal), res.PremiereDate);
Assert.Equal(22, res.People.Length);
Assert.Equal("Krysta Youngs", res.People[0].Name);
Assert.Equal(PersonType.Composer, res.People[0].Type);
Assert.Equal(PersonKind.Composer, res.People[0].Type);
Assert.Equal("Julia Ross", res.People[1].Name);
Assert.Equal(PersonType.Composer, res.People[1].Type);
Assert.Equal(PersonKind.Composer, res.People[1].Type);
Assert.Equal("Yiwoomin", res.People[2].Name);
Assert.Equal(PersonType.Composer, res.People[2].Type);
Assert.Equal(PersonKind.Composer, res.People[2].Type);
Assert.Equal("Ji-hyo Park", res.People[3].Name);
Assert.Equal(PersonType.Lyricist, res.People[3].Type);
Assert.Equal(PersonKind.Lyricist, res.People[3].Type);
Assert.Equal("Yiwoomin", res.People[4].Name);
Assert.Equal(PersonType.Actor, res.People[4].Type);
Assert.Equal(PersonKind.Actor, res.People[4].Type);
Assert.Equal("Electric Piano", res.People[4].Role);
Assert.Equal(4, res.Genres.Length);
Assert.Contains("Electronic", res.Genres);

View File

@ -1,6 +1,7 @@
using System;
using System.Linq;
using System.Threading;
using Jellyfin.Data.Enums;
using MediaBrowser.Common.Configuration;
using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.Library;
@ -79,18 +80,18 @@ namespace Jellyfin.XbmcMetadata.Tests.Parsers
Assert.Equal("1276153", item.ProviderIds[MetadataProvider.Tmdb.ToString()]);
// Credits
var writers = result.People.Where(x => x.Type == PersonType.Writer).ToArray();
var writers = result.People.Where(x => x.Type == PersonKind.Writer).ToArray();
Assert.Equal(2, writers.Length);
Assert.Contains("Bryan Fuller", writers.Select(x => x.Name));
Assert.Contains("Michael Green", writers.Select(x => x.Name));
// Direcotrs
var directors = result.People.Where(x => x.Type == PersonType.Director).ToArray();
var directors = result.People.Where(x => x.Type == PersonKind.Director).ToArray();
Assert.Single(directors);
Assert.Contains("David Slade", directors.Select(x => x.Name));
// Actors
var actors = result.People.Where(x => x.Type == PersonType.Actor).ToArray();
var actors = result.People.Where(x => x.Type == PersonKind.Actor).ToArray();
Assert.Equal(11, actors.Length);
// Only test one actor
var shadow = actors.FirstOrDefault(x => x.Role.Equals("Shadow Moon", StringComparison.Ordinal));

View File

@ -2,6 +2,7 @@ using System;
using System.Linq;
using System.Threading;
using Jellyfin.Data.Entities;
using Jellyfin.Data.Enums;
using MediaBrowser.Common.Configuration;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Movies;
@ -117,18 +118,18 @@ namespace Jellyfin.XbmcMetadata.Tests.Parsers
Assert.Equal(20, result.People.Count);
var writers = result.People.Where(x => x.Type == PersonType.Writer).ToArray();
var writers = result.People.Where(x => x.Type == PersonKind.Writer).ToArray();
Assert.Equal(3, writers.Length);
var writerNames = writers.Select(x => x.Name);
Assert.Contains("Jerry Siegel", writerNames);
Assert.Contains("Joe Shuster", writerNames);
Assert.Contains("Test", writerNames);
var directors = result.People.Where(x => x.Type == PersonType.Director).ToArray();
var directors = result.People.Where(x => x.Type == PersonKind.Director).ToArray();
Assert.Single(directors);
Assert.Equal("Zack Snyder", directors[0].Name);
var actors = result.People.Where(x => x.Type == PersonType.Actor).ToArray();
var actors = result.People.Where(x => x.Type == PersonKind.Actor).ToArray();
Assert.Equal(15, actors.Length);
// Only test one actor
@ -138,7 +139,7 @@ namespace Jellyfin.XbmcMetadata.Tests.Parsers
Assert.Equal(5, aquaman!.SortOrder);
Assert.Equal("https://m.media-amazon.com/images/M/MV5BMTI5MTU5NjM1MV5BMl5BanBnXkFtZTcwODc4MDk0Mw@@._V1_SX1024_SY1024_.jpg", aquaman!.ImageUrl);
var lyricist = result.People.FirstOrDefault(x => x.Type == PersonType.Lyricist);
var lyricist = result.People.FirstOrDefault(x => x.Type == PersonKind.Lyricist);
Assert.NotNull(lyricist);
Assert.Equal("Test Lyricist", lyricist!.Name);

View File

@ -1,6 +1,7 @@
using System;
using System.Linq;
using System.Threading;
using Jellyfin.Data.Enums;
using MediaBrowser.Common.Configuration;
using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.Library;
@ -60,7 +61,7 @@ namespace Jellyfin.XbmcMetadata.Tests.Parsers
Assert.Equal(10, result.People.Count);
Assert.True(result.People.All(x => x.Type == PersonType.Actor));
Assert.True(result.People.All(x => x.Type == PersonKind.Actor));
// Only test one actor
var nini = result.People.FirstOrDefault(x => x.Role.Equals("Nini", StringComparison.Ordinal));

View File

@ -1,6 +1,7 @@
using System;
using System.Linq;
using System.Threading;
using Jellyfin.Data.Enums;
using MediaBrowser.Common.Configuration;
using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.Library;
@ -67,7 +68,7 @@ namespace Jellyfin.XbmcMetadata.Tests.Parsers
Assert.Equal(6, result.People.Count);
Assert.True(result.People.All(x => x.Type == PersonType.Actor));
Assert.True(result.People.All(x => x.Type == PersonKind.Actor));
// Only test one actor
var sweeney = result.People.FirstOrDefault(x => x.Role.Equals("Mad Sweeney", StringComparison.Ordinal));