Merge pull request #4600 from sephrat/sonarr-sync-2

Sonarr sync: stop using seasonpass API
pull/4620/head
Jamie 3 years ago committed by GitHub
commit 0c73501d32
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -343,8 +343,6 @@ namespace Ombi.Core.Senders
await Task.Delay(500); await Task.Delay(500);
} }
var seriesChanges = false;
foreach (var season in model.SeasonRequests) foreach (var season in model.SeasonRequests)
{ {
foreach (var ep in season.Episodes) foreach (var ep in season.Episodes)
@ -359,72 +357,36 @@ namespace Ombi.Core.Senders
} }
existingSeason = result.seasons.FirstOrDefault(x => x.seasonNumber == season.SeasonNumber); existingSeason = result.seasons.FirstOrDefault(x => x.seasonNumber == season.SeasonNumber);
var sonarrEpisodeList = sonarrEpList.Where(x => x.seasonNumber == season.SeasonNumber).ToList();
var sonarrEpCount = sonarrEpisodeList.Count;
var ourRequestCount = season.Episodes.Count;
var ourEpisodes = season.Episodes.Select(x => x.EpisodeNumber).ToList();
var unairedEpisodes = sonarrEpisodeList.Where(x => x.airDateUtc > DateTime.UtcNow).Select(x => x.episodeNumber).ToList();
//// Check if we have requested all the latest episodes, if we have then monitor
//// NOTE, not sure if needed since ombi ui displays future episodes anyway...
//ourEpisodes.AddRange(unairedEpisodes);
//var distinctEpisodes = ourEpisodes.Distinct().ToList();
//var missingEpisodes = Enumerable.Range(distinctEpisodes.Min(), distinctEpisodes.Count).Except(distinctEpisodes);
// Make sure this season is set to monitored
if (sonarrEpCount == ourRequestCount /*|| !missingEpisodes.Any()*/) if (!existingSeason.monitored)
{ {
// We have the same amount of requests as all of the episodes in the season. // We need to monitor it, problem being is all episodes will now be monitored
// So we need to monitor the series but unmonitor every episode
existingSeason.monitored = true; existingSeason.monitored = true;
seriesChanges = true; var sea = result.seasons.FirstOrDefault(x => x.seasonNumber == existingSeason.seasonNumber);
sea.monitored = true;
// We do not need to update the episodes as marking the season as monitored will mark the episodes as monitored. result = await SonarrApi.UpdateSeries(result, s.ApiKey, s.FullUri);
var seasonToUpdate = result.seasons.FirstOrDefault(x => x.seasonNumber == season.SeasonNumber); var epToUnmonitored = new List<Episode>();
seasonToUpdate.monitored = true; // Update by ref var newEpList = sonarrEpList.ConvertAll(ep => new Episode(ep)); // Clone it so we don't modify the original member
} foreach (var ep in newEpList.Where(x => x.seasonNumber == existingSeason.seasonNumber).ToList())
else
{
// Make sure this season is set to monitored
if (!existingSeason.monitored)
{ {
// We need to monitor it, problem being is all episodes will now be monitored ep.monitored = false;
// So we need to monitor the series but unmonitor every episode epToUnmonitored.Add(ep);
// Except the episodes that are already monitored before we update the series (we do not want to unmonitored episodes that are monitored beforehand)
existingSeason.monitored = true;
var sea = result.seasons.FirstOrDefault(x => x.seasonNumber == existingSeason.seasonNumber);
sea.monitored = true;
//var previouslyMonitoredEpisodes = sonarrEpList.Where(x =>
// x.seasonNumber == existingSeason.seasonNumber && x.monitored).Select(x => x.episodeNumber).ToList(); // We probably don't actually care about this
result = await SonarrApi.UpdateSeries(result, s.ApiKey, s.FullUri);
var epToUnmonitored = new List<Episode>();
var newEpList = sonarrEpList.ConvertAll(ep => new Episode(ep)); // Clone it so we don't modify the original member
foreach (var ep in newEpList.Where(x => x.seasonNumber == existingSeason.seasonNumber).ToList())
{
//if (previouslyMonitoredEpisodes.Contains(ep.episodeNumber))
//{
// // This was previously monitored.
// continue;
//}
ep.monitored = false;
epToUnmonitored.Add(ep);
}
foreach (var epToUpdate in epToUnmonitored)
{
await SonarrApi.UpdateEpisode(epToUpdate, s.ApiKey, s.FullUri);
}
} }
// Now update the episodes that need updating
foreach (var epToUpdate in episodesToUpdate.Where(x => x.seasonNumber == season.SeasonNumber)) foreach (var epToUpdate in epToUnmonitored)
{ {
await SonarrApi.UpdateEpisode(epToUpdate, s.ApiKey, s.FullUri); await SonarrApi.UpdateEpisode(epToUpdate, s.ApiKey, s.FullUri);
} }
} }
} // Now update the episodes that need updating
if (seriesChanges) foreach (var epToUpdate in episodesToUpdate.Where(x => x.seasonNumber == season.SeasonNumber))
{ {
await SonarrApi.SeasonPass(s.ApiKey, s.FullUri, result); await SonarrApi.UpdateEpisode(epToUpdate, s.ApiKey, s.FullUri);
}
} }
if (!s.AddOnly) if (!s.AddOnly)

Loading…
Cancel
Save