From 1f30a50f4a361be303c9221d9d3e5c4d8db2b364 Mon Sep 17 00:00:00 2001 From: Claus Vium Date: Wed, 20 Feb 2019 11:03:04 +0100 Subject: [PATCH] Address review comments --- .../TV/MissingEpisodeProvider.cs | 34 +++++++++---------- .../TV/TheTVDB/TvDbClientManager.cs | 22 ++++++------ .../TV/TheTVDB/TvdbSeasonImageProvider.cs | 5 +-- .../TV/TheTVDB/TvdbSeriesImageProvider.cs | 2 +- 4 files changed, 30 insertions(+), 33 deletions(-) diff --git a/MediaBrowser.Providers/TV/MissingEpisodeProvider.cs b/MediaBrowser.Providers/TV/MissingEpisodeProvider.cs index d24a7bbc7..0a2975e0f 100644 --- a/MediaBrowser.Providers/TV/MissingEpisodeProvider.cs +++ b/MediaBrowser.Providers/TV/MissingEpisodeProvider.cs @@ -64,11 +64,11 @@ namespace MediaBrowser.Providers.TV DateTime.TryParse(i.FirstAired, out var firstAired); var seasonNumber = i.AiredSeason.GetValueOrDefault(-1); var episodeNumber = i.AiredEpisodeNumber.GetValueOrDefault(-1); - return (SeasonNumber: seasonNumber, EpisodeNumber: episodeNumber, firstAired: firstAired); + return (seasonNumber: seasonNumber, episodeNumber: episodeNumber, firstAired: firstAired); }) - .Where(i => i.SeasonNumber != -1 && i.EpisodeNumber != -1) - .OrderBy(i => i.SeasonNumber) - .ThenBy(i => i.EpisodeNumber) + .Where(i => i.seasonNumber != -1 && i.episodeNumber != -1) + .OrderBy(i => i.seasonNumber) + .ThenBy(i => i.episodeNumber) .ToList(); var allRecursiveChildren = series.GetRecursiveChildren(); @@ -133,18 +133,18 @@ namespace MediaBrowser.Providers.TV Series series, IEnumerable allItems, bool addMissingEpisodes, - IReadOnlyCollection<(int SeasonNumber, int Episodenumber, DateTime FirstAired)> episodeLookup, + IReadOnlyCollection<(int seasonNumber, int episodenumber, DateTime firstAired)> episodeLookup, CancellationToken cancellationToken) { var existingEpisodes = allItems.OfType().ToList(); - var seasonCounts = episodeLookup.GroupBy(e => e.SeasonNumber).ToDictionary(g => g.Key, g => g.Count()); + var seasonCounts = episodeLookup.GroupBy(e => e.seasonNumber).ToDictionary(g => g.Key, g => g.Count()); var hasChanges = false; foreach (var tuple in episodeLookup) { - if (tuple.SeasonNumber <= 0 || tuple.Episodenumber <= 0) + if (tuple.seasonNumber <= 0 || tuple.episodenumber <= 0) { // Ignore episode/season zeros continue; @@ -157,15 +157,15 @@ namespace MediaBrowser.Providers.TV continue; } - var airDate = tuple.FirstAired; + var airDate = tuple.firstAired; var now = DateTime.UtcNow.AddDays(-UnairedEpisodeThresholdDays); if (airDate < now && addMissingEpisodes || airDate > now) { // tvdb has a lot of nearly blank episodes - _logger.LogInformation("Creating virtual missing/unaired episode {0} {1}x{2}", series.Name, tuple.SeasonNumber, tuple.Episodenumber); - await AddEpisode(series, tuple.SeasonNumber, tuple.Episodenumber, cancellationToken).ConfigureAwait(false); + _logger.LogInformation("Creating virtual missing/unaired episode {0} {1}x{2}", series.Name, tuple.seasonNumber, tuple.episodenumber); + await AddEpisode(series, tuple.seasonNumber, tuple.episodenumber, cancellationToken).ConfigureAwait(false); hasChanges = true; } @@ -179,7 +179,7 @@ namespace MediaBrowser.Providers.TV /// private bool RemoveObsoleteOrMissingEpisodes( IEnumerable allRecursiveChildren, - IEnumerable<(int SeasonNumber, int EpisodeNumber, DateTime FirstAired)> episodeLookup, + IEnumerable<(int seasonNumber, int episodeNumber, DateTime firstAired)> episodeLookup, bool allowMissingEpisodes) { var existingEpisodes = allRecursiveChildren.OfType(); @@ -218,7 +218,7 @@ namespace MediaBrowser.Providers.TV } // If the episode no longer exists in the remote lookup, delete it - if (!episodeLookup.Any(e => e.SeasonNumber == seasonNumber && e.EpisodeNumber == episodeNumber)) + if (!episodeLookup.Any(e => e.seasonNumber == seasonNumber && e.episodeNumber == episodeNumber)) { return true; } @@ -252,7 +252,7 @@ namespace MediaBrowser.Providers.TV /// The episode lookup. /// Task{System.Boolean}. private bool RemoveObsoleteOrMissingSeasons(IList allRecursiveChildren, - IEnumerable<(int SeasonNumber, int EpisodeNumber, DateTime FirstAired)> episodeLookup) + IEnumerable<(int seasonNumber, int episodeNumber, DateTime firstAired)> episodeLookup) { var existingSeasons = allRecursiveChildren.OfType().ToList(); @@ -286,7 +286,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 - return episodeLookup.All(e => e.SeasonNumber != seasonNumber) && allEpisodes.All(s => s.ParentIndexNumber != seasonNumber || s.IsInSeasonFolder); + return episodeLookup.All(e => e.seasonNumber != seasonNumber) && allEpisodes.All(s => s.ParentIndexNumber != seasonNumber || s.IsInSeasonFolder); } // Season does not have a number @@ -354,10 +354,10 @@ namespace MediaBrowser.Providers.TV /// /// /// Episode. - private Episode GetExistingEpisode(IList existingEpisodes, IReadOnlyDictionary 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; + var seasonNumber = episodeTuple.seasonNumber; + var episodeNumber = episodeTuple.episodeNumber; while (true) { diff --git a/MediaBrowser.Providers/TV/TheTVDB/TvDbClientManager.cs b/MediaBrowser.Providers/TV/TheTVDB/TvDbClientManager.cs index 21f09d8d1..7e9c7a76e 100644 --- a/MediaBrowser.Providers/TV/TheTVDB/TvDbClientManager.cs +++ b/MediaBrowser.Providers/TV/TheTVDB/TvDbClientManager.cs @@ -16,16 +16,16 @@ namespace MediaBrowser.Providers.TV.TheTVDB { private readonly SemaphoreSlim _cacheWriteLock = new SemaphoreSlim(1, 1); private readonly IMemoryCache _cache; - private readonly TvDbClient tvDbClient; - private DateTime tokenCreatedAt; + private readonly TvDbClient _tvDbClient; + private DateTime _tokenCreatedAt; private const string DefaultLanguage = "en"; public TvDbClientManager(IMemoryCache memoryCache) { _cache = memoryCache; - tvDbClient = new TvDbClient(); - tvDbClient.Authentication.AuthenticateAsync(TvdbUtils.TvdbApiKey); - tokenCreatedAt = DateTime.Now; + _tvDbClient = new TvDbClient(); + _tvDbClient.Authentication.AuthenticateAsync(TvdbUtils.TvdbApiKey); + _tokenCreatedAt = DateTime.Now; } public TvDbClient TvDbClient @@ -33,21 +33,21 @@ namespace MediaBrowser.Providers.TV.TheTVDB get { // Refresh if necessary - if (tokenCreatedAt > DateTime.Now.Subtract(TimeSpan.FromHours(20))) + if (_tokenCreatedAt > DateTime.Now.Subtract(TimeSpan.FromHours(20))) { try { - tvDbClient.Authentication.RefreshTokenAsync(); + _tvDbClient.Authentication.RefreshTokenAsync(); } catch { - tvDbClient.Authentication.AuthenticateAsync(TvdbUtils.TvdbApiKey); + _tvDbClient.Authentication.AuthenticateAsync(TvdbUtils.TvdbApiKey); } - tokenCreatedAt = DateTime.Now; + _tokenCreatedAt = DateTime.Now; } - return tvDbClient; + return _tvDbClient; } } @@ -197,7 +197,7 @@ namespace MediaBrowser.Providers.TV.TheTVDB return cachedValue; } - tvDbClient.AcceptedLanguage = TvdbUtils.NormalizeLanguage(language) ?? DefaultLanguage; + _tvDbClient.AcceptedLanguage = TvdbUtils.NormalizeLanguage(language) ?? DefaultLanguage; var result = await resultFactory.Invoke(); _cache.Set(key, result, TimeSpan.FromHours(1)); return result; diff --git a/MediaBrowser.Providers/TV/TheTVDB/TvdbSeasonImageProvider.cs b/MediaBrowser.Providers/TV/TheTVDB/TvdbSeasonImageProvider.cs index ee0388a70..fec0e1177 100644 --- a/MediaBrowser.Providers/TV/TheTVDB/TvdbSeasonImageProvider.cs +++ b/MediaBrowser.Providers/TV/TheTVDB/TvdbSeasonImageProvider.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Globalization; using System.Linq; using System.Threading; using System.Threading.Tasks; @@ -19,8 +18,6 @@ namespace MediaBrowser.Providers.TV.TheTVDB { public class TvdbSeasonImageProvider : IRemoteImageProvider, IHasOrder { - private static readonly CultureInfo UsCulture = new CultureInfo("en-US"); - private readonly IHttpClient _httpClient; private readonly ILogger _logger; private readonly TvDbClientManager _tvDbClientManager; @@ -66,7 +63,7 @@ namespace MediaBrowser.Providers.TV.TheTVDB var language = item.GetPreferredMetadataLanguage(); var remoteImages = new List(); - var keyTypes = new[] {KeyType.Season, KeyType.Seasonwide, KeyType.Fanart}; + var keyTypes = new[] { KeyType.Season, KeyType.Seasonwide, KeyType.Fanart }; foreach (var keyType in keyTypes) { var imageQuery = new ImagesQuery diff --git a/MediaBrowser.Providers/TV/TheTVDB/TvdbSeriesImageProvider.cs b/MediaBrowser.Providers/TV/TheTVDB/TvdbSeriesImageProvider.cs index dc9f61756..5137b4c2d 100644 --- a/MediaBrowser.Providers/TV/TheTVDB/TvdbSeriesImageProvider.cs +++ b/MediaBrowser.Providers/TV/TheTVDB/TvdbSeriesImageProvider.cs @@ -57,7 +57,7 @@ namespace MediaBrowser.Providers.TV.TheTVDB var language = item.GetPreferredMetadataLanguage(); var remoteImages = new List(); - var keyTypes = new[] {KeyType.Poster, KeyType.Series, KeyType.Fanart}; + var keyTypes = new[] { KeyType.Poster, KeyType.Series, KeyType.Fanart }; var tvdbId = Convert.ToInt32(item.GetProviderId(MetadataProviders.Tvdb)); foreach (KeyType keyType in keyTypes) {