mirror of
https://github.com/Radarr/Radarr.git
synced 2026-04-21 22:05:43 -04:00
Decision Engine is now mostly working with movies :)
This commit is contained in:
@@ -62,6 +62,46 @@ namespace NzbDrone.Core.DecisionEngine.Specifications
|
||||
return Decision.Accept();
|
||||
}
|
||||
|
||||
public virtual Decision IsSatisfiedBy(RemoteMovie subject, SearchCriteriaBase searchCriteria)
|
||||
{
|
||||
_logger.Debug("Checking if release meets restrictions: {0}", subject);
|
||||
|
||||
var title = subject.Release.Title;
|
||||
var restrictions = _restrictionService.AllForTags(subject.Movie.Tags);
|
||||
|
||||
var required = restrictions.Where(r => r.Required.IsNotNullOrWhiteSpace());
|
||||
var ignored = restrictions.Where(r => r.Ignored.IsNotNullOrWhiteSpace());
|
||||
|
||||
foreach (var r in required)
|
||||
{
|
||||
var requiredTerms = r.Required.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList();
|
||||
|
||||
var foundTerms = ContainsAny(requiredTerms, title);
|
||||
if (foundTerms.Empty())
|
||||
{
|
||||
var terms = string.Join(", ", requiredTerms);
|
||||
_logger.Debug("[{0}] does not contain one of the required terms: {1}", title, terms);
|
||||
return Decision.Reject("Does not contain one of the required terms: {0}", terms);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var r in ignored)
|
||||
{
|
||||
var ignoredTerms = r.Ignored.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList();
|
||||
|
||||
var foundTerms = ContainsAny(ignoredTerms, title);
|
||||
if (foundTerms.Any())
|
||||
{
|
||||
var terms = string.Join(", ", foundTerms);
|
||||
_logger.Debug("[{0}] contains these ignored terms: {1}", title, terms);
|
||||
return Decision.Reject("Contains these ignored terms: {0}", terms);
|
||||
}
|
||||
}
|
||||
|
||||
_logger.Debug("[{0}] No restrictions apply, allowing", subject);
|
||||
return Decision.Accept();
|
||||
}
|
||||
|
||||
private static List<string> ContainsAny(List<string> terms, string title)
|
||||
{
|
||||
return terms.Where(t => title.ToLowerInvariant().Contains(t.ToLowerInvariant())).ToList();
|
||||
|
||||
Reference in New Issue
Block a user