From 298a7488a3a45e51e0defdf0196070ad1bff85cc Mon Sep 17 00:00:00 2001 From: LJQ Date: Mon, 16 Oct 2023 19:48:01 +0800 Subject: [PATCH] Applied 2nd Round of Suggested Changes --- .../Plugins/Tmdb/TV/TmdbEpisodeProvider.cs | 48 ++++++++++--------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/MediaBrowser.Providers/Plugins/Tmdb/TV/TmdbEpisodeProvider.cs b/MediaBrowser.Providers/Plugins/Tmdb/TV/TmdbEpisodeProvider.cs index 69ffd7859c..90abaa6956 100644 --- a/MediaBrowser.Providers/Plugins/Tmdb/TV/TmdbEpisodeProvider.cs +++ b/MediaBrowser.Providers/Plugins/Tmdb/TV/TmdbEpisodeProvider.cs @@ -104,47 +104,49 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.TV return metadataResult; } - var episodeResult = new TvEpisode(); - if (!info.IndexNumberEnd.HasValue) - { - episodeResult = await _tmdbClientManager - .GetEpisodeAsync(seriesTmdbId, seasonNumber.Value, episodeNumber.Value, info.SeriesDisplayOrder, info.MetadataLanguage, TmdbUtils.GetImageLanguagesParam(info.MetadataLanguage), cancellationToken) - .ConfigureAwait(false); - } - else + TvEpisode? episodeResult = null; + if (info.IndexNumberEnd.HasValue) { var startindex = episodeNumber; var endindex = info.IndexNumberEnd; - List result = new List(); + List? result = null; for (int? episode = startindex; episode <= endindex; episode++) { var episodeInfo = await _tmdbClientManager.GetEpisodeAsync(seriesTmdbId, seasonNumber.Value, episode.Value, info.SeriesDisplayOrder, info.MetadataLanguage, TmdbUtils.GetImageLanguagesParam(info.MetadataLanguage), cancellationToken).ConfigureAwait(false); if (episodeInfo is not null) { - result.Add(episodeInfo); + (result ??= new List()).Add(episodeInfo); } } - if (result.Count > 0) + if (result is not null) { episodeResult = result[0]; + if (result.Count > 1) + { + var name = new StringBuilder(episodeResult.Name); + var overview = new StringBuilder(episodeResult.Overview); + + for (int i = 1; i < result.Count; i++) + { + name.Append(" / ").Append(result[i].Name); + overview.Append(" / ").Append(result[i].Overview); + } + + episodeResult.Name = name.ToString(); + episodeResult.Overview = overview.ToString(); + } } else { return metadataResult; } - - var name = new StringBuilder(episodeResult.Name); - var overview = new StringBuilder(episodeResult.Overview); - - for (int i = 1; i < result.Count; i++) - { - name.Append(" / ").Append(result[i].Name); - overview.Append(" / ").Append(result[i].Overview); - } - - episodeResult.Name = name.ToString(); - episodeResult.Overview = overview.ToString(); + } + else + { + episodeResult = await _tmdbClientManager + .GetEpisodeAsync(seriesTmdbId, seasonNumber.Value, episodeNumber.Value, info.SeriesDisplayOrder, info.MetadataLanguage, TmdbUtils.GetImageLanguagesParam(info.MetadataLanguage), cancellationToken) + .ConfigureAwait(false); } if (episodeResult is null)