sonarr-repo-only/NzbDrone.Core/DecisionEngine/DownloadDecision.cs

39 lines
1.1 KiB
C#
Raw Normal View History

2013-03-07 01:51:47 +00:00
using System.Collections.Generic;
using System.Linq;
2013-04-07 07:30:37 +00:00
using NzbDrone.Core.Model;
2013-03-07 01:51:47 +00:00
namespace NzbDrone.Core.DecisionEngine
{
public class DownloadDecision
{
public IndexerParseResult ParseResult { get; private set; }
2013-03-07 01:51:47 +00:00
public IEnumerable<string> Rejections { get; private set; }
2013-04-07 07:30:37 +00:00
2013-03-07 01:51:47 +00:00
public bool Approved
{
get
{
return !Rejections.Any();
}
}
public DownloadDecision(IndexerParseResult parseResult, params string[] rejections)
2013-03-07 01:51:47 +00:00
{
2013-04-07 07:30:37 +00:00
ParseResult = parseResult;
2013-03-07 01:51:47 +00:00
Rejections = rejections.ToList();
}
2013-04-07 07:30:37 +00:00
public static IndexerParseResult PickBestReport(IEnumerable<DownloadDecision> downloadDecisions)
2013-04-07 07:30:37 +00:00
{
var reports = downloadDecisions
.Where(c => c.Approved)
.Select(c => c.ParseResult)
.OrderByDescending(c => c.Quality)
.ThenBy(c => c.EpisodeNumbers.MinOrDefault())
.ThenBy(c => c.Age);
return reports.SingleOrDefault();
}
2013-03-07 01:51:47 +00:00
}
}