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)); }
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); }
public async Task <IEnumerable <RemoteSearchResult> > GetSearchResults(SeriesInfo searchInfo, CancellationToken cancellationToken) { if (searchInfo.TryGetProviderId(MetadataProvider.Tmdb, out var tmdbId)) { var series = await _tmdbClientManager .GetSeriesAsync(Convert.ToInt32(tmdbId, CultureInfo.InvariantCulture), searchInfo.MetadataLanguage, searchInfo.MetadataLanguage, cancellationToken) .ConfigureAwait(false); if (series != null) { var remoteResult = MapTvShowToRemoteSearchResult(series); return(new[] { remoteResult }); } } if (searchInfo.TryGetProviderId(MetadataProvider.Imdb, out var imdbId)) { var findResult = await _tmdbClientManager .FindByExternalIdAsync(imdbId, FindExternalSource.Imdb, searchInfo.MetadataLanguage, cancellationToken) .ConfigureAwait(false); var tvResults = findResult?.TvResults; if (tvResults != null) { var imdbIdResults = new RemoteSearchResult[tvResults.Count]; for (var i = 0; i < tvResults.Count; i++) { var remoteResult = MapSearchTvToRemoteSearchResult(tvResults[i]); remoteResult.SetProviderId(MetadataProvider.Imdb, imdbId); imdbIdResults[i] = remoteResult; } return(imdbIdResults); } } if (searchInfo.TryGetProviderId(MetadataProvider.Tvdb, out var tvdbId)) { var findResult = await _tmdbClientManager .FindByExternalIdAsync(tvdbId, FindExternalSource.TvDb, searchInfo.MetadataLanguage, cancellationToken) .ConfigureAwait(false); var tvResults = findResult?.TvResults; if (tvResults != null) { var tvIdResults = new RemoteSearchResult[tvResults.Count]; for (var i = 0; i < tvResults.Count; i++) { var remoteResult = MapSearchTvToRemoteSearchResult(tvResults[i]); remoteResult.SetProviderId(MetadataProvider.Tvdb, tvdbId); tvIdResults[i] = remoteResult; } return(tvIdResults); } } var tvSearchResults = await _tmdbClientManager.SearchSeriesAsync(searchInfo.Name, searchInfo.MetadataLanguage, cancellationToken : cancellationToken) .ConfigureAwait(false); var remoteResults = new RemoteSearchResult[tvSearchResults.Count]; for (var i = 0; i < tvSearchResults.Count; i++) { remoteResults[i] = MapSearchTvToRemoteSearchResult(tvSearchResults[i]); } return(remoteResults); }
public async Task <IEnumerable <RemoteSearchResult> > GetSearchResults(SeriesInfo searchInfo, CancellationToken cancellationToken) { if (searchInfo.TryGetProviderId(MetadataProvider.Tmdb, out var tmdbId)) { var series = await _tmdbClientManager .GetSeriesAsync(Convert.ToInt32(tmdbId, CultureInfo.InvariantCulture), searchInfo.MetadataLanguage, searchInfo.MetadataLanguage, cancellationToken) .ConfigureAwait(false); if (series != null) { var remoteResult = MapTvShowToRemoteSearchResult(series); return(new[] { remoteResult }); } } if (searchInfo.TryGetProviderId(MetadataProvider.Imdb, out var imdbId)) { var findResult = await _tmdbClientManager .FindByExternalIdAsync(imdbId, FindExternalSource.Imdb, searchInfo.MetadataLanguage, cancellationToken) .ConfigureAwait(false); var tvResults = findResult?.TvResults; if (tvResults != null) { var imdbIdResults = new RemoteSearchResult[tvResults.Count]; for (var i = 0; i < tvResults.Count; i++) { var remoteResult = MapSearchTvToRemoteSearchResult(tvResults[i]); remoteResult.SetProviderId(MetadataProvider.Imdb, imdbId); imdbIdResults[i] = remoteResult; } return(imdbIdResults); } } if (searchInfo.TryGetProviderId(MetadataProvider.Tvdb, out var tvdbId)) { var findResult = await _tmdbClientManager .FindByExternalIdAsync(tvdbId, FindExternalSource.TvDb, searchInfo.MetadataLanguage, cancellationToken) .ConfigureAwait(false); var tvResults = findResult?.TvResults; if (tvResults != null) { var tvIdResults = new RemoteSearchResult[tvResults.Count]; for (var i = 0; i < tvResults.Count; i++) { var remoteResult = MapSearchTvToRemoteSearchResult(tvResults[i]); remoteResult.SetProviderId(MetadataProvider.Tvdb, tvdbId); tvIdResults[i] = remoteResult; } return(tvIdResults); } } var tvSearchResults = await _tmdbClientManager.SearchSeriesAsync(searchInfo.Name, searchInfo.MetadataLanguage, cancellationToken : cancellationToken) .ConfigureAwait(false); var tmdbSearchResults = new TMDbLib.Objects.TvShows.TvShow[tvSearchResults.Count]; var remoteResults = new RemoteSearchResult[tvSearchResults.Count]; for (var i = 0; i < tvSearchResults.Count; i++) { tmdbSearchResults[i] = await _tmdbClientManager .GetSeriesAsync(Convert.ToInt32(tvSearchResults[i].Id, CultureInfo.InvariantCulture), searchInfo.MetadataLanguage, searchInfo.MetadataLanguage, cancellationToken) .ConfigureAwait(false); remoteResults[i] = MapTvShowToRemoteSearchResult(tmdbSearchResults[i]); } int resultCountHelper = 0; for (var i = 0; i < remoteResults.Length; i++) { resultCountHelper += 1 + remoteResults[i].EpisodeGroups.Results.Count; } var remoteResultEpisodeGroups = new RemoteSearchResult[resultCountHelper]; for (var i = 0; i < remoteResultEpisodeGroups.Length; i++) { for (var j = 0; j < tmdbSearchResults.Length; j++) { remoteResultEpisodeGroups[i++] = MapTvShowToRemoteSearchResult(tmdbSearchResults[j]); for (var k = 0; k < tmdbSearchResults[j].EpisodeGroups.Results.Count; k++) { remoteResultEpisodeGroups[i++] = MapTvShowEpisodeGroupToRemoteSearchResult(tmdbSearchResults[j], k); } } } return(remoteResultEpisodeGroups); }