Lidarr/src/NzbDrone.Core/DecisionEngine/DownloadDecisionPriorizatio...

35 lines
1.3 KiB
C#
Raw Normal View History

2017-09-04 02:20:56 +00:00
using System.Linq;
using System.Collections.Generic;
using NzbDrone.Core.Profiles.Delay;
2017-09-04 02:20:56 +00:00
using NzbDrone.Core.Languages;
namespace NzbDrone.Core.DecisionEngine
{
public interface IPrioritizeDownloadDecision
{
List<DownloadDecision> PrioritizeDecisions(List<DownloadDecision> decisions);
}
public class DownloadDecisionPriorizationService : IPrioritizeDownloadDecision
{
private readonly IDelayProfileService _delayProfileService;
public DownloadDecisionPriorizationService(IDelayProfileService delayProfileService)
{
_delayProfileService = delayProfileService;
}
public List<DownloadDecision> PrioritizeDecisions(List<DownloadDecision> decisions)
{
return decisions.Where(c => c.RemoteAlbum.Artist != null)
.GroupBy(c => c.RemoteAlbum.Artist.Id, (artistId, downloadDecisions) =>
{
2016-04-08 20:23:09 +00:00
return downloadDecisions.OrderByDescending(decision => decision, new DownloadDecisionComparer(_delayProfileService));
})
.SelectMany(c => c)
.Union(decisions.Where(c => c.RemoteAlbum.Artist == null))
.ToList();
}
}
}