2013-04-10 02:47:04 +02:00
|
|
|
|
using System.Collections.Generic;
|
2013-02-27 04:19:22 +01:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using NLog;
|
2013-04-24 03:56:00 +02:00
|
|
|
|
using NzbDrone.Common.Messaging;
|
2013-02-27 04:19:22 +01:00
|
|
|
|
using NzbDrone.Core.Lifecycle;
|
2013-07-06 01:53:05 +02:00
|
|
|
|
using NzbDrone.Core.Tv;
|
2013-03-02 19:25:39 +01:00
|
|
|
|
|
2013-02-27 04:19:22 +01:00
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Qualities
|
|
|
|
|
{
|
|
|
|
|
public interface IQualityProfileService
|
|
|
|
|
{
|
|
|
|
|
QualityProfile Add(QualityProfile profile);
|
|
|
|
|
void Update(QualityProfile profile);
|
|
|
|
|
void Delete(int id);
|
|
|
|
|
List<QualityProfile> All();
|
|
|
|
|
QualityProfile Get(int id);
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-10 02:47:04 +02:00
|
|
|
|
public class QualityProfileService : IQualityProfileService, IHandle<ApplicationStartedEvent>
|
2013-02-27 04:19:22 +01:00
|
|
|
|
{
|
|
|
|
|
private readonly IQualityProfileRepository _qualityProfileRepository;
|
2013-07-06 01:53:05 +02:00
|
|
|
|
private readonly ISeriesService _seriesService;
|
2013-02-27 04:19:22 +01:00
|
|
|
|
private readonly Logger _logger;
|
|
|
|
|
|
2013-07-06 01:53:05 +02:00
|
|
|
|
public QualityProfileService(IQualityProfileRepository qualityProfileRepository, ISeriesService seriesService, Logger logger)
|
2013-02-27 04:19:22 +01:00
|
|
|
|
{
|
|
|
|
|
_qualityProfileRepository = qualityProfileRepository;
|
2013-07-06 01:53:05 +02:00
|
|
|
|
_seriesService = seriesService;
|
2013-02-27 04:19:22 +01:00
|
|
|
|
_logger = logger;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public QualityProfile Add(QualityProfile profile)
|
|
|
|
|
{
|
|
|
|
|
return _qualityProfileRepository.Insert(profile);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Update(QualityProfile profile)
|
|
|
|
|
{
|
|
|
|
|
_qualityProfileRepository.Update(profile);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Delete(int id)
|
|
|
|
|
{
|
2013-07-06 01:53:05 +02:00
|
|
|
|
if (_seriesService.GetAllSeries().Any(c => c.QualityProfileId == id))
|
|
|
|
|
{
|
|
|
|
|
throw new QualityProfileInUseException(id);
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-27 04:19:22 +01:00
|
|
|
|
_qualityProfileRepository.Delete(id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<QualityProfile> All()
|
|
|
|
|
{
|
|
|
|
|
return _qualityProfileRepository.All().ToList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public QualityProfile Get(int id)
|
|
|
|
|
{
|
|
|
|
|
return _qualityProfileRepository.Get(id);
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-10 02:47:04 +02:00
|
|
|
|
public void Handle(ApplicationStartedEvent message)
|
2013-02-27 04:19:22 +01:00
|
|
|
|
{
|
2013-02-27 09:21:53 +01:00
|
|
|
|
if (All().Any()) return;
|
2013-02-27 04:19:22 +01:00
|
|
|
|
|
|
|
|
|
_logger.Info("Setting up default quality profiles");
|
|
|
|
|
|
2013-07-04 05:47:58 +02:00
|
|
|
|
var sd = new QualityProfile
|
2013-07-06 01:53:05 +02:00
|
|
|
|
{
|
|
|
|
|
Name = "SD",
|
2013-07-04 05:47:58 +02:00
|
|
|
|
Allowed = new List<Quality>
|
|
|
|
|
{
|
|
|
|
|
Quality.SDTV,
|
|
|
|
|
Quality.WEBDL480p,
|
|
|
|
|
Quality.DVD
|
2013-07-06 01:53:05 +02:00
|
|
|
|
},
|
2013-07-04 05:47:58 +02:00
|
|
|
|
Cutoff = Quality.SDTV
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var hd720p = new QualityProfile
|
|
|
|
|
{
|
|
|
|
|
Name = "HD 720p",
|
|
|
|
|
Allowed = new List<Quality>
|
|
|
|
|
{
|
|
|
|
|
Quality.HDTV720p,
|
|
|
|
|
Quality.WEBDL720p,
|
|
|
|
|
Quality.Bluray720p
|
|
|
|
|
},
|
|
|
|
|
Cutoff = Quality.HDTV720p
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var hd1080p = new QualityProfile
|
|
|
|
|
{
|
|
|
|
|
Name = "HD 1080p",
|
|
|
|
|
Allowed = new List<Quality>
|
|
|
|
|
{
|
|
|
|
|
Quality.HDTV1080p,
|
|
|
|
|
Quality.WEBDL1080p,
|
|
|
|
|
Quality.Bluray1080p
|
|
|
|
|
},
|
|
|
|
|
Cutoff = Quality.HDTV1080p
|
|
|
|
|
};
|
2013-02-27 04:19:22 +01:00
|
|
|
|
|
2013-07-04 05:47:58 +02:00
|
|
|
|
var hdAll = new QualityProfile
|
2013-02-27 04:19:22 +01:00
|
|
|
|
{
|
2013-07-04 05:47:58 +02:00
|
|
|
|
Name = "HD - All",
|
|
|
|
|
Allowed = new List<Quality>
|
|
|
|
|
{
|
|
|
|
|
Quality.HDTV720p,
|
|
|
|
|
Quality.WEBDL720p,
|
|
|
|
|
Quality.Bluray720p,
|
|
|
|
|
Quality.HDTV1080p,
|
|
|
|
|
Quality.WEBDL1080p,
|
|
|
|
|
Quality.Bluray1080p
|
|
|
|
|
},
|
2013-02-27 04:19:22 +01:00
|
|
|
|
Cutoff = Quality.HDTV720p
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Add(sd);
|
2013-07-04 05:47:58 +02:00
|
|
|
|
Add(hd720p);
|
|
|
|
|
Add(hd1080p);
|
|
|
|
|
Add(hdAll);
|
2013-02-27 04:19:22 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|