|
|
|
@ -343,8 +343,6 @@ namespace Ombi.Core.Senders
|
|
|
|
|
await Task.Delay(500);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var seriesChanges = false;
|
|
|
|
|
|
|
|
|
|
foreach (var season in model.SeasonRequests)
|
|
|
|
|
{
|
|
|
|
|
foreach (var ep in season.Episodes)
|
|
|
|
@ -359,53 +357,22 @@ namespace Ombi.Core.Senders
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (sonarrEpCount == ourRequestCount /*|| !missingEpisodes.Any()*/)
|
|
|
|
|
{
|
|
|
|
|
// We have the same amount of requests as all of the episodes in the season.
|
|
|
|
|
existingSeason.monitored = true;
|
|
|
|
|
seriesChanges = true;
|
|
|
|
|
|
|
|
|
|
// We do not need to update the episodes as marking the season as monitored will mark the episodes as monitored.
|
|
|
|
|
var seasonToUpdate = result.seasons.FirstOrDefault(x => x.seasonNumber == season.SeasonNumber);
|
|
|
|
|
seasonToUpdate.monitored = true; // Update by ref
|
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
// So we need to monitor the series but unmonitor every episode
|
|
|
|
|
// 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);
|
|
|
|
|
}
|
|
|
|
@ -421,11 +388,6 @@ namespace Ombi.Core.Senders
|
|
|
|
|
await SonarrApi.UpdateEpisode(epToUpdate, s.ApiKey, s.FullUri);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (seriesChanges)
|
|
|
|
|
{
|
|
|
|
|
await SonarrApi.SeasonPass(s.ApiKey, s.FullUri, result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!s.AddOnly)
|
|
|
|
|
{
|
|
|
|
|