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
|
|
|
|
{
|
2013-04-07 07:30:37 +00:00
|
|
|
public EpisodeParseResult 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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-07 07:30:37 +00:00
|
|
|
public DownloadDecision(EpisodeParseResult 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 EpisodeParseResult PickBestReport(IEnumerable<DownloadDecision> downloadDecisions)
|
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|