From 07d8649f975db04a166cb29ead04e89a38063639 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sun, 14 Apr 2013 11:03:12 -0400 Subject: [PATCH] avoid guest star/actor dupes --- MediaBrowser.Controller/Entities/BaseItem.cs | 35 ++++++++++++++++---- 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/MediaBrowser.Controller/Entities/BaseItem.cs b/MediaBrowser.Controller/Entities/BaseItem.cs index a311cca9e..295b9b27d 100644 --- a/MediaBrowser.Controller/Entities/BaseItem.cs +++ b/MediaBrowser.Controller/Entities/BaseItem.cs @@ -957,7 +957,7 @@ namespace MediaBrowser.Controller.Entities { if (person == null) { - throw new ArgumentNullException(); + throw new ArgumentNullException("person"); } if (string.IsNullOrWhiteSpace(person.Name)) @@ -967,14 +967,37 @@ namespace MediaBrowser.Controller.Entities if (People == null) { - People = new List(); + People = new List { person }; + return; } - // Check for dupes based on the combination of Name and Type - - if (!People.Any(p => p.Name.Equals(person.Name, StringComparison.OrdinalIgnoreCase) && p.Type.Equals(person.Type, StringComparison.OrdinalIgnoreCase))) + // 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)) { - People.Add(person); + var existing = People.FirstOrDefault(p => p.Name.Equals(person.Name, StringComparison.OrdinalIgnoreCase) && p.Type.Equals(PersonType.Actor, StringComparison.OrdinalIgnoreCase)); + + if (existing != null) + { + existing.Type = PersonType.GuestStar; + return; + } + } + + if (string.Equals(person.Type, PersonType.Actor, StringComparison.OrdinalIgnoreCase)) + { + // Only add actors if there isn't an existing one of type Actor or GuestStar + if (!People.Any(p => p.Name.Equals(person.Name, StringComparison.OrdinalIgnoreCase) && (p.Type.Equals(PersonType.Actor, StringComparison.OrdinalIgnoreCase) || p.Type.Equals(PersonType.GuestStar, StringComparison.OrdinalIgnoreCase)))) + { + People.Add(person); + } + } + else + { + // Check for dupes based on the combination of Name and Type + if (!People.Any(p => p.Name.Equals(person.Name, StringComparison.OrdinalIgnoreCase) && p.Type.Equals(person.Type, StringComparison.OrdinalIgnoreCase))) + { + People.Add(person); + } } }