diff options
| author | Luke Pulverenti <luke.pulverenti@gmail.com> | 2015-06-28 12:36:25 -0400 |
|---|---|---|
| committer | Luke Pulverenti <luke.pulverenti@gmail.com> | 2015-06-28 12:36:25 -0400 |
| commit | 8afd04ae376ddafb981173b7715cfcf7e4b274e7 (patch) | |
| tree | d735d68851e039c4b479a85987e8e19e24e9a6c6 /MediaBrowser.Controller | |
| parent | 4ea244e4cdc3c9857a31cba33ee038b9fba5dc82 (diff) | |
consolidate people access
Diffstat (limited to 'MediaBrowser.Controller')
| -rw-r--r-- | MediaBrowser.Controller/Entities/BaseItem.cs | 87 | ||||
| -rw-r--r-- | MediaBrowser.Controller/Entities/PeopleHelper.cs | 100 | ||||
| -rw-r--r-- | MediaBrowser.Controller/Entities/Person.cs | 2 | ||||
| -rw-r--r-- | MediaBrowser.Controller/MediaBrowser.Controller.csproj | 1 | ||||
| -rw-r--r-- | MediaBrowser.Controller/Providers/BaseItemXmlParser.cs | 10 |
5 files changed, 108 insertions, 92 deletions
diff --git a/MediaBrowser.Controller/Entities/BaseItem.cs b/MediaBrowser.Controller/Entities/BaseItem.cs index 014b3ae6a..6e8c9ae54 100644 --- a/MediaBrowser.Controller/Entities/BaseItem.cs +++ b/MediaBrowser.Controller/Entities/BaseItem.cs @@ -413,15 +413,6 @@ namespace MediaBrowser.Controller.Entities } } - public bool ContainsPerson(string name) - { - if (string.IsNullOrWhiteSpace(name)) - { - throw new ArgumentNullException("name"); - } - return People.Any(i => string.Equals(i.Name, name, StringComparison.OrdinalIgnoreCase)); - } - public string GetInternalMetadataPath() { var basePath = ConfigurationManager.ApplicationPaths.InternalMetadataPath; @@ -1248,83 +1239,7 @@ namespace MediaBrowser.Controller.Entities /// <exception cref="System.ArgumentNullException"></exception> public void AddPerson(PersonInfo person) { - if (person == null) - { - throw new ArgumentNullException("person"); - } - - if (string.IsNullOrWhiteSpace(person.Name)) - { - throw new ArgumentNullException(); - } - - // Normalize - if (string.Equals(person.Role, PersonType.GuestStar, StringComparison.OrdinalIgnoreCase)) - { - person.Type = PersonType.GuestStar; - } - else if (string.Equals(person.Role, PersonType.Director, StringComparison.OrdinalIgnoreCase)) - { - person.Type = PersonType.Director; - } - else if (string.Equals(person.Role, PersonType.Producer, StringComparison.OrdinalIgnoreCase)) - { - person.Type = PersonType.Producer; - } - else if (string.Equals(person.Role, PersonType.Writer, StringComparison.OrdinalIgnoreCase)) - { - person.Type = PersonType.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)) - { - 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; - existing.SortOrder = person.SortOrder ?? existing.SortOrder; - return; - } - } - - if (string.Equals(person.Type, PersonType.Actor, StringComparison.OrdinalIgnoreCase)) - { - // 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))); - if (existing == null) - { - // Wasn't there - add it - People.Add(person); - } - else - { - // Was there, if no role and we have one - fill it in - if (string.IsNullOrWhiteSpace(existing.Role) && !string.IsNullOrWhiteSpace(person.Role)) - { - existing.Role = person.Role; - } - - existing.SortOrder = person.SortOrder ?? existing.SortOrder; - } - } - else - { - var existing = People.FirstOrDefault(p => - string.Equals(p.Name, person.Name, StringComparison.OrdinalIgnoreCase) && - string.Equals(p.Type, person.Type, StringComparison.OrdinalIgnoreCase)); - - // Check for dupes based on the combination of Name and Type - if (existing == null) - { - People.Add(person); - } - else - { - existing.SortOrder = person.SortOrder ?? existing.SortOrder; - } - } + PeopleHelper.AddPerson(People, person); } /// <summary> diff --git a/MediaBrowser.Controller/Entities/PeopleHelper.cs b/MediaBrowser.Controller/Entities/PeopleHelper.cs new file mode 100644 index 000000000..3468ca2d5 --- /dev/null +++ b/MediaBrowser.Controller/Entities/PeopleHelper.cs @@ -0,0 +1,100 @@ +using MediaBrowser.Model.Entities; +using System; +using System.Collections.Generic; +using System.Linq; + +namespace MediaBrowser.Controller.Entities +{ + public static class PeopleHelper + { + public static void AddPerson(List<PersonInfo> people, PersonInfo person) + { + if (person == null) + { + throw new ArgumentNullException("person"); + } + + if (string.IsNullOrWhiteSpace(person.Name)) + { + throw new ArgumentNullException(); + } + + // Normalize + if (string.Equals(person.Role, PersonType.GuestStar, StringComparison.OrdinalIgnoreCase)) + { + person.Type = PersonType.GuestStar; + } + else if (string.Equals(person.Role, PersonType.Director, StringComparison.OrdinalIgnoreCase)) + { + person.Type = PersonType.Director; + } + else if (string.Equals(person.Role, PersonType.Producer, StringComparison.OrdinalIgnoreCase)) + { + person.Type = PersonType.Producer; + } + else if (string.Equals(person.Role, PersonType.Writer, StringComparison.OrdinalIgnoreCase)) + { + person.Type = PersonType.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)) + { + 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; + existing.SortOrder = person.SortOrder ?? existing.SortOrder; + return; + } + } + + if (string.Equals(person.Type, PersonType.Actor, StringComparison.OrdinalIgnoreCase)) + { + // 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))); + if (existing == null) + { + // Wasn't there - add it + people.Add(person); + } + else + { + // Was there, if no role and we have one - fill it in + if (string.IsNullOrWhiteSpace(existing.Role) && !string.IsNullOrWhiteSpace(person.Role)) + { + existing.Role = person.Role; + } + + existing.SortOrder = person.SortOrder ?? existing.SortOrder; + } + } + else + { + var existing = people.FirstOrDefault(p => + string.Equals(p.Name, person.Name, StringComparison.OrdinalIgnoreCase) && + string.Equals(p.Type, person.Type, StringComparison.OrdinalIgnoreCase)); + + // Check for dupes based on the combination of Name and Type + if (existing == null) + { + people.Add(person); + } + else + { + existing.SortOrder = person.SortOrder ?? existing.SortOrder; + } + } + } + + public static bool ContainsPerson(List<PersonInfo> people, string name) + { + if (string.IsNullOrWhiteSpace(name)) + { + throw new ArgumentNullException("name"); + } + return people.Any(i => string.Equals(i.Name, name, StringComparison.OrdinalIgnoreCase)); + } + } +} diff --git a/MediaBrowser.Controller/Entities/Person.cs b/MediaBrowser.Controller/Entities/Person.cs index ef24d4347..bbd112de0 100644 --- a/MediaBrowser.Controller/Entities/Person.cs +++ b/MediaBrowser.Controller/Entities/Person.cs @@ -76,7 +76,7 @@ namespace MediaBrowser.Controller.Entities public Func<BaseItem, bool> GetItemFilter() { - return i => i.People.Any(p => string.Equals(p.Name, Name, StringComparison.OrdinalIgnoreCase)); + return i => LibraryManager.GetPeople(i).Any(p => string.Equals(p.Name, Name, StringComparison.OrdinalIgnoreCase)); } } diff --git a/MediaBrowser.Controller/MediaBrowser.Controller.csproj b/MediaBrowser.Controller/MediaBrowser.Controller.csproj index bf86c049f..62578e675 100644 --- a/MediaBrowser.Controller/MediaBrowser.Controller.csproj +++ b/MediaBrowser.Controller/MediaBrowser.Controller.csproj @@ -173,6 +173,7 @@ <Compile Include="Entities\LinkedChild.cs" /> <Compile Include="Entities\MusicVideo.cs" /> <Compile Include="Entities\IHasAwards.cs" /> + <Compile Include="Entities\PeopleHelper.cs" /> <Compile Include="Entities\Photo.cs" /> <Compile Include="Entities\PhotoAlbum.cs" /> <Compile Include="Entities\Share.cs" /> diff --git a/MediaBrowser.Controller/Providers/BaseItemXmlParser.cs b/MediaBrowser.Controller/Providers/BaseItemXmlParser.cs index a8a3e88ab..2ed12973b 100644 --- a/MediaBrowser.Controller/Providers/BaseItemXmlParser.cs +++ b/MediaBrowser.Controller/Providers/BaseItemXmlParser.cs @@ -490,7 +490,7 @@ namespace MediaBrowser.Controller.Providers { continue; } - item.AddPerson(p); + PeopleHelper.AddPerson(item.People, p); } break; } @@ -502,7 +502,7 @@ namespace MediaBrowser.Controller.Providers { continue; } - item.AddPerson(p); + PeopleHelper.AddPerson(item.People, p); } break; } @@ -527,7 +527,7 @@ namespace MediaBrowser.Controller.Providers { continue; } - item.AddPerson(p); + PeopleHelper.AddPerson(item.People, p); } } break; @@ -541,7 +541,7 @@ namespace MediaBrowser.Controller.Providers { continue; } - item.AddPerson(p); + PeopleHelper.AddPerson(item.People, p); } break; } @@ -1154,7 +1154,7 @@ namespace MediaBrowser.Controller.Providers { continue; } - item.AddPerson(person); + PeopleHelper.AddPerson(item.People, person); } } break; |
