get people info during media refresh

This commit is contained in:
Luke Pulverenti 2016-01-21 13:50:43 -05:00
parent dc1c69ea7b
commit 1c8b97866b
5 changed files with 126 additions and 8 deletions

View File

@ -45,7 +45,7 @@ namespace MediaBrowser.Controller.Entities
if (existing != null)
{
existing.Type = PersonType.GuestStar;
existing.SortOrder = person.SortOrder ?? existing.SortOrder;
MergeExisting(existing, person);
return;
}
}
@ -67,7 +67,7 @@ namespace MediaBrowser.Controller.Entities
existing.Role = person.Role;
}
existing.SortOrder = person.SortOrder ?? existing.SortOrder;
MergeExisting(existing, person);
}
}
else
@ -83,11 +83,22 @@ namespace MediaBrowser.Controller.Entities
}
else
{
existing.SortOrder = person.SortOrder ?? existing.SortOrder;
MergeExisting(existing, person);
}
}
}
private static void MergeExisting(PersonInfo existing, PersonInfo person)
{
existing.SortOrder = person.SortOrder ?? existing.SortOrder;
existing.ImageUrl = person.ImageUrl ?? existing.ImageUrl;
foreach (var id in person.ProviderIds)
{
existing.SetProviderId(id.Key, id.Value);
}
}
public static bool ContainsPerson(List<PersonInfo> people, string name)
{
if (string.IsNullOrWhiteSpace(name))

View File

@ -3,6 +3,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using MediaBrowser.Model.Entities;
namespace MediaBrowser.Controller.Entities
{
@ -115,8 +116,13 @@ namespace MediaBrowser.Controller.Entities
/// <summary>
/// This is the small Person stub that is attached to BaseItems
/// </summary>
public class PersonInfo
public class PersonInfo : IHasProviderIds
{
public PersonInfo()
{
ProviderIds = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
}
public Guid ItemId { get; set; }
/// <summary>
@ -141,6 +147,10 @@ namespace MediaBrowser.Controller.Entities
/// <value>The sort order.</value>
public int? SortOrder { get; set; }
public string ImageUrl { get; set; }
public Dictionary<string, string> ProviderIds { get; set; }
/// <summary>
/// Returns a <see cref="System.String" /> that represents this instance.
/// </summary>

View File

@ -254,10 +254,53 @@ namespace MediaBrowser.Providers.Manager
if (result.Item.SupportsPeople && result.People != null)
{
await LibraryManager.UpdatePeople(result.Item as BaseItem, result.People.ToList());
await SavePeopleMetadata(result.People, cancellationToken).ConfigureAwait(false);
}
await result.Item.UpdateToRepository(reason, cancellationToken).ConfigureAwait(false);
}
private async Task SavePeopleMetadata(List<PersonInfo> people, CancellationToken cancellationToken)
{
foreach (var person in people)
{
cancellationToken.ThrowIfCancellationRequested();
if (person.ProviderIds.Any() || !string.IsNullOrWhiteSpace(person.ImageUrl))
{
var updateType = ItemUpdateType.MetadataDownload;
var saveEntity = false;
var personEntity = LibraryManager.GetPerson(person.Name);
foreach (var id in person.ProviderIds)
{
if (!string.Equals(personEntity.GetProviderId(id.Key), id.Value, StringComparison.OrdinalIgnoreCase))
{
personEntity.SetProviderId(id.Key, id.Value);
saveEntity = true;
}
}
if (!string.IsNullOrWhiteSpace(person.ImageUrl) && !personEntity.HasImage(ImageType.Primary))
{
personEntity.SetImage(new ItemImageInfo
{
Path = person.ImageUrl,
Type = ImageType.Primary,
IsPlaceholder = true
}, 0);
saveEntity = true;
updateType = updateType | ItemUpdateType.ImageUpdate;
}
if (saveEntity)
{
await personEntity.UpdateToRepository(updateType, cancellationToken).ConfigureAwait(false);
}
}
}
}
private readonly Task _cachedTask = Task.FromResult(true);
protected virtual Task AfterMetadataRefresh(TItemType item, MetadataRefreshOptions refreshOptions, CancellationToken cancellationToken)
{

View File

@ -104,7 +104,9 @@ namespace MediaBrowser.Providers.Movies
dataFilePath = dataFilePath ?? MovieDbProvider.Current.GetDataFilePath(tmdbId, language);
movieInfo = movieInfo ?? _jsonSerializer.DeserializeFromFile<MovieDbProvider.CompleteMovieData>(dataFilePath);
ProcessMainInfo(item, preferredCountryCode, movieInfo);
var settings = await MovieDbProvider.Current.GetTmdbSettings(cancellationToken).ConfigureAwait(false);
ProcessMainInfo(item, settings, preferredCountryCode, movieInfo);
item.HasMetadata = true;
}
@ -115,9 +117,10 @@ namespace MediaBrowser.Providers.Movies
/// Processes the main info.
/// </summary>
/// <param name="resultItem">The result item.</param>
/// <param name="settings">The settings.</param>
/// <param name="preferredCountryCode">The preferred country code.</param>
/// <param name="movieData">The movie data.</param>
private void ProcessMainInfo(MetadataResult<T> resultItem, string preferredCountryCode, MovieDbProvider.CompleteMovieData movieData)
private void ProcessMainInfo(MetadataResult<T> resultItem, TmdbSettingsResult settings, string preferredCountryCode, MovieDbProvider.CompleteMovieData movieData)
{
var movie = resultItem.Item;
@ -247,6 +250,7 @@ namespace MediaBrowser.Providers.Movies
}
resultItem.ResetPeople();
var tmdbImageUrl = settings.images.base_url + "original";
//Actors, Directors, Writers - all in People
//actors come from cast
@ -254,7 +258,25 @@ namespace MediaBrowser.Providers.Movies
{
foreach (var actor in movieData.casts.cast.OrderBy(a => a.order))
{
resultItem.AddPerson(new PersonInfo { Name = actor.name.Trim(), Role = actor.character, Type = PersonType.Actor, SortOrder = actor.order });
var personInfo = new PersonInfo
{
Name = actor.name.Trim(),
Role = actor.character,
Type = PersonType.Actor,
SortOrder = actor.order
};
if (!string.IsNullOrWhiteSpace(actor.profile_path))
{
personInfo.ImageUrl = tmdbImageUrl + actor.profile_path;
}
if (actor.id > 0)
{
personInfo.SetProviderId(MetadataProviders.Tmdb, actor.id.ToString(CultureInfo.InvariantCulture));
}
resultItem.AddPerson(personInfo);
}
}
@ -270,7 +292,24 @@ namespace MediaBrowser.Providers.Movies
type = PersonType.Writer;
}
resultItem.AddPerson(new PersonInfo { Name = person.name.Trim(), Role = person.job, Type = type });
var personInfo = new PersonInfo
{
Name = person.name.Trim(),
Role = person.job,
Type = type
};
if (!string.IsNullOrWhiteSpace(person.profile_path))
{
personInfo.ImageUrl = tmdbImageUrl + person.profile_path;
}
if (person.id > 0)
{
personInfo.SetProviderId(MetadataProviders.Tmdb, person.id.ToString(CultureInfo.InvariantCulture));
}
resultItem.AddPerson(personInfo);
}
}

View File

@ -826,6 +826,21 @@ namespace MediaBrowser.Providers.TV
break;
}
case "id":
{
break;
}
case "Image":
{
var url = (reader.ReadElementContentAsString() ?? string.Empty).Trim();
if (!string.IsNullOrWhiteSpace(url))
{
personInfo.ImageUrl = TVUtils.BannerUrl + url;
}
break;
}
case "SortOrder":
{
var val = reader.ReadElementContentAsString();