2014-02-23 03:19:05 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using NLog;
|
|
|
|
|
using NzbDrone.Core.Datastore;
|
2014-06-08 08:22:55 +00:00
|
|
|
|
using NzbDrone.Core.Profiles;
|
2014-02-23 03:19:05 +00:00
|
|
|
|
using NzbDrone.Core.Qualities;
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Tv
|
|
|
|
|
{
|
|
|
|
|
public interface IEpisodeCutoffService
|
|
|
|
|
{
|
|
|
|
|
PagingSpec<Episode> EpisodesWhereCutoffUnmet(PagingSpec<Episode> pagingSpec);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class EpisodeCutoffService : IEpisodeCutoffService
|
|
|
|
|
{
|
|
|
|
|
private readonly IEpisodeRepository _episodeRepository;
|
2014-06-08 08:22:55 +00:00
|
|
|
|
private readonly IProfileService _profileService;
|
2014-02-23 03:19:05 +00:00
|
|
|
|
private readonly Logger _logger;
|
|
|
|
|
|
2014-06-08 08:22:55 +00:00
|
|
|
|
public EpisodeCutoffService(IEpisodeRepository episodeRepository, IProfileService profileService, Logger logger)
|
2014-02-23 03:19:05 +00:00
|
|
|
|
{
|
|
|
|
|
_episodeRepository = episodeRepository;
|
2014-06-08 08:22:55 +00:00
|
|
|
|
_profileService = profileService;
|
2014-02-23 03:19:05 +00:00
|
|
|
|
_logger = logger;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public PagingSpec<Episode> EpisodesWhereCutoffUnmet(PagingSpec<Episode> pagingSpec)
|
|
|
|
|
{
|
|
|
|
|
var qualitiesBelowCutoff = new List<QualitiesBelowCutoff>();
|
2014-06-08 08:22:55 +00:00
|
|
|
|
var profiles = _profileService.All();
|
2014-02-23 03:19:05 +00:00
|
|
|
|
|
|
|
|
|
//Get all items less than the cutoff
|
2014-06-08 08:22:55 +00:00
|
|
|
|
foreach (var profile in profiles)
|
2014-02-23 03:19:05 +00:00
|
|
|
|
{
|
2014-06-08 08:22:55 +00:00
|
|
|
|
var cutoffIndex = profile.Items.FindIndex(v => v.Quality == profile.Cutoff);
|
|
|
|
|
var belowCutoff = profile.Items.Take(cutoffIndex).ToList();
|
2014-02-23 03:19:05 +00:00
|
|
|
|
|
|
|
|
|
if (belowCutoff.Any())
|
|
|
|
|
{
|
2014-06-08 08:22:55 +00:00
|
|
|
|
qualitiesBelowCutoff.Add(new QualitiesBelowCutoff(profile.Id, belowCutoff.Select(i => i.Quality.Id)));
|
2014-02-23 03:19:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return _episodeRepository.EpisodesWhereCutoffUnmet(pagingSpec, qualitiesBelowCutoff, false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|