diff --git a/MediaBrowser.Providers/TV/MissingEpisodeProvider.cs b/MediaBrowser.Providers/TV/MissingEpisodeProvider.cs index c54a3fa4a3..4952608480 100644 --- a/MediaBrowser.Providers/TV/MissingEpisodeProvider.cs +++ b/MediaBrowser.Providers/TV/MissingEpisodeProvider.cs @@ -129,8 +129,7 @@ namespace MediaBrowser.Providers.TV IReadOnlyCollection<(int SeasonNumber, int Episodenumber, DateTime FirstAired)> episodeLookup, CancellationToken cancellationToken) { - var existingEpisodes = allItems.OfType() - .ToList(); + var existingEpisodes = allItems.OfType().ToList(); var seasonCounts = episodeLookup.GroupBy(e => e.SeasonNumber).ToDictionary(g => g.Key, g => g.Count()); @@ -280,15 +279,7 @@ namespace MediaBrowser.Providers.TV } // If the season no longer exists in the remote lookup, delete it, but only if an existing episode doesn't require it - if (episodeLookup.All(e => e.SeasonNumber != seasonNumber)) - { - if (allEpisodes.All(s => s.ParentIndexNumber != seasonNumber || s.IsInSeasonFolder)) - { - return true; - } - } - - return false; + return episodeLookup.All(e => e.SeasonNumber != seasonNumber) && allEpisodes.All(s => s.ParentIndexNumber != seasonNumber || s.IsInSeasonFolder); } // Season does not have a number @@ -354,9 +345,9 @@ namespace MediaBrowser.Providers.TV /// /// The existing episodes. /// - /// The tuple. + /// /// Episode. - private Episode GetExistingEpisode(IList existingEpisodes, Dictionary seasonCounts, (int SeasonNumber, int EpisodeNumber, DateTime FirstAired) episodeTuple) + private Episode GetExistingEpisode(IList existingEpisodes, IReadOnlyDictionary seasonCounts, (int SeasonNumber, int EpisodeNumber, DateTime FirstAired) episodeTuple) { var seasonNumber = episodeTuple.SeasonNumber; var episodeNumber = episodeTuple.EpisodeNumber; @@ -365,14 +356,20 @@ namespace MediaBrowser.Providers.TV { var episode = GetExistingEpisode(existingEpisodes, seasonNumber, episodeNumber); if (episode != null) + { return episode; + } seasonNumber--; if (seasonCounts.ContainsKey(seasonNumber)) + { episodeNumber += seasonCounts[seasonNumber]; + } else + { break; + } } return null;