< Summary - Jellyfin

Information
Class: MediaBrowser.Controller.Entities.PeopleHelper
Assembly: MediaBrowser.Controller
File(s): /srv/git/jellyfin/MediaBrowser.Controller/Entities/PeopleHelper.cs
Line coverage
45%
Covered lines: 16
Uncovered lines: 19
Coverable lines: 35
Total lines: 98
Line coverage: 45.7%
Branch coverage
35%
Covered branches: 10
Total branches: 28
Branch coverage: 35.7%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
AddPerson(...)45.45%71.22253.33%
MergeExisting(...)0%4260%

File(s)

/srv/git/jellyfin/MediaBrowser.Controller/Entities/PeopleHelper.cs

#LineLine coverage
 1#pragma warning disable CS1591
 2
 3using System;
 4using System.Collections.Generic;
 5using System.Linq;
 6using Jellyfin.Data.Enums;
 7using MediaBrowser.Model.Entities;
 8
 9namespace MediaBrowser.Controller.Entities
 10{
 11    public static class PeopleHelper
 12    {
 13        public static void AddPerson(List<PersonInfo> people, PersonInfo person)
 14        {
 6315            ArgumentNullException.ThrowIfNull(person);
 6316            ArgumentException.ThrowIfNullOrEmpty(person.Name);
 17
 18            // Normalize
 6319            if (string.Equals(person.Role, PersonType.GuestStar, StringComparison.OrdinalIgnoreCase))
 20            {
 021                person.Type = PersonKind.GuestStar;
 22            }
 6323            else if (string.Equals(person.Role, PersonType.Director, StringComparison.OrdinalIgnoreCase))
 24            {
 025                person.Type = PersonKind.Director;
 26            }
 6327            else if (string.Equals(person.Role, PersonType.Producer, StringComparison.OrdinalIgnoreCase))
 28            {
 029                person.Type = PersonKind.Producer;
 30            }
 6331            else if (string.Equals(person.Role, PersonType.Writer, StringComparison.OrdinalIgnoreCase))
 32            {
 033                person.Type = PersonKind.Writer;
 34            }
 35
 36            // If the type is GuestStar and there's already an Actor entry, then update it to avoid dupes
 6337            if (person.Type == PersonKind.GuestStar)
 38            {
 039                var existing = people.FirstOrDefault(p => p.Name.Equals(person.Name, StringComparison.OrdinalIgnoreCase)
 40
 041                if (existing is not null)
 42                {
 043                    existing.Type = PersonKind.GuestStar;
 044                    MergeExisting(existing, person);
 045                    return;
 46                }
 47            }
 48
 6349            if (person.Type == PersonKind.Actor)
 50            {
 51                // If the actor already exists without a role and we have one, fill it in
 5452                var existing = people.FirstOrDefault(p => p.Name.Equals(person.Name, StringComparison.OrdinalIgnoreCase)
 5453                if (existing is null)
 54                {
 55                    // Wasn't there - add it
 5456                    people.Add(person);
 57                }
 58                else
 59                {
 60                    // Was there, if no role and we have one - fill it in
 061                    if (string.IsNullOrEmpty(existing.Role) && !string.IsNullOrEmpty(person.Role))
 62                    {
 063                        existing.Role = person.Role;
 64                    }
 65
 066                    MergeExisting(existing, person);
 67                }
 68            }
 69            else
 70            {
 971                var existing = people.FirstOrDefault(p =>
 972                    string.Equals(p.Name, person.Name, StringComparison.OrdinalIgnoreCase)
 973                    && p.Type == person.Type);
 74
 75                // Check for dupes based on the combination of Name and Type
 976                if (existing is null)
 77                {
 978                    people.Add(person);
 79                }
 80                else
 81                {
 082                    MergeExisting(existing, person);
 83                }
 84            }
 085        }
 86
 87        private static void MergeExisting(PersonInfo existing, PersonInfo person)
 88        {
 089            existing.SortOrder = person.SortOrder ?? existing.SortOrder;
 090            existing.ImageUrl = person.ImageUrl ?? existing.ImageUrl;
 91
 092            foreach (var id in person.ProviderIds)
 93            {
 094                existing.SetProviderId(id.Key, id.Value);
 95            }
 096        }
 97    }
 98}