Beispiel #1
0
        public async Task <IEnumerable <RemoteImageInfo> > GetImages(BaseItem item, CancellationToken cancellationToken)
        {
            var episode = (Controller.Entities.TV.Episode)item;
            var series  = episode.Series;

            var seriesTmdbId = Convert.ToInt32(series?.GetProviderId(MetadataProvider.Tmdb), CultureInfo.InvariantCulture);

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

            var seasonNumber  = episode.ParentIndexNumber;
            var episodeNumber = episode.IndexNumber;

            if (!seasonNumber.HasValue || !episodeNumber.HasValue)
            {
                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 episodeResult = await _tmdbClientManager
                                .GetEpisodeAsync(seriesTmdbId, seasonNumber.Value, episodeNumber.Value, null, null, cancellationToken)
                                .ConfigureAwait(false);

            var stills = episodeResult?.Images?.Stills;

            if (stills == null)
            {
                return(Enumerable.Empty <RemoteImageInfo>());
            }

            var remoteImages = new RemoteImageInfo[stills.Count];

            for (var i = 0; i < stills.Count; i++)
            {
                var image = stills[i];
                remoteImages[i] = new RemoteImageInfo
                {
                    Url             = _tmdbClientManager.GetStillUrl(image.FilePath),
                    CommunityRating = image.VoteAverage,
                    VoteCount       = image.VoteCount,
                    Width           = image.Width,
                    Height          = image.Height,
                    Language        = TmdbUtils.AdjustImageLanguage(image.Iso_639_1, language),
                    ProviderName    = Name,
                    Type            = ImageType.Primary,
                    RatingType      = RatingType.Score
                };
            }

            return(remoteImages.OrderByLanguageDescending(language));
        }