We no longer block you from Requesting all seasons if we already have Season 1 Available/Requested. We will just request the delta now! For example if we request Season 1 and we have the first 3 episodes requested, we will skip those and request the remaining #2709

This commit is contained in:
tidusjar 2021-06-15 16:25:59 +01:00
parent ac3f1941bc
commit 11527e332c
14 changed files with 1646 additions and 26 deletions

View file

@ -7,6 +7,7 @@ using Ombi.Core.Rule.Interfaces;
using Ombi.Store.Entities;
using Ombi.Store.Entities.Requests;
using Ombi.Store.Repository;
using Ombi.Store.Repository.Requests;
namespace Ombi.Core.Rule.Rules.Request
{
@ -60,6 +61,7 @@ namespace Ombi.Core.Rule.Rules.Request
{
foreach (var season in child.SeasonRequests)
{
var episodesToRemove = new List<EpisodeRequests>();
var currentSeasonRequest =
content.Episodes.Where(x => x.SeasonNumber == season.SeasonNumber).ToList();
if (!currentSeasonRequest.Any())
@ -68,12 +70,24 @@ namespace Ombi.Core.Rule.Rules.Request
}
foreach (var e in season.Episodes)
{
var hasEpisode = currentSeasonRequest.Any(x => x.EpisodeNumber == e.EpisodeNumber);
if (hasEpisode)
var existingEpRequest = currentSeasonRequest.FirstOrDefault(x => x.EpisodeNumber == e.EpisodeNumber);
if (existingEpRequest != null)
{
return Fail($"We already have episodes requested from series {child.Title}");
episodesToRemove.Add(e);
}
}
episodesToRemove.ForEach(x =>
{
season.Episodes.Remove(x);
});
}
var anyEpisodes = child.SeasonRequests.SelectMany(x => x.Episodes).Any();
if (!anyEpisodes)
{
return Fail($"We already have episodes requested from series {child.Title}");
}
return Success();

View file

@ -1,4 +1,5 @@
using System.Linq;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Ombi.Core.Rule.Interfaces;
@ -41,15 +42,30 @@ namespace Ombi.Core.Rule.Rules.Request
{
continue;
}
var episodesToRemove = new List<EpisodeRequests>();
foreach (var e in season.Episodes)
{
var hasEpisode = currentSeasonRequest.Episodes.Any(x => x.EpisodeNumber == e.EpisodeNumber);
if (hasEpisode)
var existingEpRequest = currentSeasonRequest.Episodes.FirstOrDefault(x => x.EpisodeNumber == e.EpisodeNumber);
if (existingEpRequest != null)
{
return Fail($"We already have episodes requested from series {tv.Title}");
episodesToRemove.Add(e);
}
}
episodesToRemove.ForEach(x =>
{
season.Episodes.Remove(x);
});
}
var anyEpisodes = tv.SeasonRequests.SelectMany(x => x.Episodes).Any();
if (!anyEpisodes)
{
return Fail($"We already have episodes requested from series {tv.Title}");
}
}
return Success();
}

View file

@ -1,4 +1,5 @@
using System.Linq;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Ombi.Core.Models.Search;
@ -6,6 +7,7 @@ using Ombi.Helpers;
using Ombi.Store.Context;
using Ombi.Store.Entities;
using Ombi.Store.Entities.Requests;
using Ombi.Store.Repository.Requests;
namespace Ombi.Core.Rule.Rules
{
@ -23,7 +25,7 @@ namespace Ombi.Core.Rule.Rules
if (obj.RequestType == RequestType.TvShow)
{
var vm = (ChildRequests) obj;
var result = await _ctx.SonarrCache.FirstOrDefaultAsync(x => x.TvDbId == vm.Id); // TODO lookup the external provider in the sonarr sync to use themoviedb
var result = await _ctx.SonarrCache.FirstOrDefaultAsync(x => x.TheMovieDbId == vm.Id);
if (result != null)
{
if (vm.SeasonRequests.Any())
@ -31,17 +33,30 @@ namespace Ombi.Core.Rule.Rules
var sonarrEpisodes = _ctx.SonarrEpisodeCache;
foreach (var season in vm.SeasonRequests)
{
var toRemove = new List<EpisodeRequests>();
foreach (var ep in season.Episodes)
{
// Check if we have it
var monitoredInSonarr = sonarrEpisodes.Any(x =>
var monitoredInSonarr = sonarrEpisodes.FirstOrDefault(x =>
x.EpisodeNumber == ep.EpisodeNumber && x.SeasonNumber == season.SeasonNumber
&& x.TvDbId == vm.Id);
if (monitoredInSonarr)
&& x.MovieDbId == vm.Id);
if (monitoredInSonarr != null)
{
return new RuleResult{Message = "We already have this request, please choose the \"Select...\" option to refine your request"};
}
toRemove.Add(ep);
}
}
toRemove.ForEach(x =>
{
season.Episodes.Remove(x);
});
}
var anyEpisodes = vm.SeasonRequests.SelectMany(x => x.Episodes).Any();
if (!anyEpisodes)
{
return new RuleResult { Message = $"We already have episodes requested from series {vm.Title}" };
}
}
}