Ejemplo n.º 1
0
        private RemoteSearchResult MapTvShowToRemoteSearchResult(TvShow series)
        {
            var remoteResult = new RemoteSearchResult
            {
                Name = series.Name ?? series.OriginalName,
                SearchProviderName = Name,
                ImageUrl           = _tmdbClientManager.GetPosterUrl(series.PosterPath),
                Overview           = series.Overview
            };

            remoteResult.SetProviderId(MetadataProvider.Tmdb, series.Id.ToString(CultureInfo.InvariantCulture));
            if (series.ExternalIds != null)
            {
                if (!string.IsNullOrEmpty(series.ExternalIds.ImdbId))
                {
                    remoteResult.SetProviderId(MetadataProvider.Imdb, series.ExternalIds.ImdbId);
                }

                if (!string.IsNullOrEmpty(series.ExternalIds.TvdbId))
                {
                    remoteResult.SetProviderId(MetadataProvider.Tvdb, series.ExternalIds.TvdbId);
                }
            }

            remoteResult.PremiereDate = series.FirstAirDate?.ToUniversalTime();

            return(remoteResult);
        }
Ejemplo n.º 2
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.º 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 <RemoteSearchResult> > GetSearchResults(BoxSetInfo searchInfo, CancellationToken cancellationToken)
        {
            var tmdbId   = Convert.ToInt32(searchInfo.GetProviderId(MetadataProvider.Tmdb), CultureInfo.InvariantCulture);
            var language = searchInfo.MetadataLanguage;

            if (tmdbId > 0)
            {
                var collection = await _tmdbClientManager.GetCollectionAsync(tmdbId, language, TmdbUtils.GetImageLanguagesParam(language), cancellationToken).ConfigureAwait(false);

                if (collection == null)
                {
                    return(Enumerable.Empty <RemoteSearchResult>());
                }

                var result = new RemoteSearchResult
                {
                    Name = collection.Name,
                    SearchProviderName = Name
                };

                if (collection.Images != null)
                {
                    result.ImageUrl = _tmdbClientManager.GetPosterUrl(collection.PosterPath);
                }

                result.SetProviderId(MetadataProvider.Tmdb, collection.Id.ToString(CultureInfo.InvariantCulture));

                return(new[] { result });
            }

            var collectionSearchResults = await _tmdbClientManager.SearchCollectionAsync(searchInfo.Name, language, cancellationToken).ConfigureAwait(false);

            var collections = new List <RemoteSearchResult>();

            for (var i = 0; i < collectionSearchResults.Count; i++)
            {
                var collection = new RemoteSearchResult
                {
                    Name = collectionSearchResults[i].Name,
                    SearchProviderName = Name
                };
                collection.SetProviderId(MetadataProvider.Tmdb, collectionSearchResults[i].Id.ToString(CultureInfo.InvariantCulture));

                collections.Add(collection);
            }

            return(collections);
        }
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 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.º 8
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.º 9
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));
        }