consolidate people access

This commit is contained in:
Luke Pulverenti 2015-06-28 12:36:25 -04:00
parent 4ea244e4cd
commit 8afd04ae37
13 changed files with 130 additions and 107 deletions

View File

@ -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>

View File

@ -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));
}
}
}

View File

@ -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));
}
}

View File

@ -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" />

View File

@ -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;

View File

@ -488,7 +488,7 @@ namespace MediaBrowser.Dlna.ContentDirectory
private async Task<QueryResult<ServerItem>> GetItemsFromPerson(Person person, User user, int? startIndex, int? limit)
{
var items = user.RootFolder.GetRecursiveChildren(user, i => i is Movie || i is Series && i.ContainsPerson(person.Name))
var items = user.RootFolder.GetRecursiveChildren(user, i => i is Movie || i is Series && PeopleHelper.ContainsPerson(_libraryManager.GetPeople(i), person.Name))
.ToList();
var trailerResult = await _channelManager.GetAllMediaInternal(new AllChannelMediaQuery
@ -503,7 +503,7 @@ namespace MediaBrowser.Dlna.ContentDirectory
.ToList();
var trailersToAdd = trailerResult.Items
.Where(i => i.ContainsPerson(person.Name))
.Where(i => PeopleHelper.ContainsPerson(_libraryManager.GetPeople(i), person.Name))
.Where(i =>
{
// Try to filter out dupes using imdb id
@ -569,7 +569,7 @@ namespace MediaBrowser.Dlna.ContentDirectory
private bool EnablePeopleDisplay(BaseItem item)
{
if (item.People.Count > 0)
if (_libraryManager.GetPeople(item).Count > 0)
{
return item is Movie;
}

View File

@ -134,7 +134,7 @@ namespace MediaBrowser.Providers.MediaInfo
foreach (var person in data.People)
{
audio.AddPerson(new PersonInfo
PeopleHelper.AddPerson(audio.People, new PersonInfo
{
Name = person.Name,
Type = person.Type,

View File

@ -378,7 +378,7 @@ namespace MediaBrowser.Providers.MediaInfo
foreach (var person in data.People)
{
video.AddPerson(new PersonInfo
PeopleHelper.AddPerson(video.People, new PersonInfo
{
Name = person.Name,
Type = person.Type,

View File

@ -233,13 +233,19 @@ namespace MediaBrowser.Providers.Movies
//actors come from cast
if (movieData.casts != null && movieData.casts.cast != null)
{
foreach (var actor in movieData.casts.cast.OrderBy(a => a.order)) movie.AddPerson(new PersonInfo { Name = actor.name.Trim(), Role = actor.character, Type = PersonType.Actor, SortOrder = actor.order });
foreach (var actor in movieData.casts.cast.OrderBy(a => a.order))
{
PeopleHelper.AddPerson(movie.People, new PersonInfo { Name = actor.name.Trim(), Role = actor.character, Type = PersonType.Actor, SortOrder = actor.order });
}
}
//and the rest from crew
if (movieData.casts != null && movieData.casts.crew != null)
{
foreach (var person in movieData.casts.crew) movie.AddPerson(new PersonInfo { Name = person.name.Trim(), Role = person.job, Type = person.department });
foreach (var person in movieData.casts.crew)
{
PeopleHelper.AddPerson(movie.People, new PersonInfo { Name = person.name.Trim(), Role = person.job, Type = person.department });
}
}
if (movieData.keywords != null && movieData.keywords.keywords != null)

View File

@ -603,7 +603,7 @@ namespace MediaBrowser.Providers.TV
.Where(i => !string.IsNullOrWhiteSpace(i))
.Select(str => new PersonInfo { Type = personType, Name = str.Trim() }))
{
item.AddPerson(person);
PeopleHelper.AddPerson(item.People, person);
}
}
@ -631,7 +631,7 @@ namespace MediaBrowser.Providers.TV
{
if (!string.IsNullOrWhiteSpace(person.Name))
{
item.AddPerson(person);
PeopleHelper.AddPerson(item.People, person);
}
}
}

View File

@ -719,7 +719,7 @@ namespace MediaBrowser.Providers.TV
if (!string.IsNullOrWhiteSpace(personInfo.Name))
{
series.AddPerson(personInfo);
PeopleHelper.AddPerson(series.People, personInfo);
}
}

View File

@ -1237,7 +1237,6 @@ namespace MediaBrowser.Server.Implementations.Channels
item.Overview = info.Overview;
item.IndexNumber = info.IndexNumber;
item.ParentIndexNumber = info.ParentIndexNumber;
item.People = info.People;
item.PremiereDate = info.PremiereDate;
item.ProductionYear = info.ProductionYear;
item.ProviderIds = info.ProviderIds;
@ -1277,6 +1276,8 @@ namespace MediaBrowser.Server.Implementations.Channels
{
await _libraryManager.CreateItem(item, cancellationToken).ConfigureAwait(false);
_libraryManager.RegisterItem(item);
await _libraryManager.UpdatePeople(item, info.People ?? new List<PersonInfo>()).ConfigureAwait(false);
}
return item;

View File

@ -573,7 +573,7 @@ namespace MediaBrowser.XbmcMetadata.Parsers
{
continue;
}
item.AddPerson(p);
PeopleHelper.AddPerson(item.People, p);
}
break;
}
@ -592,7 +592,7 @@ namespace MediaBrowser.XbmcMetadata.Parsers
{
continue;
}
item.AddPerson(p);
PeopleHelper.AddPerson(item.People, p);
}
}
break;
@ -606,7 +606,7 @@ namespace MediaBrowser.XbmcMetadata.Parsers
{
continue;
}
item.AddPerson(p);
PeopleHelper.AddPerson(item.People, p);
}
break;
}
@ -617,7 +617,7 @@ namespace MediaBrowser.XbmcMetadata.Parsers
{
var person = GetPersonFromXmlNode(subtree);
item.AddPerson(person);
PeopleHelper.AddPerson(item.People, person);
}
break;
}