Add Person to TypedBaseItems if it's new

This commit is contained in:
cvium 2021-04-18 12:34:33 +02:00
parent 990e4e8e58
commit 351b987982

View File

@ -223,13 +223,13 @@ namespace MediaBrowser.Providers.Manager
var baseItem = result.Item; var baseItem = result.Item;
LibraryManager.UpdatePeople(baseItem, result.People); LibraryManager.UpdatePeople(baseItem, result.People);
await SavePeopleMetadataAsync(result.People, libraryOptions, cancellationToken).ConfigureAwait(false); await SavePeopleMetadataAsync(result.People, cancellationToken).ConfigureAwait(false);
} }
await result.Item.UpdateToRepositoryAsync(reason, cancellationToken).ConfigureAwait(false); await result.Item.UpdateToRepositoryAsync(reason, cancellationToken).ConfigureAwait(false);
} }
private async Task SavePeopleMetadataAsync(List<PersonInfo> people, LibraryOptions libraryOptions, CancellationToken cancellationToken) private async Task SavePeopleMetadataAsync(IEnumerable<PersonInfo> people, CancellationToken cancellationToken)
{ {
var personsToSave = new List<BaseItem>(); var personsToSave = new List<BaseItem>();
@ -237,39 +237,44 @@ namespace MediaBrowser.Providers.Manager
{ {
cancellationToken.ThrowIfCancellationRequested(); cancellationToken.ThrowIfCancellationRequested();
if (person.ProviderIds.Count > 0 || !string.IsNullOrWhiteSpace(person.ImageUrl)) var itemUpdateType = ItemUpdateType.MetadataDownload;
var saveEntity = false;
var personEntity = LibraryManager.GetPerson(person.Name);
// if PresentationUniqueKey is empty it's likely a new item.
if (string.IsNullOrEmpty(personEntity.PresentationUniqueKey))
{ {
var itemUpdateType = ItemUpdateType.MetadataDownload; personEntity.PresentationUniqueKey = personEntity.CreatePresentationUniqueKey();
var saveEntity = false; saveEntity = true;
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)) foreach (var id in person.ProviderIds)
{
if (!string.Equals(personEntity.GetProviderId(id.Key), id.Value, StringComparison.OrdinalIgnoreCase))
{ {
personEntity.SetImage( personEntity.SetProviderId(id.Key, id.Value);
new ItemImageInfo
{
Path = person.ImageUrl,
Type = ImageType.Primary
},
0);
saveEntity = true; saveEntity = true;
itemUpdateType = ItemUpdateType.ImageUpdate;
} }
}
if (saveEntity) if (!string.IsNullOrWhiteSpace(person.ImageUrl) && !personEntity.HasImage(ImageType.Primary))
{ {
personsToSave.Add(personEntity); personEntity.SetImage(
await LibraryManager.RunMetadataSavers(personEntity, itemUpdateType).ConfigureAwait(false); new ItemImageInfo
} {
Path = person.ImageUrl,
Type = ImageType.Primary
},
0);
saveEntity = true;
itemUpdateType = ItemUpdateType.ImageUpdate;
}
if (saveEntity)
{
personsToSave.Add(personEntity);
await LibraryManager.RunMetadataSavers(personEntity, itemUpdateType).ConfigureAwait(false);
} }
} }