Merge pull request #5870 from cvium/fix-tmdbpersonprovider

pull/5885/head
Bond-009 4 years ago committed by GitHub
commit 6b103f7ab2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -49,23 +49,25 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.People
public async Task<IEnumerable<RemoteImageInfo>> GetImages(BaseItem item, CancellationToken cancellationToken) public async Task<IEnumerable<RemoteImageInfo>> GetImages(BaseItem item, CancellationToken cancellationToken)
{ {
var person = (Person)item; var person = (Person)item;
var personTmdbId = Convert.ToInt32(person.GetProviderId(MetadataProvider.Tmdb), CultureInfo.InvariantCulture);
if (personTmdbId > 0) if (!person.TryGetProviderId(MetadataProvider.Tmdb, out var personTmdbId))
{ {
var personResult = await _tmdbClientManager.GetPersonAsync(personTmdbId, cancellationToken).ConfigureAwait(false); return Enumerable.Empty<RemoteImageInfo>();
}
var personResult = await _tmdbClientManager.GetPersonAsync(int.Parse(personTmdbId, CultureInfo.InvariantCulture), cancellationToken).ConfigureAwait(false);
if (personResult?.Images?.Profiles == null) if (personResult?.Images?.Profiles == null)
{ {
return Enumerable.Empty<RemoteImageInfo>(); return Enumerable.Empty<RemoteImageInfo>();
} }
var remoteImages = new List<RemoteImageInfo>(); var remoteImages = new RemoteImageInfo[personResult.Images.Profiles.Count];
var language = item.GetPreferredMetadataLanguage(); var language = item.GetPreferredMetadataLanguage();
for (var i = 0; i < personResult.Images.Profiles.Count; i++) for (var i = 0; i < personResult.Images.Profiles.Count; i++)
{ {
var image = personResult.Images.Profiles[i]; var image = personResult.Images.Profiles[i];
remoteImages.Add(new RemoteImageInfo remoteImages[i] = new RemoteImageInfo
{ {
ProviderName = Name, ProviderName = Name,
Type = ImageType.Primary, Type = ImageType.Primary,
@ -73,15 +75,12 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.People
Height = image.Height, Height = image.Height,
Language = TmdbUtils.AdjustImageLanguage(image.Iso_639_1, language), Language = TmdbUtils.AdjustImageLanguage(image.Iso_639_1, language),
Url = _tmdbClientManager.GetProfileUrl(image.FilePath) Url = _tmdbClientManager.GetProfileUrl(image.FilePath)
}); };
} }
return remoteImages.OrderByLanguageDescending(language); return remoteImages.OrderByLanguageDescending(language);
} }
return Enumerable.Empty<RemoteImageInfo>();
}
public Task<HttpResponseMessage> GetImageResponse(string url, CancellationToken cancellationToken) public Task<HttpResponseMessage> GetImageResponse(string url, CancellationToken cancellationToken)
{ {
return _httpClientFactory.CreateClient(NamedClient.Default).GetAsync(url, cancellationToken); return _httpClientFactory.CreateClient(NamedClient.Default).GetAsync(url, cancellationToken);

@ -30,11 +30,9 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.People
public async Task<IEnumerable<RemoteSearchResult>> GetSearchResults(PersonLookupInfo searchInfo, CancellationToken cancellationToken) public async Task<IEnumerable<RemoteSearchResult>> GetSearchResults(PersonLookupInfo searchInfo, CancellationToken cancellationToken)
{ {
var personTmdbId = Convert.ToInt32(searchInfo.GetProviderId(MetadataProvider.Tmdb), CultureInfo.InvariantCulture); if (searchInfo.TryGetProviderId(MetadataProvider.Tmdb, out var personTmdbId))
if (personTmdbId <= 0)
{ {
var personResult = await _tmdbClientManager.GetPersonAsync(personTmdbId, cancellationToken).ConfigureAwait(false); var personResult = await _tmdbClientManager.GetPersonAsync(int.Parse(personTmdbId, CultureInfo.InvariantCulture), cancellationToken).ConfigureAwait(false);
if (personResult != null) if (personResult != null)
{ {
@ -51,19 +49,15 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.People
} }
result.SetProviderId(MetadataProvider.Tmdb, personResult.Id.ToString(CultureInfo.InvariantCulture)); result.SetProviderId(MetadataProvider.Tmdb, personResult.Id.ToString(CultureInfo.InvariantCulture));
if (!string.IsNullOrEmpty(personResult.ExternalIds.ImdbId))
{
result.SetProviderId(MetadataProvider.Imdb, personResult.ExternalIds.ImdbId); result.SetProviderId(MetadataProvider.Imdb, personResult.ExternalIds.ImdbId);
}
return new[] { result }; return new[] { result };
} }
} }
// TODO why? Because of the old rate limit?
if (searchInfo.IsAutomated)
{
// Don't hammer moviedb searching by name
return Enumerable.Empty<RemoteSearchResult>();
}
var personSearchResult = await _tmdbClientManager.SearchPersonAsync(searchInfo.Name, cancellationToken).ConfigureAwait(false); var personSearchResult = await _tmdbClientManager.SearchPersonAsync(searchInfo.Name, cancellationToken).ConfigureAwait(false);
var remoteSearchResults = new List<RemoteSearchResult>(); var remoteSearchResults = new List<RemoteSearchResult>();

Loading…
Cancel
Save