Skip to content

Commit

Permalink
Prevent failure in download thread when series not found
Browse files Browse the repository at this point in the history
  • Loading branch information
SirSparkles committed Jan 16, 2019
1 parent 5215027 commit e1ff710
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 27 deletions.
4 changes: 2 additions & 2 deletions TVRename/TVRename/CacheUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 6 additions & 0 deletions TVRename/TheTVDB/ShowNotFoundException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,11 @@ namespace TVRename
{
internal class ShowNotFoundException : Exception
{
public int showId;

public ShowNotFoundException(int id)
{
showId = id;
}
}
}
57 changes: 32 additions & 25 deletions TVRename/TheTVDB/TheTVDB.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<JObject> episodeDefaultLangResponses = null;
string requestedLanguageCode = series[id].UseCustomLanguage ? series[id].TargetLanguageCode: TVSettings.Instance.PreferredLanguageCode;
List<JObject> episodeResponses = GetEpisodes(id, requestedLanguageCode);
if (IsNotDefaultLanguage(requestedLanguageCode)) episodeDefaultLangResponses = GetEpisodes(id, DefaultLanguageCode);
try
{
List<JObject> episodeResponses = GetEpisodes(id, requestedLanguageCode);
if (IsNotDefaultLanguage(requestedLanguageCode)) episodeDefaultLangResponses = GetEpisodes(id, DefaultLanguageCode);

Dictionary<int, Tuple<JToken, JToken>> episodesResponses =
MergeEpisodeResponses(episodeResponses, episodeDefaultLangResponses);
Dictionary<int, Tuple<JToken, JToken>> episodesResponses =
MergeEpisodeResponses(episodeResponses, episodeDefaultLangResponses);

int numberOfNewEpisodes = 0;
int numberOfUpdatedEpisodes = 0;
int numberOfNewEpisodes = 0;
int numberOfUpdatedEpisodes = 0;

ICollection<int> oldEpisodeIds = new List<int>();
foreach (KeyValuePair<int, Season> kvp2 in GetSeries(id)?.AiredSeasons ?? new Dictionary<int, Season>())
{
foreach (Episode ep in kvp2.Value.Episodes.Values)
ICollection<int> oldEpisodeIds = new List<int>();
foreach (KeyValuePair<int, Season> kvp2 in GetSeries(id)?.AiredSeasons ?? new Dictionary<int, Season>())
{
oldEpisodeIds.Add(ep.EpisodeId);
foreach (Episode ep in kvp2.Value.Episodes.Values)
{
oldEpisodeIds.Add(ep.EpisodeId);
}
}
}

try
{
Expand Down Expand Up @@ -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}");
}
}
}
}
Expand Down Expand Up @@ -913,7 +920,7 @@ private List<JObject> GetEpisodes(int id,string lang)

if (TvdbIsUp())
{
throw new ShowNotFoundException();
throw new ShowNotFoundException(id);
}
}

Expand Down Expand Up @@ -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);
}
}

Expand Down

0 comments on commit e1ff710

Please sign in to comment.