From 6def4b06a8916c831ec2bd38bb066aeac7f75594 Mon Sep 17 00:00:00 2001 From: Bond-009 Date: Tue, 6 Oct 2020 14:54:17 +0200 Subject: [PATCH] Minor improvements to tmdb code --- .../Tmdb/TV/TmdbEpisodeImageProvider.cs | 14 ++++---- .../Plugins/Tmdb/TV/TmdbEpisodeProvider.cs | 32 ++++++++--------- .../Tmdb/TV/TmdbSeasonImageProvider.cs | 13 +++---- .../Tmdb/TV/TmdbSeriesImageProvider.cs | 19 ++++++----- .../Plugins/Tmdb/TV/TmdbSeriesProvider.cs | 34 +++++++++++-------- 5 files changed, 60 insertions(+), 52 deletions(-) diff --git a/MediaBrowser.Providers/Plugins/Tmdb/TV/TmdbEpisodeImageProvider.cs b/MediaBrowser.Providers/Plugins/Tmdb/TV/TmdbEpisodeImageProvider.cs index fe9e483c67..3b7a0b254e 100644 --- a/MediaBrowser.Providers/Plugins/Tmdb/TV/TmdbEpisodeImageProvider.cs +++ b/MediaBrowser.Providers/Plugins/Tmdb/TV/TmdbEpisodeImageProvider.cs @@ -67,17 +67,17 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.TV .GetEpisodeAsync(seriesTmdbId, seasonNumber.Value, episodeNumber.Value, language, TmdbUtils.GetImageLanguagesParam(language), cancellationToken) .ConfigureAwait(false); - if (episodeResult?.Images?.Stills == null) + var stills = episodeResult?.Images?.Stills; + if (stills == null) { return Enumerable.Empty(); } - var remoteImages = new List(); - - for (var i = 0; i < episodeResult.Images.Stills.Count; i++) + var remoteImages = new RemoteImageInfo[stills.Count]; + for (var i = 0; i < stills.Count; i++) { - var image = episodeResult.Images.Stills[i]; - remoteImages.Add(new RemoteImageInfo + var image = stills[i]; + remoteImages[i] = new RemoteImageInfo { Url = _tmdbClientManager.GetStillUrl(image.FilePath), CommunityRating = image.VoteAverage, @@ -88,7 +88,7 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.TV ProviderName = Name, Type = ImageType.Primary, RatingType = RatingType.Score - }); + }; } return remoteImages.OrderByLanguageDescending(language); diff --git a/MediaBrowser.Providers/Plugins/Tmdb/TV/TmdbEpisodeProvider.cs b/MediaBrowser.Providers/Plugins/Tmdb/TV/TmdbEpisodeProvider.cs index 55f1ba7dcc..93998a1102 100644 --- a/MediaBrowser.Providers/Plugins/Tmdb/TV/TmdbEpisodeProvider.cs +++ b/MediaBrowser.Providers/Plugins/Tmdb/TV/TmdbEpisodeProvider.cs @@ -40,30 +40,29 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.TV return Enumerable.Empty(); } - var metadataResult = await GetMetadata(searchInfo, cancellationToken); + var metadataResult = await GetMetadata(searchInfo, cancellationToken).ConfigureAwait(false); if (!metadataResult.HasMetadata) { return Enumerable.Empty(); } - var list = new List(); - var item = metadataResult.Item; - list.Add(new RemoteSearchResult + return new[] { - IndexNumber = item.IndexNumber, - Name = item.Name, - ParentIndexNumber = item.ParentIndexNumber, - PremiereDate = item.PremiereDate, - ProductionYear = item.ProductionYear, - ProviderIds = item.ProviderIds, - SearchProviderName = Name, - IndexNumberEnd = item.IndexNumberEnd - }); - - return list; + new RemoteSearchResult + { + IndexNumber = item.IndexNumber, + Name = item.Name, + ParentIndexNumber = item.ParentIndexNumber, + PremiereDate = item.PremiereDate, + ProductionYear = item.ProductionYear, + ProviderIds = item.ProviderIds, + SearchProviderName = Name, + IndexNumberEnd = item.IndexNumberEnd + } + }; } public async Task> GetMetadata(EpisodeInfo info, CancellationToken cancellationToken) @@ -137,8 +136,7 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.TV { if (TmdbUtils.IsTrailerType(video)) { - var videoUrl = string.Format(CultureInfo.InvariantCulture, "http://www.youtube.com/watch?v={0}", video.Key); - item.AddTrailerUrl(videoUrl); + item.AddTrailerUrl("https://www.youtube.com/watch?v=" + video.Key); } } } diff --git a/MediaBrowser.Providers/Plugins/Tmdb/TV/TmdbSeasonImageProvider.cs b/MediaBrowser.Providers/Plugins/Tmdb/TV/TmdbSeasonImageProvider.cs index 0feaa5732a..f4ed480aef 100644 --- a/MediaBrowser.Providers/Plugins/Tmdb/TV/TmdbSeasonImageProvider.cs +++ b/MediaBrowser.Providers/Plugins/Tmdb/TV/TmdbSeasonImageProvider.cs @@ -56,16 +56,17 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.TV .GetSeasonAsync(seriesTmdbId, season.IndexNumber.Value, language, TmdbUtils.GetImageLanguagesParam(language), cancellationToken) .ConfigureAwait(false); - if (seasonResult?.Images?.Posters == null) + var posters = seasonResult?.Images?.Posters; + if (posters == null) { return Enumerable.Empty(); } - var remoteImages = new List(); - for (var i = 0; i < seasonResult.Images.Posters.Count; i++) + var remoteImages = new RemoteImageInfo[posters.Count]; + for (var i = 0; i < posters.Count; i++) { - var image = seasonResult.Images.Posters[i]; - remoteImages.Add(new RemoteImageInfo + var image = posters[i]; + remoteImages[i] = new RemoteImageInfo { Url = _tmdbClientManager.GetPosterUrl(image.FilePath), CommunityRating = image.VoteAverage, @@ -76,7 +77,7 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.TV ProviderName = Name, Type = ImageType.Primary, RatingType = RatingType.Score - }); + }; } return remoteImages.OrderByLanguageDescending(language); diff --git a/MediaBrowser.Providers/Plugins/Tmdb/TV/TmdbSeriesImageProvider.cs b/MediaBrowser.Providers/Plugins/Tmdb/TV/TmdbSeriesImageProvider.cs index 2fdec0196b..d0c6b8b886 100644 --- a/MediaBrowser.Providers/Plugins/Tmdb/TV/TmdbSeriesImageProvider.cs +++ b/MediaBrowser.Providers/Plugins/Tmdb/TV/TmdbSeriesImageProvider.cs @@ -68,12 +68,15 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.TV return Enumerable.Empty(); } - var remoteImages = new List(); + var posters = series.Images.Posters; + var backdrops = series.Images.Backdrops; - for (var i = 0; i < series.Images.Posters.Count; i++) + var remoteImages = new RemoteImageInfo[posters.Count + backdrops.Count]; + + for (var i = 0; i < posters.Count; i++) { - var poster = series.Images.Posters[i]; - remoteImages.Add(new RemoteImageInfo + var poster = posters[i]; + remoteImages[i] = new RemoteImageInfo { Url = _tmdbClientManager.GetPosterUrl(poster.FilePath), CommunityRating = poster.VoteAverage, @@ -84,13 +87,13 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.TV ProviderName = Name, Type = ImageType.Primary, RatingType = RatingType.Score - }); + }; } - for (var i = 0; i < series.Images.Backdrops.Count; i++) + for (var i = 0; i < backdrops.Count; i++) { var backdrop = series.Images.Backdrops[i]; - remoteImages.Add(new RemoteImageInfo + remoteImages[posters.Count + i] = new RemoteImageInfo { Url = _tmdbClientManager.GetBackdropUrl(backdrop.FilePath), CommunityRating = backdrop.VoteAverage, @@ -100,7 +103,7 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.TV ProviderName = Name, Type = ImageType.Backdrop, RatingType = RatingType.Score - }); + }; } return remoteImages.OrderByLanguageDescending(language); diff --git a/MediaBrowser.Providers/Plugins/Tmdb/TV/TmdbSeriesProvider.cs b/MediaBrowser.Providers/Plugins/Tmdb/TV/TmdbSeriesProvider.cs index 7944dfe27c..942c85b90d 100644 --- a/MediaBrowser.Providers/Plugins/Tmdb/TV/TmdbSeriesProvider.cs +++ b/MediaBrowser.Providers/Plugins/Tmdb/TV/TmdbSeriesProvider.cs @@ -66,14 +66,15 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.TV .FindByExternalIdAsync(imdbId, FindExternalSource.Imdb, searchInfo.MetadataLanguage, cancellationToken) .ConfigureAwait(false); - if (findResult?.TvResults != null) + var tvResults = findResult?.TvResults; + if (tvResults != null) { - var imdbIdResults = new List(); - for (var i = 0; i < findResult.TvResults.Count; i++) + var imdbIdResults = new RemoteSearchResult[tvResults.Count]; + for (var i = 0; i < tvResults.Count; i++) { - var remoteResult = MapSearchTvToRemoteSearchResult(findResult.TvResults[i]); + var remoteResult = MapSearchTvToRemoteSearchResult(tvResults[i]); remoteResult.SetProviderId(MetadataProvider.Imdb, imdbId); - imdbIdResults.Add(remoteResult); + imdbIdResults[i] = remoteResult; } return imdbIdResults; @@ -88,14 +89,15 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.TV .FindByExternalIdAsync(tvdbId, FindExternalSource.TvDb, searchInfo.MetadataLanguage, cancellationToken) .ConfigureAwait(false); - if (findResult?.TvResults != null) + var tvResults = findResult?.TvResults; + if (tvResults != null) { - var tvIdResults = new List(); - for (var i = 0; i < findResult.TvResults.Count; i++) + var tvIdResults = new RemoteSearchResult[tvResults.Count]; + for (var i = 0; i < tvResults.Count; i++) { - var remoteResult = MapSearchTvToRemoteSearchResult(findResult.TvResults[i]); + var remoteResult = MapSearchTvToRemoteSearchResult(tvResults[i]); remoteResult.SetProviderId(MetadataProvider.Tvdb, tvdbId); - tvIdResults.Add(remoteResult); + tvIdResults[i] = remoteResult; } return tvIdResults; @@ -105,10 +107,10 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.TV var tvSearchResults = await _tmdbClientManager.SearchSeriesAsync(searchInfo.Name, searchInfo.MetadataLanguage, cancellationToken) .ConfigureAwait(false); - var remoteResults = new List(); + var remoteResults = new RemoteSearchResult[tvSearchResults.Count]; for (var i = 0; i < tvSearchResults.Count; i++) { - remoteResults.Add(MapSearchTvToRemoteSearchResult(tvSearchResults[i])); + remoteResults[i] = MapSearchTvToRemoteSearchResult(tvSearchResults[i]); } return remoteResults; @@ -236,7 +238,11 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.TV private Series MapTvShowToSeries(TvShow seriesResult, string preferredCountryCode) { - var series = new Series {Name = seriesResult.Name, OriginalTitle = seriesResult.OriginalName}; + var series = new Series + { + Name = seriesResult.Name, + OriginalTitle = seriesResult.OriginalName + }; series.SetProviderId(MetadataProvider.Tmdb, seriesResult.Id.ToString(CultureInfo.InvariantCulture)); @@ -322,7 +328,7 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.TV { if (TmdbUtils.IsTrailerType(video)) { - series.AddTrailerUrl($"http://www.youtube.com/watch?v={video.Key}"); + series.AddTrailerUrl("https://www.youtube.com/watch?v=" + video.Key); } } }