2022-08-14 19:07:26 +00:00
|
|
|
using System.Collections.Generic;
|
2014-02-23 03:19:05 +00:00
|
|
|
using System.Linq;
|
|
|
|
using NLog;
|
|
|
|
using NzbDrone.Core.Datastore;
|
2015-07-12 16:44:33 +00:00
|
|
|
using NzbDrone.Core.Languages;
|
2021-08-03 04:43:28 +00:00
|
|
|
using NzbDrone.Core.Profiles.Qualities;
|
|
|
|
using NzbDrone.Core.Qualities;
|
2014-02-23 03:19:05 +00:00
|
|
|
|
|
|
|
namespace NzbDrone.Core.Tv
|
|
|
|
{
|
|
|
|
public interface IEpisodeCutoffService
|
|
|
|
{
|
|
|
|
PagingSpec<Episode> EpisodesWhereCutoffUnmet(PagingSpec<Episode> pagingSpec);
|
|
|
|
}
|
|
|
|
|
|
|
|
public class EpisodeCutoffService : IEpisodeCutoffService
|
|
|
|
{
|
|
|
|
private readonly IEpisodeRepository _episodeRepository;
|
2020-09-16 05:18:48 +00:00
|
|
|
private readonly IQualityProfileService _qualityProfileService;
|
2014-02-23 03:19:05 +00:00
|
|
|
|
2022-08-14 19:07:26 +00:00
|
|
|
public EpisodeCutoffService(IEpisodeRepository episodeRepository, IQualityProfileService qualityProfileService, Logger logger)
|
2014-02-23 03:19:05 +00:00
|
|
|
{
|
|
|
|
_episodeRepository = episodeRepository;
|
2020-09-16 05:18:48 +00:00
|
|
|
_qualityProfileService = qualityProfileService;
|
2014-02-23 03:19:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public PagingSpec<Episode> EpisodesWhereCutoffUnmet(PagingSpec<Episode> pagingSpec)
|
|
|
|
{
|
|
|
|
var qualitiesBelowCutoff = new List<QualitiesBelowCutoff>();
|
2015-07-12 16:44:33 +00:00
|
|
|
var languagesBelowCutoff = new List<LanguagesBelowCutoff>();
|
2020-09-16 05:18:48 +00:00
|
|
|
var profiles = _qualityProfileService.All();
|
2021-08-03 04:43:28 +00:00
|
|
|
|
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
|
|
|
{
|
2022-05-22 23:44:12 +00:00
|
|
|
var cutoff = profile.UpgradeAllowed ? profile.Cutoff : profile.FirststAllowedQuality().Id;
|
|
|
|
var cutoffIndex = profile.GetIndex(cutoff);
|
2017-06-18 17:02:20 +00:00
|
|
|
var belowCutoff = profile.Items.Take(cutoffIndex.Index).ToList();
|
|
|
|
|
2014-02-23 03:19:05 +00:00
|
|
|
if (belowCutoff.Any())
|
|
|
|
{
|
2017-06-18 17:02:20 +00:00
|
|
|
qualitiesBelowCutoff.Add(new QualitiesBelowCutoff(profile.Id, belowCutoff.SelectMany(i => i.GetQualities().Select(q => q.Id))));
|
2014-02-23 03:19:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-12 16:44:33 +00:00
|
|
|
return _episodeRepository.EpisodesWhereCutoffUnmet(pagingSpec, qualitiesBelowCutoff, languagesBelowCutoff, false);
|
2014-02-23 03:19:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|