2016-04-08 20:23:09 +00:00
|
|
|
|
using System.Linq;
|
2014-07-15 19:03:53 +00:00
|
|
|
|
using System.Collections.Generic;
|
2014-11-24 00:07:46 +00:00
|
|
|
|
using NzbDrone.Core.Profiles.Delay;
|
2014-07-15 19:03:53 +00:00
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.DecisionEngine
|
|
|
|
|
{
|
|
|
|
|
public interface IPrioritizeDownloadDecision
|
|
|
|
|
{
|
|
|
|
|
List<DownloadDecision> PrioritizeDecisions(List<DownloadDecision> decisions);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class DownloadDecisionPriorizationService : IPrioritizeDownloadDecision
|
|
|
|
|
{
|
2014-11-24 00:07:46 +00:00
|
|
|
|
private readonly IDelayProfileService _delayProfileService;
|
|
|
|
|
|
|
|
|
|
public DownloadDecisionPriorizationService(IDelayProfileService delayProfileService)
|
|
|
|
|
{
|
|
|
|
|
_delayProfileService = delayProfileService;
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-15 19:03:53 +00:00
|
|
|
|
public List<DownloadDecision> PrioritizeDecisions(List<DownloadDecision> decisions)
|
|
|
|
|
{
|
2014-11-24 00:07:46 +00:00
|
|
|
|
return decisions.Where(c => c.RemoteEpisode.Series != null)
|
2016-04-08 20:23:09 +00:00
|
|
|
|
.GroupBy(c => c.RemoteEpisode.Series.Id, (seriesId, downloadDecisions) =>
|
2014-11-24 00:07:46 +00:00
|
|
|
|
{
|
2016-04-08 20:23:09 +00:00
|
|
|
|
return downloadDecisions.OrderByDescending(decision => decision, new DownloadDecisionComparer(_delayProfileService));
|
2014-11-24 00:07:46 +00:00
|
|
|
|
})
|
|
|
|
|
.SelectMany(c => c)
|
|
|
|
|
.Union(decisions.Where(c => c.RemoteEpisode.Series == null))
|
|
|
|
|
.ToList();
|
|
|
|
|
}
|
2014-07-15 19:03:53 +00:00
|
|
|
|
}
|
|
|
|
|
}
|