mirror of
https://github.com/Radarr/Radarr.git
synced 2026-04-25 22:37:27 -04:00
38 lines
1.7 KiB
C#
38 lines
1.7 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using NzbDrone.Core.Configuration;
|
|
using NzbDrone.Core.Parser;
|
|
using NzbDrone.Core.Profiles.Delay;
|
|
|
|
namespace NzbDrone.Core.DecisionEngine
|
|
{
|
|
public interface IPrioritizeDownloadDecision
|
|
{
|
|
List<DownloadDecision> PrioritizeDecisionsForMovies(List<DownloadDecision> decisions);
|
|
}
|
|
|
|
public class DownloadDecisionPriorizationService : IPrioritizeDownloadDecision
|
|
{
|
|
private readonly IConfigService _configService;
|
|
private readonly IDelayProfileService _delayProfileService;
|
|
|
|
public DownloadDecisionPriorizationService(IConfigService configService, IDelayProfileService delayProfileService)
|
|
{
|
|
_configService = configService;
|
|
_delayProfileService = delayProfileService;
|
|
}
|
|
|
|
public List<DownloadDecision> PrioritizeDecisionsForMovies(List<DownloadDecision> decisions)
|
|
{
|
|
return decisions.Where(c => c.RemoteMovie.MappingResult == MappingResultType.Success || c.RemoteMovie.MappingResult == MappingResultType.SuccessLenientMapping)
|
|
.GroupBy(c => c.RemoteMovie.Movie.Id, (movieId, downloadDecisions) =>
|
|
{
|
|
return downloadDecisions.OrderByDescending(decision => decision, new DownloadDecisionComparer(_configService, _delayProfileService));
|
|
})
|
|
.SelectMany(c => c)
|
|
.Union(decisions.Where(c => c.RemoteMovie.MappingResult != MappingResultType.Success || c.RemoteMovie.MappingResult != MappingResultType.SuccessLenientMapping))
|
|
.ToList();
|
|
}
|
|
}
|
|
}
|