2017-09-04 02:20:56 +00:00
|
|
|
using System.Collections.Generic;
|
2014-06-08 08:22:55 +00:00
|
|
|
using System.Linq;
|
|
|
|
using NLog;
|
|
|
|
using NzbDrone.Core.Lifecycle;
|
|
|
|
using NzbDrone.Core.Messaging.Events;
|
|
|
|
using NzbDrone.Core.Qualities;
|
2017-06-03 01:25:34 +00:00
|
|
|
using NzbDrone.Core.Music;
|
2014-06-08 08:22:55 +00:00
|
|
|
|
2017-09-04 02:20:56 +00:00
|
|
|
namespace NzbDrone.Core.Profiles.Qualities
|
2014-06-08 08:22:55 +00:00
|
|
|
{
|
|
|
|
public interface IProfileService
|
|
|
|
{
|
|
|
|
Profile Add(Profile profile);
|
|
|
|
void Update(Profile profile);
|
|
|
|
void Delete(int id);
|
|
|
|
List<Profile> All();
|
|
|
|
Profile Get(int id);
|
2015-12-05 10:22:22 +00:00
|
|
|
bool Exists(int id);
|
2014-06-08 08:22:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public class ProfileService : IProfileService, IHandle<ApplicationStartedEvent>
|
|
|
|
{
|
|
|
|
private readonly IProfileRepository _profileRepository;
|
2017-06-03 01:25:34 +00:00
|
|
|
private readonly IArtistService _artistService;
|
2014-06-08 08:22:55 +00:00
|
|
|
private readonly Logger _logger;
|
|
|
|
|
2017-06-03 01:25:34 +00:00
|
|
|
public ProfileService(IProfileRepository profileRepository, IArtistService artistService, Logger logger)
|
2014-06-08 08:22:55 +00:00
|
|
|
{
|
|
|
|
_profileRepository = profileRepository;
|
2017-06-03 01:25:34 +00:00
|
|
|
_artistService = artistService;
|
2014-06-08 08:22:55 +00:00
|
|
|
_logger = logger;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Profile Add(Profile profile)
|
|
|
|
{
|
|
|
|
return _profileRepository.Insert(profile);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Update(Profile profile)
|
|
|
|
{
|
|
|
|
_profileRepository.Update(profile);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Delete(int id)
|
|
|
|
{
|
2017-06-03 01:25:34 +00:00
|
|
|
if (_artistService.GetAllArtists().Any(c => c.ProfileId == id))
|
2014-06-08 08:22:55 +00:00
|
|
|
{
|
|
|
|
throw new ProfileInUseException(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
_profileRepository.Delete(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
public List<Profile> All()
|
|
|
|
{
|
|
|
|
return _profileRepository.All().ToList();
|
|
|
|
}
|
|
|
|
|
|
|
|
public Profile Get(int id)
|
|
|
|
{
|
|
|
|
return _profileRepository.Get(id);
|
|
|
|
}
|
|
|
|
|
2015-12-05 10:22:22 +00:00
|
|
|
public bool Exists(int id)
|
|
|
|
{
|
|
|
|
return _profileRepository.Exists(id);
|
|
|
|
}
|
|
|
|
|
2014-06-08 08:22:55 +00:00
|
|
|
private Profile AddDefaultProfile(string name, Quality cutoff, params Quality[] allowed)
|
|
|
|
{
|
|
|
|
var items = Quality.DefaultQualityDefinitions
|
|
|
|
.OrderBy(v => v.Weight)
|
|
|
|
.Select(v => new ProfileQualityItem { Quality = v.Quality, Allowed = allowed.Contains(v.Quality) })
|
|
|
|
.ToList();
|
|
|
|
|
2017-09-04 02:20:56 +00:00
|
|
|
var profile = new Profile { Name = name, Cutoff = cutoff, Items = items};
|
2014-06-08 08:22:55 +00:00
|
|
|
|
|
|
|
return Add(profile);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Handle(ApplicationStartedEvent message)
|
|
|
|
{
|
|
|
|
if (All().Any()) return;
|
|
|
|
|
|
|
|
_logger.Info("Setting up default quality profiles");
|
|
|
|
|
2017-05-08 02:07:19 +00:00
|
|
|
AddDefaultProfile("Any",
|
2017-10-19 02:57:11 +00:00
|
|
|
Quality.Unknown,
|
|
|
|
Quality.Unknown,
|
2017-07-03 18:39:06 +00:00
|
|
|
Quality.MP3_192,
|
|
|
|
Quality.MP3_256,
|
|
|
|
Quality.MP3_320,
|
|
|
|
Quality.MP3_512,
|
|
|
|
Quality.MP3_VBR,
|
2017-05-08 02:07:19 +00:00
|
|
|
Quality.FLAC);
|
|
|
|
|
|
|
|
AddDefaultProfile("Lossless",
|
2017-10-19 02:57:11 +00:00
|
|
|
Quality.FLAC,
|
2017-05-08 02:07:19 +00:00
|
|
|
Quality.FLAC);
|
|
|
|
|
|
|
|
AddDefaultProfile("Standard",
|
2017-10-19 02:57:11 +00:00
|
|
|
Quality.MP3_192,
|
2017-07-03 18:39:06 +00:00
|
|
|
Quality.MP3_192,
|
|
|
|
Quality.MP3_256,
|
|
|
|
Quality.MP3_320);
|
2014-06-08 08:22:55 +00:00
|
|
|
}
|
|
|
|
}
|
2017-09-04 02:20:56 +00:00
|
|
|
}
|