From e1ff71062160b7b4afec42e5744eccb3c0267109 Mon Sep 17 00:00:00 2001 From: Mark Date: Thu, 17 Jan 2019 00:08:20 +0800 Subject: [PATCH] Prevent failure in download thread when series not found --- TVRename/TVRename/CacheUpdater.cs | 4 +- TVRename/TheTVDB/ShowNotFoundException.cs | 6 +++ TVRename/TheTVDB/TheTVDB.cs | 57 +++++++++++++---------- 3 files changed, 40 insertions(+), 27 deletions(-) diff --git a/TVRename/TVRename/CacheUpdater.cs b/TVRename/TVRename/CacheUpdater.cs index 70e5fde8b..573406728 100644 --- a/TVRename/TVRename/CacheUpdater.cs +++ b/TVRename/TVRename/CacheUpdater.cs @@ -116,10 +116,10 @@ private void GetThread(object codeIn) r = TheTVDB.Instance.EnsureUpdated(series.SeriesId, bannersToo, series.UseCustomLanguage, series.CustomLanguageCode); } - catch (ShowNotFoundException) + catch (ShowNotFoundException snfe) { r = true; - problematicSeriesIds.Add(series.SeriesId); + problematicSeriesIds.Add(snfe.showId); } Threadslogger.Trace(" Finished " + series.SeriesId); diff --git a/TVRename/TheTVDB/ShowNotFoundException.cs b/TVRename/TheTVDB/ShowNotFoundException.cs index 481eb3264..83c8d6db7 100644 --- a/TVRename/TheTVDB/ShowNotFoundException.cs +++ b/TVRename/TheTVDB/ShowNotFoundException.cs @@ -12,5 +12,11 @@ namespace TVRename { internal class ShowNotFoundException : Exception { + public int showId; + + public ShowNotFoundException(int id) + { + showId = id; + } } } diff --git a/TVRename/TheTVDB/TheTVDB.cs b/TVRename/TheTVDB/TheTVDB.cs index f4d81f41a..6563d8ad7 100644 --- a/TVRename/TheTVDB/TheTVDB.cs +++ b/TVRename/TheTVDB/TheTVDB.cs @@ -696,23 +696,25 @@ private void ProcessUpdate(JObject jsonResponse, string uri) //now we wish to see if any episodes from the series have been updated. If so then mark them as dirty too List episodeDefaultLangResponses = null; string requestedLanguageCode = series[id].UseCustomLanguage ? series[id].TargetLanguageCode: TVSettings.Instance.PreferredLanguageCode; - List episodeResponses = GetEpisodes(id, requestedLanguageCode); - if (IsNotDefaultLanguage(requestedLanguageCode)) episodeDefaultLangResponses = GetEpisodes(id, DefaultLanguageCode); + try + { + List episodeResponses = GetEpisodes(id, requestedLanguageCode); + if (IsNotDefaultLanguage(requestedLanguageCode)) episodeDefaultLangResponses = GetEpisodes(id, DefaultLanguageCode); - Dictionary> episodesResponses = - MergeEpisodeResponses(episodeResponses, episodeDefaultLangResponses); + Dictionary> episodesResponses = + MergeEpisodeResponses(episodeResponses, episodeDefaultLangResponses); - int numberOfNewEpisodes = 0; - int numberOfUpdatedEpisodes = 0; + int numberOfNewEpisodes = 0; + int numberOfUpdatedEpisodes = 0; - ICollection oldEpisodeIds = new List(); - foreach (KeyValuePair kvp2 in GetSeries(id)?.AiredSeasons ?? new Dictionary()) - { - foreach (Episode ep in kvp2.Value.Episodes.Values) + ICollection oldEpisodeIds = new List(); + foreach (KeyValuePair kvp2 in GetSeries(id)?.AiredSeasons ?? new Dictionary()) { - oldEpisodeIds.Add(ep.EpisodeId); + foreach (Episode ep in kvp2.Value.Episodes.Values) + { + oldEpisodeIds.Add(ep.EpisodeId); + } } - } try { @@ -757,27 +759,32 @@ private void ProcessUpdate(JObject jsonResponse, string uri) } catch (InvalidCastException ex) { - Logger.Error(ex,"Did not receive the expected format of episode json from {0}.", uri); + Logger.Error(ex, "Did not receive the expected format of episode json from {0}.", uri); Logger.Error(jsonResponse["data"].ToString()); } catch (OverflowException ex) { - Logger.Error(ex,"Could not parse the episode json from {0}.", uri); + Logger.Error(ex, "Could not parse the episode json from {0}.", uri); Logger.Error(jsonResponse["data"].ToString()); } - Logger.Info(series[id].Name + " had " + numberOfUpdatedEpisodes + - " episodes updated and " + numberOfNewEpisodes + " new episodes "); + Logger.Info(series[id].Name + " had " + numberOfUpdatedEpisodes + + " episodes updated and " + numberOfNewEpisodes + " new episodes "); - if (oldEpisodeIds.Count > 0) - Logger.Warn(series[id].Name + " had " + oldEpisodeIds.Count + - " episodes deleted: " + string.Join(",", oldEpisodeIds)); + if (oldEpisodeIds.Count > 0) + Logger.Warn(series[id].Name + " had " + oldEpisodeIds.Count + + " episodes deleted: " + string.Join(",", oldEpisodeIds)); - LockRemoveEpisodes(); - foreach (int episodeId in oldEpisodeIds) - removeEpisodeIds.Add(new ExtraEp(id, episodeId)); + LockRemoveEpisodes(); + foreach (int episodeId in oldEpisodeIds) + removeEpisodeIds.Add(new ExtraEp(id, episodeId)); - UnlockRemoveEpisodes(); + UnlockRemoveEpisodes(); + } + catch (ShowNotFoundException ex) + { + Logger.Error($"Episodes were not found for {ex.showId}:{series[id].Name} in languange {requestedLanguageCode} or {DefaultLanguageCode}"); + } } } } @@ -913,7 +920,7 @@ private List GetEpisodes(int id,string lang) if (TvdbIsUp()) { - throw new ShowNotFoundException(); + throw new ShowNotFoundException(id); } } @@ -1116,7 +1123,7 @@ private SeriesInfo DownloadSeriesNow(int code, bool episodesToo, bool bannersToo if (TvdbIsUp()) { LastError = ex.Message; - throw new ShowNotFoundException(); + throw new ShowNotFoundException(code); } }