1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-11-01 00:12:30 +01:00
Sonarr/NzbDrone.Core/DecisionEngine/DownloadDecision.cs

39 lines
1.1 KiB
C#
Raw Normal View History

2013-03-07 02:51:47 +01:00
using System.Collections.Generic;
using System.Linq;
2013-04-07 09:30:37 +02:00
using NzbDrone.Core.Model;
2013-03-07 02:51:47 +01:00
namespace NzbDrone.Core.DecisionEngine
{
public class DownloadDecision
{
public IndexerParseResult ParseResult { get; private set; }
2013-03-07 02:51:47 +01:00
public IEnumerable<string> Rejections { get; private set; }
2013-04-07 09:30:37 +02:00
2013-03-07 02:51:47 +01:00
public bool Approved
{
get
{
return !Rejections.Any();
}
}
public DownloadDecision(IndexerParseResult parseResult, params string[] rejections)
2013-03-07 02:51:47 +01:00
{
2013-04-07 09:30:37 +02:00
ParseResult = parseResult;
2013-03-07 02:51:47 +01:00
Rejections = rejections.ToList();
}
2013-04-07 09:30:37 +02:00
public static IndexerParseResult PickBestReport(IEnumerable<DownloadDecision> downloadDecisions)
2013-04-07 09:30:37 +02: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 02:51:47 +01:00
}
}