Skip to content

Commit

Permalink
fix(sonarr): 🐛 Fixed an issue where we could attempt to add a series …
Browse files Browse the repository at this point in the history
…to sonarr before sonarr has got all the metadata #4459
  • Loading branch information
tidusjar committed Jan 14, 2022
1 parent 73f9626 commit 5c691dc
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions src/Ombi.Core/Senders/TvSender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,20 @@ public async Task<NewSeries> SendToSonarr(ChildRequests model, SonarrSettings s)

private async Task SendToSonarr(ChildRequests model, SonarrSeries result, SonarrSettings s)
{
// Check to ensure we have the all the seasons, ensure the Sonarr metadata has grabbed all the data
foreach (var season in model.SeasonRequests)
{
var attempt = 0;
var existingSeason = result.seasons.FirstOrDefault(x => x.seasonNumber == season.SeasonNumber);
while (existingSeason == null && attempt < 5)
{
attempt++;
Logger.LogInformation("There was no season numer {0} in Sonarr for title {1}. Will try again as the metadata did not get created", season.SeasonNumber, model.ParentRequest.Title);
result = await SonarrApi.GetSeriesById(result.id, s.ApiKey, s.FullUri);
await Task.Delay(500);
}
}

var episodesToUpdate = new List<Episode>();
// Ok, now let's sort out the episodes.

Expand All @@ -327,10 +341,11 @@ private async Task SendToSonarr(ChildRequests model, SonarrSeries result, Sonarr
await Task.Delay(500);
}

var seriesChanges = false;

foreach (var req in model.SeasonRequests)
foreach (var season in model.SeasonRequests)
{
foreach (var ep in req.Episodes)
foreach (var ep in season.Episodes)
{
var sonarrEp = sonarrEpList.FirstOrDefault(x =>
x.episodeNumber == ep.EpisodeNumber && x.seasonNumber == req.SeasonNumber);
Expand All @@ -340,11 +355,6 @@ private async Task SendToSonarr(ChildRequests model, SonarrSeries result, Sonarr
episodesToUpdate.Add(sonarrEp);
}
}
}
var seriesChanges = false;

foreach (var season in model.SeasonRequests)
{
var sonarrEpisodeList = sonarrEpList.Where(x => x.seasonNumber == season.SeasonNumber).ToList();
var sonarrEpCount = sonarrEpisodeList.Count;
var ourRequestCount = season.Episodes.Count;
Expand All @@ -358,13 +368,7 @@ private async Task SendToSonarr(ChildRequests model, SonarrSeries result, Sonarr
//var distinctEpisodes = ourEpisodes.Distinct().ToList();
//var missingEpisodes = Enumerable.Range(distinctEpisodes.Min(), distinctEpisodes.Count).Except(distinctEpisodes);

var existingSeason =
result.seasons.FirstOrDefault(x => x.seasonNumber == season.SeasonNumber);
if (existingSeason == null)
{
Logger.LogError("There was no season numer {0} in Sonarr for title {1}", season.SeasonNumber, model.ParentRequest.Title);
continue;
}



if (sonarrEpCount == ourRequestCount /*|| !missingEpisodes.Any()*/)
Expand Down

0 comments on commit 5c691dc

Please # to comment.