2017-10-17 04:05:03 +00:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
using NzbDrone.Core.Datastore;
|
|
|
|
using NzbDrone.Core.Profiles.Qualities;
|
|
|
|
using NzbDrone.Core.Qualities;
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Music
|
|
|
|
{
|
|
|
|
public interface IAlbumCutoffService
|
|
|
|
{
|
|
|
|
PagingSpec<Album> AlbumsWhereCutoffUnmet(PagingSpec<Album> pagingSpec);
|
|
|
|
}
|
|
|
|
|
|
|
|
public class AlbumCutoffService : IAlbumCutoffService
|
|
|
|
{
|
|
|
|
private readonly IAlbumRepository _albumRepository;
|
2022-06-04 23:00:21 +00:00
|
|
|
private readonly IQualityProfileService _profileService;
|
2017-10-17 04:05:03 +00:00
|
|
|
|
2022-06-04 23:00:21 +00:00
|
|
|
public AlbumCutoffService(IAlbumRepository albumRepository, IQualityProfileService profileService)
|
2017-10-17 04:05:03 +00:00
|
|
|
{
|
|
|
|
_albumRepository = albumRepository;
|
|
|
|
_profileService = profileService;
|
|
|
|
}
|
|
|
|
|
|
|
|
public PagingSpec<Album> AlbumsWhereCutoffUnmet(PagingSpec<Album> pagingSpec)
|
|
|
|
{
|
|
|
|
var qualitiesBelowCutoff = new List<QualitiesBelowCutoff>();
|
|
|
|
var profiles = _profileService.All();
|
|
|
|
|
2022-11-22 01:51:00 +00:00
|
|
|
// Get all items less than the cutoff
|
2017-10-17 04:05:03 +00:00
|
|
|
foreach (var profile in profiles)
|
|
|
|
{
|
2017-11-16 02:24:33 +00:00
|
|
|
var cutoffIndex = profile.GetIndex(profile.Cutoff);
|
|
|
|
var belowCutoff = profile.Items.Take(cutoffIndex.Index).ToList();
|
2017-10-17 04:05:03 +00:00
|
|
|
|
|
|
|
if (belowCutoff.Any())
|
|
|
|
{
|
2017-11-16 02:24:33 +00:00
|
|
|
qualitiesBelowCutoff.Add(new QualitiesBelowCutoff(profile.Id, belowCutoff.SelectMany(i => i.GetQualities().Select(q => q.Id))));
|
2017-10-17 04:05:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-02 11:50:09 +00:00
|
|
|
return _albumRepository.AlbumsWhereCutoffUnmet(pagingSpec, qualitiesBelowCutoff);
|
2017-10-17 04:05:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|