mirror of
https://github.com/lidarr/lidarr.git
synced 2025-08-20 13:33:34 -07:00
cleaned up parsing logic and structure.
This commit is contained in:
parent
cd2761d07d
commit
6e88f55a54
120 changed files with 2149 additions and 3064 deletions
|
@ -2,62 +2,64 @@ using System.Collections.Generic;
|
|||
using System.Linq;
|
||||
using NzbDrone.Core.DecisionEngine.Specifications.Search;
|
||||
using NzbDrone.Core.IndexerSearch.Definitions;
|
||||
using NzbDrone.Core.Model;
|
||||
using NzbDrone.Core.Parser;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
|
||||
namespace NzbDrone.Core.DecisionEngine
|
||||
{
|
||||
public interface IMakeDownloadDecision
|
||||
{
|
||||
IEnumerable<DownloadDecision> GetRssDecision(IEnumerable<IndexerParseResult> episodeParseResults);
|
||||
IEnumerable<DownloadDecision> GetSearchDecision(IEnumerable<IndexerParseResult> episodeParseResult, SearchDefinitionBase searchDefinitionBase);
|
||||
IEnumerable<DownloadDecision> GetRssDecision(IEnumerable<ReportInfo> reports);
|
||||
IEnumerable<DownloadDecision> GetSearchDecision(IEnumerable<ReportInfo> reports, SearchDefinitionBase searchDefinitionBase);
|
||||
}
|
||||
|
||||
public class DownloadDecisionMaker : IMakeDownloadDecision
|
||||
{
|
||||
private readonly IEnumerable<IRejectWithReason> _specifications;
|
||||
private readonly IParsingService _parsingService;
|
||||
|
||||
public DownloadDecisionMaker(IEnumerable<IRejectWithReason> specifications)
|
||||
public DownloadDecisionMaker(IEnumerable<IRejectWithReason> specifications, IParsingService parsingService)
|
||||
{
|
||||
_specifications = specifications;
|
||||
_parsingService = parsingService;
|
||||
}
|
||||
|
||||
public IEnumerable<DownloadDecision> GetRssDecision(IEnumerable<IndexerParseResult> episodeParseResults)
|
||||
public IEnumerable<DownloadDecision> GetRssDecision(IEnumerable<ReportInfo> reports)
|
||||
{
|
||||
foreach (var parseResult in episodeParseResults)
|
||||
foreach (var report in reports)
|
||||
{
|
||||
parseResult.Decision = new DownloadDecision(parseResult, GetGeneralRejectionReasons(parseResult).ToArray());
|
||||
yield return parseResult.Decision;
|
||||
var parseResult = _parsingService.Map(report);
|
||||
yield return new DownloadDecision(parseResult, GetGeneralRejectionReasons(parseResult).ToArray());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public IEnumerable<DownloadDecision> GetSearchDecision(IEnumerable<IndexerParseResult> episodeParseResults, SearchDefinitionBase searchDefinitionBase)
|
||||
public IEnumerable<DownloadDecision> GetSearchDecision(IEnumerable<ReportInfo> reports, SearchDefinitionBase searchDefinitionBase)
|
||||
{
|
||||
foreach (var parseResult in episodeParseResults)
|
||||
foreach (var report in reports)
|
||||
{
|
||||
var parseResult = _parsingService.Map(report);
|
||||
var generalReasons = GetGeneralRejectionReasons(parseResult);
|
||||
var searchReasons = GetSearchRejectionReasons(parseResult, searchDefinitionBase);
|
||||
|
||||
parseResult.Decision = new DownloadDecision(parseResult, generalReasons.Union(searchReasons).ToArray());
|
||||
|
||||
yield return parseResult.Decision;
|
||||
yield return new DownloadDecision(parseResult, generalReasons.Union(searchReasons).ToArray());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private IEnumerable<string> GetGeneralRejectionReasons(IndexerParseResult indexerParseResult)
|
||||
private IEnumerable<string> GetGeneralRejectionReasons(RemoteEpisode report)
|
||||
{
|
||||
return _specifications
|
||||
.OfType<IDecisionEngineSpecification>()
|
||||
.Where(spec => !spec.IsSatisfiedBy(indexerParseResult))
|
||||
.Where(spec => !spec.IsSatisfiedBy(report))
|
||||
.Select(spec => spec.RejectionReason);
|
||||
}
|
||||
|
||||
private IEnumerable<string> GetSearchRejectionReasons(IndexerParseResult indexerParseResult, SearchDefinitionBase searchDefinitionBase)
|
||||
private IEnumerable<string> GetSearchRejectionReasons(RemoteEpisode report, SearchDefinitionBase searchDefinitionBase)
|
||||
{
|
||||
return _specifications
|
||||
.OfType<IDecisionEngineSearchSpecification>()
|
||||
.Where(spec => !spec.IsSatisfiedBy(indexerParseResult, searchDefinitionBase))
|
||||
.Where(spec => !spec.IsSatisfiedBy(report, searchDefinitionBase))
|
||||
.Select(spec => spec.RejectionReason);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue