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

39 lines
1.1 KiB
C#
Raw Normal View History

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