2019-06-11 02:59:39 +00:00
|
|
|
using System.Collections.Generic;
|
2017-02-10 05:15:41 +00:00
|
|
|
using System.Linq;
|
|
|
|
using NLog;
|
|
|
|
using NzbDrone.Core.Datastore;
|
|
|
|
using NzbDrone.Core.Profiles;
|
|
|
|
using NzbDrone.Core.Qualities;
|
|
|
|
|
2018-03-14 20:41:36 +00:00
|
|
|
namespace NzbDrone.Core.Movies
|
2017-02-10 05:15:41 +00:00
|
|
|
{
|
|
|
|
public interface IMovieCutoffService
|
|
|
|
{
|
|
|
|
PagingSpec<Movie> MoviesWhereCutoffUnmet(PagingSpec<Movie> pagingSpec);
|
|
|
|
}
|
|
|
|
|
|
|
|
public class MovieCutoffService : IMovieCutoffService
|
|
|
|
{
|
|
|
|
private readonly IMovieRepository _movieRepository;
|
|
|
|
private readonly IProfileService _profileService;
|
|
|
|
|
|
|
|
public MovieCutoffService(IMovieRepository movieRepository, IProfileService profileService, Logger logger)
|
|
|
|
{
|
|
|
|
_movieRepository = movieRepository;
|
|
|
|
_profileService = profileService;
|
|
|
|
}
|
|
|
|
|
|
|
|
public PagingSpec<Movie> MoviesWhereCutoffUnmet(PagingSpec<Movie> pagingSpec)
|
|
|
|
{
|
|
|
|
var qualitiesBelowCutoff = new List<QualitiesBelowCutoff>();
|
|
|
|
var profiles = _profileService.All();
|
|
|
|
|
|
|
|
//Get all items less than the cutoff
|
|
|
|
foreach (var profile in profiles)
|
|
|
|
{
|
2022-05-24 03:52:27 +00:00
|
|
|
var cutoff = profile.UpgradeAllowed ? profile.Cutoff : profile.FirststAllowedQuality().Id;
|
|
|
|
var cutoffIndex = profile.GetIndex(cutoff);
|
2019-06-11 02:59:39 +00:00
|
|
|
var belowCutoff = profile.Items.Take(cutoffIndex.Index).ToList();
|
2017-02-10 05:15:41 +00:00
|
|
|
|
|
|
|
if (belowCutoff.Any())
|
|
|
|
{
|
2019-06-11 02:59:39 +00:00
|
|
|
qualitiesBelowCutoff.Add(new QualitiesBelowCutoff(profile.Id, belowCutoff.SelectMany(i => i.GetQualities().Select(q => q.Id))));
|
2017-02-10 05:15:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return _movieRepository.MoviesWhereCutoffUnmet(pagingSpec, qualitiesBelowCutoff);
|
|
|
|
}
|
|
|
|
}
|
2018-08-05 14:28:05 +00:00
|
|
|
}
|