/// <inheritdoc />
        public async Task <IEnumerable <RemoteSearchResult> > GetSearchResults(PersonLookupInfo searchInfo, CancellationToken cancellationToken)
        {
            var personTmdbId = Convert.ToInt32(searchInfo.GetProviderId(MetadataProvider.Tmdb), CultureInfo.InvariantCulture);

            if (personTmdbId <= 0)
            {
                var personResult = await _tmdbClientManager.GetPersonAsync(personTmdbId, cancellationToken).ConfigureAwait(false);

                if (personResult != null)
                {
                    var result = new RemoteSearchResult
                    {
                        Name = personResult.Name,
                        SearchProviderName = Name,
                        Overview           = personResult.Biography
                    };

                    if (personResult.Images?.Profiles != null && personResult.Images.Profiles.Count > 0)
                    {
                        result.ImageUrl = _tmdbClientManager.GetProfileUrl(personResult.Images.Profiles[0].FilePath);
                    }

                    result.SetProviderId(MetadataProvider.Tmdb, personResult.Id.ToString(CultureInfo.InvariantCulture));
                    result.SetProviderId(MetadataProvider.Imdb, personResult.ExternalIds.ImdbId);

                    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 remoteSearchResults = new List <RemoteSearchResult>();

            for (var i = 0; i < personSearchResult.Count; i++)
            {
                var person             = personSearchResult[i];
                var remoteSearchResult = new RemoteSearchResult
                {
                    SearchProviderName = Name,
                    Name     = person.Name,
                    ImageUrl = _tmdbClientManager.GetProfileUrl(person.ProfilePath)
                };

                remoteSearchResult.SetProviderId(MetadataProvider.Tmdb, person.Id.ToString(CultureInfo.InvariantCulture));
                remoteSearchResults.Add(remoteSearchResult);
            }

            return(remoteSearchResults);
        }
Ejemplo n.º 2
0
        public async Task <IEnumerable <RemoteSearchResult> > GetSearchResults(PersonLookupInfo searchInfo, CancellationToken cancellationToken)
        {
            if (searchInfo.TryGetProviderId(MetadataProvider.Tmdb, out var personTmdbId))
            {
                var personResult = await _tmdbClientManager.GetPersonAsync(int.Parse(personTmdbId, CultureInfo.InvariantCulture), cancellationToken).ConfigureAwait(false);

                if (personResult != null)
                {
                    var result = new RemoteSearchResult
                    {
                        Name = personResult.Name,
                        SearchProviderName = Name,
                        Overview           = personResult.Biography
                    };

                    if (personResult.Images?.Profiles != null && personResult.Images.Profiles.Count > 0)
                    {
                        result.ImageUrl = _tmdbClientManager.GetProfileUrl(personResult.Images.Profiles[0].FilePath);
                    }

                    result.SetProviderId(MetadataProvider.Tmdb, personResult.Id.ToString(CultureInfo.InvariantCulture));
                    if (!string.IsNullOrEmpty(personResult.ExternalIds.ImdbId))
                    {
                        result.SetProviderId(MetadataProvider.Imdb, personResult.ExternalIds.ImdbId);
                    }

                    return(new[] { result });
                }
            }

            var personSearchResult = await _tmdbClientManager.SearchPersonAsync(searchInfo.Name, cancellationToken).ConfigureAwait(false);

            var remoteSearchResults = new List <RemoteSearchResult>();

            for (var i = 0; i < personSearchResult.Count; i++)
            {
                var person             = personSearchResult[i];
                var remoteSearchResult = new RemoteSearchResult
                {
                    SearchProviderName = Name,
                    Name     = person.Name,
                    ImageUrl = _tmdbClientManager.GetProfileUrl(person.ProfilePath)
                };

                remoteSearchResult.SetProviderId(MetadataProvider.Tmdb, person.Id.ToString(CultureInfo.InvariantCulture));
                remoteSearchResults.Add(remoteSearchResult);
            }

            return(remoteSearchResults);
        }
Ejemplo n.º 3
0
        public async Task <IEnumerable <RemoteImageInfo> > GetImages(BaseItem item, CancellationToken cancellationToken)
        {
            var person = (Person)item;

            if (!person.TryGetProviderId(MetadataProvider.Tmdb, out var personTmdbId))
            {
                return(Enumerable.Empty <RemoteImageInfo>());
            }

            var personResult = await _tmdbClientManager.GetPersonAsync(int.Parse(personTmdbId, CultureInfo.InvariantCulture), cancellationToken).ConfigureAwait(false);

            if (personResult?.Images?.Profiles == null)
            {
                return(Enumerable.Empty <RemoteImageInfo>());
            }

            var remoteImages = new RemoteImageInfo[personResult.Images.Profiles.Count];
            var language     = item.GetPreferredMetadataLanguage();

            for (var i = 0; i < personResult.Images.Profiles.Count; i++)
            {
                var image = personResult.Images.Profiles[i];
                remoteImages[i] = new RemoteImageInfo
                {
                    ProviderName = Name,
                    Type         = ImageType.Primary,
                    Width        = image.Width,
                    Height       = image.Height,
                    Language     = TmdbUtils.AdjustImageLanguage(image.Iso_639_1, language),
                    Url          = _tmdbClientManager.GetProfileUrl(image.FilePath)
                };
            }

            return(remoteImages.OrderByLanguageDescending(language));
        }
Ejemplo n.º 4
0
        public async Task <IEnumerable <RemoteImageInfo> > GetImages(BaseItem item, CancellationToken cancellationToken)
        {
            var person = (Person)item;

            if (!person.TryGetProviderId(MetadataProvider.Tmdb, out var personTmdbId))
            {
                return(Enumerable.Empty <RemoteImageInfo>());
            }

            var language     = item.GetPreferredMetadataLanguage();
            var personResult = await _tmdbClientManager.GetPersonAsync(int.Parse(personTmdbId, CultureInfo.InvariantCulture), language, cancellationToken).ConfigureAwait(false);

            if (personResult?.Images?.Profiles == null)
            {
                return(Enumerable.Empty <RemoteImageInfo>());
            }

            var profiles     = personResult.Images.Profiles;
            var remoteImages = new List <RemoteImageInfo>(profiles.Count);

            _tmdbClientManager.ConvertProfilesToRemoteImageInfo(profiles, language, remoteImages);

            return(remoteImages);
        }