2011-02-03 02:07:36 +01:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2011-02-04 03:58:02 +01:00
|
|
|
|
using NLog;
|
2011-02-03 02:07:36 +01:00
|
|
|
|
using NzbDrone.Core.Repository.Quality;
|
|
|
|
|
using SubSonic.Repository;
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Providers
|
|
|
|
|
{
|
2011-04-08 06:03:46 +02:00
|
|
|
|
public class QualityProvider
|
2011-02-03 02:07:36 +01:00
|
|
|
|
{
|
2011-02-04 03:58:02 +01:00
|
|
|
|
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
2011-04-26 02:28:33 +02:00
|
|
|
|
private readonly IRepository _repository;
|
2011-02-03 02:07:36 +01:00
|
|
|
|
|
2011-04-08 08:50:30 +02:00
|
|
|
|
public QualityProvider()
|
|
|
|
|
{
|
|
|
|
|
}
|
2011-04-08 06:03:46 +02:00
|
|
|
|
|
2011-04-26 02:28:33 +02:00
|
|
|
|
public QualityProvider(IRepository repository)
|
2011-02-03 02:07:36 +01:00
|
|
|
|
{
|
2011-04-26 02:28:33 +02:00
|
|
|
|
_repository = repository;
|
2011-02-03 02:07:36 +01:00
|
|
|
|
}
|
|
|
|
|
|
2011-04-22 02:30:19 +02:00
|
|
|
|
public virtual int Add(QualityProfile profile)
|
2011-02-03 02:07:36 +01:00
|
|
|
|
{
|
2011-04-26 02:28:33 +02:00
|
|
|
|
return Convert.ToInt32(_repository.Add(profile));
|
2011-02-03 02:07:36 +01:00
|
|
|
|
}
|
|
|
|
|
|
2011-04-08 06:03:46 +02:00
|
|
|
|
public virtual void Update(QualityProfile profile)
|
2011-02-03 02:07:36 +01:00
|
|
|
|
{
|
2011-04-26 02:28:33 +02:00
|
|
|
|
if (!_repository.Exists<QualityProfile>(q => q.QualityProfileId == profile.QualityProfileId))
|
2011-02-03 02:07:36 +01:00
|
|
|
|
{
|
2011-02-04 03:58:02 +01:00
|
|
|
|
Logger.Error("Unable to update non-existing profile");
|
|
|
|
|
throw new InvalidOperationException("Unable to update non-existing profile");
|
2011-02-03 02:07:36 +01:00
|
|
|
|
}
|
|
|
|
|
|
2011-04-26 02:28:33 +02:00
|
|
|
|
_repository.Update(profile);
|
2011-02-03 02:07:36 +01:00
|
|
|
|
}
|
|
|
|
|
|
2011-04-08 06:03:46 +02:00
|
|
|
|
public virtual void Delete(int profileId)
|
2011-02-03 02:07:36 +01:00
|
|
|
|
{
|
2011-04-26 02:28:33 +02:00
|
|
|
|
_repository.Delete<QualityProfile>(profileId);
|
2011-02-03 02:07:36 +01:00
|
|
|
|
}
|
|
|
|
|
|
2011-04-08 06:03:46 +02:00
|
|
|
|
public virtual List<QualityProfile> GetAllProfiles()
|
2011-02-03 02:07:36 +01:00
|
|
|
|
{
|
2011-04-26 02:28:33 +02:00
|
|
|
|
var profiles = _repository.All<QualityProfile>().ToList();
|
2011-02-03 02:07:36 +01:00
|
|
|
|
|
|
|
|
|
return profiles;
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-08 06:03:46 +02:00
|
|
|
|
public virtual QualityProfile Find(int profileId)
|
2011-02-05 07:07:25 +01:00
|
|
|
|
{
|
2011-04-26 02:28:33 +02:00
|
|
|
|
return _repository.Single<QualityProfile>(q => q.QualityProfileId == profileId);
|
2011-02-05 07:07:25 +01:00
|
|
|
|
}
|
2011-06-13 05:45:22 +02:00
|
|
|
|
|
|
|
|
|
public virtual void SetupDefaultProfiles()
|
|
|
|
|
{
|
|
|
|
|
Logger.Info("Setting up default quality profiles");
|
|
|
|
|
|
|
|
|
|
var profiles = GetAllProfiles();
|
|
|
|
|
|
|
|
|
|
var sd = new QualityProfile { Name = "SD", Allowed = new List<QualityTypes> { QualityTypes.SDTV, QualityTypes.DVD }, Cutoff = QualityTypes.SDTV };
|
|
|
|
|
|
|
|
|
|
var hd = new QualityProfile
|
|
|
|
|
{
|
|
|
|
|
Name = "HD",
|
|
|
|
|
Allowed = new List<QualityTypes> { QualityTypes.HDTV, QualityTypes.WEBDL, QualityTypes.Bluray720p },
|
|
|
|
|
Cutoff = QualityTypes.HDTV
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//Add or Update SD
|
|
|
|
|
Logger.Debug(String.Format("Checking for default QualityProfile: {0}", sd.Name));
|
|
|
|
|
var sdDb = profiles.Where(p => p.Name == sd.Name).FirstOrDefault();
|
|
|
|
|
if (sdDb == null)
|
|
|
|
|
{
|
|
|
|
|
Logger.Debug(String.Format("Adding new default QualityProfile: {0}", sd.Name));
|
|
|
|
|
Add(sd);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Add or Update HD
|
|
|
|
|
Logger.Debug(String.Format("Checking for default QualityProfile: {0}", hd.Name));
|
|
|
|
|
var hdDb = profiles.Where(p => p.Name == hd.Name).FirstOrDefault();
|
|
|
|
|
if (hdDb == null)
|
|
|
|
|
{
|
|
|
|
|
Logger.Debug(String.Format("Adding new default QualityProfile: {0}", hd.Name));
|
|
|
|
|
Add(hd);
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-02-03 02:07:36 +01:00
|
|
|
|
}
|
2011-04-10 04:44:01 +02:00
|
|
|
|
}
|