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 List <RemoteImageInfo>(posters.Count); _tmdbClientManager.ConvertPostersToRemoteImageInfo(posters, language, remoteImages); return(remoteImages); }
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); }
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)); }
public async Task <MetadataResult <Season> > GetMetadata(SeasonInfo info, CancellationToken cancellationToken) { var result = new MetadataResult <Season>(); info.SeriesProviderIds.TryGetValue(MetadataProvider.Tmdb.ToString(), out string?seriesTmdbId); var seasonNumber = info.IndexNumber; if (string.IsNullOrWhiteSpace(seriesTmdbId) || !seasonNumber.HasValue) { return(result); } var seasonResult = await _tmdbClientManager .GetSeasonAsync(Convert.ToInt32(seriesTmdbId, CultureInfo.InvariantCulture), seasonNumber.Value, info.MetadataLanguage, TmdbUtils.GetImageLanguagesParam(info.MetadataLanguage), cancellationToken) .ConfigureAwait(false); if (seasonResult == null) { return(result); } result.HasMetadata = true; result.Item = new Season { IndexNumber = seasonNumber, Overview = seasonResult.Overview }; if (Plugin.Instance.Configuration.ImportSeasonName) { result.Item.Name = seasonResult.Name; } if (!string.IsNullOrEmpty(seasonResult.ExternalIds?.TvdbId)) { result.Item.SetProviderId(MetadataProvider.Tvdb, seasonResult.ExternalIds.TvdbId); } // TODO why was this disabled? var credits = seasonResult.Credits; if (credits?.Cast != null) { var cast = credits.Cast.OrderBy(c => c.Order).Take(Plugin.Instance.Configuration.MaxCastMembers).ToList(); for (var i = 0; i < cast.Count; i++) { result.AddPerson(new PersonInfo { Name = cast[i].Name.Trim(), Role = cast[i].Character, Type = PersonType.Actor, SortOrder = cast[i].Order }); } } if (credits?.Crew != null) { foreach (var person in credits.Crew) { // Normalize this var type = TmdbUtils.MapCrewToPersonType(person); if (!TmdbUtils.WantedCrewTypes.Contains(type, StringComparison.OrdinalIgnoreCase) && !TmdbUtils.WantedCrewTypes.Contains(person.Job ?? string.Empty, StringComparison.OrdinalIgnoreCase)) { continue; } result.AddPerson(new PersonInfo { Name = person.Name.Trim(), Role = person.Job, Type = type }); } } result.Item.PremiereDate = seasonResult.AirDate; result.Item.ProductionYear = seasonResult.AirDate?.Year; return(result); }