Ejemplo n.º 1
0
        public async Task <IEnumerable <RemoteImageInfo> > GetImages(BaseItem item, CancellationToken cancellationToken)
        {
            var tmdbId = item.GetProviderId(MetadataProvider.Tmdb);

            if (string.IsNullOrEmpty(tmdbId))
            {
                return(Enumerable.Empty <RemoteImageInfo>());
            }

            var language = item.GetPreferredMetadataLanguage();

            // TODO use image languages if All Languages isn't toggled, but there's currently no way to get that value in here
            var series = await _tmdbClientManager
                         .GetSeriesAsync(Convert.ToInt32(tmdbId, CultureInfo.InvariantCulture), null, null, cancellationToken)
                         .ConfigureAwait(false);

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

            var posters      = series.Images.Posters;
            var backdrops    = series.Images.Backdrops;
            var logos        = series.Images.Logos;
            var remoteImages = new List <RemoteImageInfo>(posters.Count + backdrops.Count + logos.Count);

            _tmdbClientManager.ConvertPostersToRemoteImageInfo(posters, language, remoteImages);
            _tmdbClientManager.ConvertBackdropsToRemoteImageInfo(backdrops, language, remoteImages);
            _tmdbClientManager.ConvertLogosToRemoteImageInfo(logos, language, remoteImages);

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

            var movieTmdbId = Convert.ToInt32(item.GetProviderId(MetadataProvider.Tmdb), CultureInfo.InvariantCulture);

            if (movieTmdbId <= 0)
            {
                var movieImdbId = item.GetProviderId(MetadataProvider.Imdb);
                if (string.IsNullOrEmpty(movieImdbId))
                {
                    return(Enumerable.Empty <RemoteImageInfo>());
                }

                var movieResult = await _tmdbClientManager.FindByExternalIdAsync(movieImdbId, FindExternalSource.Imdb, language, cancellationToken).ConfigureAwait(false);

                if (movieResult?.MovieResults != null && movieResult.MovieResults.Count > 0)
                {
                    movieTmdbId = movieResult.MovieResults[0].Id;
                }
            }

            if (movieTmdbId <= 0)
            {
                return(Enumerable.Empty <RemoteImageInfo>());
            }

            // TODO use image languages if All Languages isn't toggled, but there's currently no way to get that value in here
            var movie = await _tmdbClientManager
                        .GetMovieAsync(movieTmdbId, null, null, cancellationToken)
                        .ConfigureAwait(false);

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

            var posters      = movie.Images.Posters;
            var backdrops    = movie.Images.Backdrops;
            var logos        = movie.Images.Logos;
            var remoteImages = new List <RemoteImageInfo>(posters.Count + backdrops.Count + logos.Count);

            _tmdbClientManager.ConvertPostersToRemoteImageInfo(posters, language, remoteImages);
            _tmdbClientManager.ConvertBackdropsToRemoteImageInfo(backdrops, language, remoteImages);
            _tmdbClientManager.ConvertLogosToRemoteImageInfo(logos, language, remoteImages);

            return(remoteImages);
        }