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(null);
            }

            var language = item.GetPreferredMetadataLanguage();

            var series = await _tmdbClientManager
                         .GetSeriesAsync(Convert.ToInt32(tmdbId, CultureInfo.InvariantCulture), language, TmdbUtils.GetImageLanguagesParam(language), cancellationToken)
                         .ConfigureAwait(false);

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

            var posters   = series.Images.Posters;
            var backdrops = series.Images.Backdrops;

            var remoteImages = new RemoteImageInfo[posters.Count + backdrops.Count];

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

            for (var i = 0; i < backdrops.Count; i++)
            {
                var backdrop = series.Images.Backdrops[i];
                remoteImages[posters.Count + i] = new RemoteImageInfo
                {
                    Url             = _tmdbClientManager.GetBackdropUrl(backdrop.FilePath),
                    CommunityRating = backdrop.VoteAverage,
                    VoteCount       = backdrop.VoteCount,
                    Width           = backdrop.Width,
                    Height          = backdrop.Height,
                    ProviderName    = Name,
                    Type            = ImageType.Backdrop,
                    RatingType      = RatingType.Score
                };
            }

            return(remoteImages.OrderByLanguageDescending(language));
        }
Ejemplo n.º 2
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.º 3
0
        public async Task <IEnumerable <RemoteImageInfo> > GetImages(BaseItem item, CancellationToken cancellationToken)
        {
            var tmdbId = Convert.ToInt32(item.GetProviderId(MetadataProvider.Tmdb), CultureInfo.InvariantCulture);

            if (tmdbId <= 0)
            {
                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 collection = await _tmdbClientManager.GetCollectionAsync(tmdbId, null, null, cancellationToken).ConfigureAwait(false);

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

            var remoteImages = new List <RemoteImageInfo>();

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

            for (var i = 0; i < collection.Images.Backdrops.Count; i++)
            {
                var backdrop = collection.Images.Backdrops[i];
                remoteImages.Add(new RemoteImageInfo
                {
                    Url             = _tmdbClientManager.GetBackdropUrl(backdrop.FilePath),
                    CommunityRating = backdrop.VoteAverage,
                    VoteCount       = backdrop.VoteCount,
                    Width           = backdrop.Width,
                    Height          = backdrop.Height,
                    ProviderName    = Name,
                    Type            = ImageType.Backdrop,
                    RatingType      = RatingType.Score
                });
            }

            return(remoteImages.OrderByLanguageDescending(language));
        }
Ejemplo n.º 4
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));
        }
Ejemplo n.º 5
0
        public async Task <IEnumerable <RemoteImageInfo> > GetImages(BaseItem item, CancellationToken cancellationToken)
        {
            var season = (Season)item;
            var series = season?.Series;

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

            if (seriesTmdbId <= 0 || season?.IndexNumber == null)
            {
                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 seasonResult = await _tmdbClientManager
                               .GetSeasonAsync(seriesTmdbId, season.IndexNumber.Value, null, null, cancellationToken)
                               .ConfigureAwait(false);

            var posters = seasonResult?.Images?.Posters;

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

            var remoteImages = new RemoteImageInfo[posters.Count];

            for (var i = 0; i < posters.Count; i++)
            {
                var image = posters[i];
                remoteImages[i] = new RemoteImageInfo
                {
                    Url             = _tmdbClientManager.GetPosterUrl(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);
        }
Ejemplo n.º 6
0
        public async Task <IEnumerable <RemoteImageInfo> > GetImages(BaseItem item, CancellationToken cancellationToken)
        {
            var season = (Season)item;
            var series = season?.Series;

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

            if (seriesTmdbId <= 0 || season?.IndexNumber == null)
            {
                return(Enumerable.Empty <RemoteImageInfo>());
            }

            var language = item.GetPreferredMetadataLanguage();

            var seasonResult = await _tmdbClientManager
                               .GetSeasonAsync(seriesTmdbId, season.IndexNumber.Value, language, TmdbUtils.GetImageLanguagesParam(language), cancellationToken)
                               .ConfigureAwait(false);

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

            var remoteImages = new List <RemoteImageInfo>();

            for (var i = 0; i < seasonResult.Images.Posters.Count; i++)
            {
                var image = seasonResult.Images.Posters[i];
                remoteImages.Add(new RemoteImageInfo
                {
                    Url             = _tmdbClientManager.GetPosterUrl(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));
        }
Ejemplo n.º 7
0
 public static void AdjustImageLanguage_Valid_Success(string imageLanguage, string requestLanguage, string expected)
 {
     Assert.Equal(expected, TmdbUtils.AdjustImageLanguage(imageLanguage, requestLanguage));
 }
Ejemplo n.º 8
0
        /// <inheritdoc />
        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>());
            }

            var movie = await _tmdbClientManager
                        .GetMovieAsync(movieTmdbId, language, TmdbUtils.GetImageLanguagesParam(language), cancellationToken)
                        .ConfigureAwait(false);

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

            var remoteImages = new List <RemoteImageInfo>();

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

            for (var i = 0; i < movie.Images.Backdrops.Count; i++)
            {
                var backdrop = movie.Images.Backdrops[i];
                remoteImages.Add(new RemoteImageInfo
                {
                    Url             = _tmdbClientManager.GetPosterUrl(backdrop.FilePath),
                    CommunityRating = backdrop.VoteAverage,
                    VoteCount       = backdrop.VoteCount,
                    Width           = backdrop.Width,
                    Height          = backdrop.Height,
                    ProviderName    = Name,
                    Type            = ImageType.Backdrop,
                    RatingType      = RatingType.Score
                });
            }

            return(remoteImages.OrderByLanguageDescending(language));
        }