Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
        public async Task <IEnumerable <RemoteSearchResult> > GetSearchResults(MovieInfo searchInfo, CancellationToken cancellationToken)
        {
            if (searchInfo.TryGetProviderId(MetadataProvider.Tmdb, out var id))
            {
                var movie = await _tmdbClientManager
                            .GetMovieAsync(
                    int.Parse(id, CultureInfo.InvariantCulture),
                    searchInfo.MetadataLanguage,
                    TmdbUtils.GetImageLanguagesParam(searchInfo.MetadataLanguage),
                    cancellationToken)
                            .ConfigureAwait(false);

                var remoteResult = new RemoteSearchResult
                {
                    Name = movie.Title ?? movie.OriginalTitle,
                    SearchProviderName = Name,
                    ImageUrl           = _tmdbClientManager.GetPosterUrl(movie.PosterPath),
                    Overview           = movie.Overview
                };

                if (movie.ReleaseDate != null)
                {
                    var releaseDate = movie.ReleaseDate.Value.ToUniversalTime();
                    remoteResult.PremiereDate   = releaseDate;
                    remoteResult.ProductionYear = releaseDate.Year;
                }

                remoteResult.SetProviderId(MetadataProvider.Tmdb, movie.Id.ToString(CultureInfo.InvariantCulture));

                if (!string.IsNullOrWhiteSpace(movie.ImdbId))
                {
                    remoteResult.SetProviderId(MetadataProvider.Imdb, movie.ImdbId);
                }

                return(new[] { remoteResult });
            }

            IReadOnlyList <SearchMovie> movieResults;

            if (searchInfo.TryGetProviderId(MetadataProvider.Imdb, out id))
            {
                var result = await _tmdbClientManager.FindByExternalIdAsync(
                    id,
                    FindExternalSource.Imdb,
                    TmdbUtils.GetImageLanguagesParam(searchInfo.MetadataLanguage),
                    cancellationToken).ConfigureAwait(false);

                movieResults = result.MovieResults;
            }
            else if (searchInfo.TryGetProviderId(MetadataProvider.Tvdb, out id))
            {
                var result = await _tmdbClientManager.FindByExternalIdAsync(
                    id,
                    FindExternalSource.TvDb,
                    TmdbUtils.GetImageLanguagesParam(searchInfo.MetadataLanguage),
                    cancellationToken).ConfigureAwait(false);

                movieResults = result.MovieResults;
            }
            else
            {
                movieResults = await _tmdbClientManager
                               .SearchMovieAsync(searchInfo.Name, searchInfo.Year ?? 0, searchInfo.MetadataLanguage, cancellationToken)
                               .ConfigureAwait(false);
            }

            var len = movieResults.Count;
            var remoteSearchResults = new RemoteSearchResult[len];

            for (var i = 0; i < len; i++)
            {
                var movieResult        = movieResults[i];
                var remoteSearchResult = new RemoteSearchResult
                {
                    Name               = movieResult.Title ?? movieResult.OriginalTitle,
                    ImageUrl           = _tmdbClientManager.GetPosterUrl(movieResult.PosterPath),
                    Overview           = movieResult.Overview,
                    SearchProviderName = Name
                };

                var releaseDate = movieResult.ReleaseDate?.ToUniversalTime();
                remoteSearchResult.PremiereDate   = releaseDate;
                remoteSearchResult.ProductionYear = releaseDate?.Year;

                remoteSearchResult.SetProviderId(MetadataProvider.Tmdb, movieResult.Id.ToString(CultureInfo.InvariantCulture));
                remoteSearchResults[i] = remoteSearchResult;
            }

            return(remoteSearchResults);
        }
Ejemplo n.º 3
0
        public async Task <IEnumerable <RemoteSearchResult> > GetSearchResults(MovieInfo searchInfo, CancellationToken cancellationToken)
        {
            var tmdbId = Convert.ToInt32(searchInfo.GetProviderId(MetadataProvider.Tmdb), CultureInfo.InvariantCulture);

            if (tmdbId == 0)
            {
                var movieResults = await _tmdbClientManager
                                   .SearchMovieAsync(searchInfo.Name, searchInfo.MetadataLanguage, cancellationToken)
                                   .ConfigureAwait(false);

                var remoteSearchResults = new List <RemoteSearchResult>();
                for (var i = 0; i < movieResults.Count; i++)
                {
                    var movieResult        = movieResults[i];
                    var remoteSearchResult = new RemoteSearchResult
                    {
                        Name               = movieResult.Title ?? movieResult.OriginalTitle,
                        ImageUrl           = _tmdbClientManager.GetPosterUrl(movieResult.PosterPath),
                        Overview           = movieResult.Overview,
                        SearchProviderName = Name
                    };

                    var releaseDate = movieResult.ReleaseDate?.ToUniversalTime();
                    remoteSearchResult.PremiereDate   = releaseDate;
                    remoteSearchResult.ProductionYear = releaseDate?.Year;

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

                return(remoteSearchResults);
            }

            var movie = await _tmdbClientManager
                        .GetMovieAsync(tmdbId, searchInfo.MetadataLanguage, TmdbUtils.GetImageLanguagesParam(searchInfo.MetadataLanguage), cancellationToken)
                        .ConfigureAwait(false);

            var remoteResult = new RemoteSearchResult
            {
                Name = movie.Title ?? movie.OriginalTitle,
                SearchProviderName = Name,
                ImageUrl           = _tmdbClientManager.GetPosterUrl(movie.PosterPath),
                Overview           = movie.Overview
            };

            if (movie.ReleaseDate != null)
            {
                var releaseDate = movie.ReleaseDate.Value.ToUniversalTime();
                remoteResult.PremiereDate   = releaseDate;
                remoteResult.ProductionYear = releaseDate.Year;
            }

            remoteResult.SetProviderId(MetadataProvider.Tmdb, movie.Id.ToString(CultureInfo.InvariantCulture));

            if (!string.IsNullOrWhiteSpace(movie.ImdbId))
            {
                remoteResult.SetProviderId(MetadataProvider.Imdb, movie.ImdbId);
            }

            return(new[] { remoteResult });
        }
Ejemplo n.º 4
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));
        }