diff --git a/src/NzbDrone.Api/Profiles/ProfileModule.cs b/src/NzbDrone.Api/Profiles/ProfileModule.cs index fdab96f9f..789446b6e 100644 --- a/src/NzbDrone.Api/Profiles/ProfileModule.cs +++ b/src/NzbDrone.Api/Profiles/ProfileModule.cs @@ -7,11 +7,11 @@ namespace NzbDrone.Api.Profiles { public class ProfileModule : SonarrRestModule { - private readonly IProfileService _profileService; + private readonly IQualityProfileService _qualityProfileService; - public ProfileModule(IProfileService profileService) + public ProfileModule(IQualityProfileService qualityProfileService) { - _profileService = profileService; + _qualityProfileService = qualityProfileService; SharedValidator.RuleFor(c => c.Name).NotEmpty(); SharedValidator.RuleFor(c => c.Cutoff).NotNull(); SharedValidator.RuleFor(c => c.Items).MustHaveAllowedQuality(); @@ -27,29 +27,29 @@ namespace NzbDrone.Api.Profiles { var model = resource.ToModel(); - return _profileService.Add(model).Id; + return _qualityProfileService.Add(model).Id; } private void DeleteProfile(int id) { - _profileService.Delete(id); + _qualityProfileService.Delete(id); } private void Update(ProfileResource resource) { var model = resource.ToModel(); - _profileService.Update(model); + _qualityProfileService.Update(model); } private ProfileResource GetById(int id) { - return _profileService.Get(id).ToResource(); + return _qualityProfileService.Get(id).ToResource(); } private List GetAll() { - return _profileService.All().ToResource(); + return _qualityProfileService.All().ToResource(); } } } diff --git a/src/NzbDrone.Core/Profiles/Qualities/QualityProfileService.cs b/src/NzbDrone.Core/Profiles/Qualities/QualityProfileService.cs index 28698115f..763d337b4 100644 --- a/src/NzbDrone.Core/Profiles/Qualities/QualityProfileService.cs +++ b/src/NzbDrone.Core/Profiles/Qualities/QualityProfileService.cs @@ -9,7 +9,7 @@ using NzbDrone.Core.Tv; namespace NzbDrone.Core.Profiles.Qualities { - public interface IProfileService + public interface IQualityProfileService { QualityProfile Add(QualityProfile profile); void Update(QualityProfile profile); @@ -20,7 +20,7 @@ namespace NzbDrone.Core.Profiles.Qualities QualityProfile GetDefaultProfile(string name, Quality cutoff = null, params Quality[] allowed); } - public class QualityProfileService : IProfileService, IHandle + public class QualityProfileService : IQualityProfileService, IHandle { private readonly IProfileRepository _profileRepository; private readonly IImportListFactory _importListFactory; diff --git a/src/NzbDrone.Core/Tv/EpisodeCutoffService.cs b/src/NzbDrone.Core/Tv/EpisodeCutoffService.cs index 4142fd80d..711082e70 100644 --- a/src/NzbDrone.Core/Tv/EpisodeCutoffService.cs +++ b/src/NzbDrone.Core/Tv/EpisodeCutoffService.cs @@ -17,13 +17,13 @@ namespace NzbDrone.Core.Tv public class EpisodeCutoffService : IEpisodeCutoffService { private readonly IEpisodeRepository _episodeRepository; - private readonly IProfileService _profileService; + private readonly IQualityProfileService _qualityProfileService; private readonly ILanguageProfileService _languageProfileService; - public EpisodeCutoffService(IEpisodeRepository episodeRepository, IProfileService profileService, ILanguageProfileService languageProfileService, Logger logger) + public EpisodeCutoffService(IEpisodeRepository episodeRepository, IQualityProfileService qualityProfileService, ILanguageProfileService languageProfileService, Logger logger) { _episodeRepository = episodeRepository; - _profileService = profileService; + _qualityProfileService = qualityProfileService; _languageProfileService = languageProfileService; } @@ -31,7 +31,7 @@ namespace NzbDrone.Core.Tv { var qualitiesBelowCutoff = new List(); var languagesBelowCutoff = new List(); - var profiles = _profileService.All(); + var profiles = _qualityProfileService.All(); var languageProfiles = _languageProfileService.All(); //Get all items less than the cutoff diff --git a/src/NzbDrone.Core/Validation/ProfileExistsValidator.cs b/src/NzbDrone.Core/Validation/ProfileExistsValidator.cs index d75c7cde8..8e90c965a 100644 --- a/src/NzbDrone.Core/Validation/ProfileExistsValidator.cs +++ b/src/NzbDrone.Core/Validation/ProfileExistsValidator.cs @@ -5,19 +5,19 @@ namespace NzbDrone.Core.Validation { public class ProfileExistsValidator : PropertyValidator { - private readonly IProfileService _profileService; + private readonly IQualityProfileService _qualityProfileService; - public ProfileExistsValidator(IProfileService profileService) + public ProfileExistsValidator(IQualityProfileService qualityProfileService) : base("QualityProfile does not exist") { - _profileService = profileService; + _qualityProfileService = qualityProfileService; } protected override bool IsValid(PropertyValidatorContext context) { if (context.PropertyValue == null) return true; - return _profileService.Exists((int)context.PropertyValue); + return _qualityProfileService.Exists((int)context.PropertyValue); } } } \ No newline at end of file diff --git a/src/Sonarr.Api.V3/Indexers/ReleaseModule.cs b/src/Sonarr.Api.V3/Indexers/ReleaseModule.cs index aa3c351c4..74d9c6822 100644 --- a/src/Sonarr.Api.V3/Indexers/ReleaseModule.cs +++ b/src/Sonarr.Api.V3/Indexers/ReleaseModule.cs @@ -12,6 +12,8 @@ using NzbDrone.Core.Indexers; using NzbDrone.Core.IndexerSearch; using NzbDrone.Core.Parser; using NzbDrone.Core.Parser.Model; +using NzbDrone.Core.Profiles.Languages; +using NzbDrone.Core.Profiles.Qualities; using NzbDrone.Core.Tv; using NzbDrone.Core.Validation; using HttpStatusCode = System.Net.HttpStatusCode; @@ -41,7 +43,10 @@ namespace Sonarr.Api.V3.Indexers IEpisodeService episodeService, IParsingService parsingService, ICacheManager cacheManager, - Logger logger) + ILanguageProfileService languageProfileService, + IQualityProfileService qualityProfileService, + Logger logger) : + base(languageProfileService, qualityProfileService) { _rssFetcherAndParser = rssFetcherAndParser; _nzbSearchService = nzbSearchService; diff --git a/src/Sonarr.Api.V3/Indexers/ReleaseModuleBase.cs b/src/Sonarr.Api.V3/Indexers/ReleaseModuleBase.cs index dede10f00..605861557 100644 --- a/src/Sonarr.Api.V3/Indexers/ReleaseModuleBase.cs +++ b/src/Sonarr.Api.V3/Indexers/ReleaseModuleBase.cs @@ -1,11 +1,23 @@ using System.Collections.Generic; using NzbDrone.Core.DecisionEngine; +using NzbDrone.Core.Profiles.Languages; +using NzbDrone.Core.Profiles.Qualities; using Sonarr.Http; namespace Sonarr.Api.V3.Indexers { public abstract class ReleaseModuleBase : SonarrRestModule { + private readonly LanguageProfile LANGUAGE_PROFILE; + private readonly QualityProfile QUALITY_PROFILE; + + public ReleaseModuleBase(ILanguageProfileService languageProfileService, + IQualityProfileService qualityProfileService) + { + LANGUAGE_PROFILE = languageProfileService.GetDefaultProfile(string.Empty); + QUALITY_PROFILE = qualityProfileService.GetDefaultProfile(string.Empty); + } + protected virtual List MapDecisions(IEnumerable decisions) { var result = new List(); @@ -26,17 +38,8 @@ namespace Sonarr.Api.V3.Indexers release.ReleaseWeight = initialWeight; - if (decision.RemoteEpisode.Series != null) - { - release.QualityWeight = decision.RemoteEpisode - .Series - .QualityProfile.Value.GetIndex(release.Quality.Quality).Index * 100; - - release.LanguageWeight = decision.RemoteEpisode - .Series - .LanguageProfile.Value - .Languages.FindIndex(v => v.Language == release.Language) * 100; - } + release.QualityWeight = QUALITY_PROFILE.GetIndex(release.Quality.Quality).Index * 100; + release.LanguageWeight = LANGUAGE_PROFILE.Languages.FindIndex(v => v.Language == release.Language) * 100; release.QualityWeight += release.Quality.Revision.Real * 10; release.QualityWeight += release.Quality.Revision.Version; diff --git a/src/Sonarr.Api.V3/Indexers/ReleasePushModule.cs b/src/Sonarr.Api.V3/Indexers/ReleasePushModule.cs index d8525cef5..40adf837c 100644 --- a/src/Sonarr.Api.V3/Indexers/ReleasePushModule.cs +++ b/src/Sonarr.Api.V3/Indexers/ReleasePushModule.cs @@ -9,6 +9,8 @@ using NzbDrone.Core.DecisionEngine; using NzbDrone.Core.Download; using NzbDrone.Core.Indexers; using NzbDrone.Core.Parser.Model; +using NzbDrone.Core.Profiles.Languages; +using NzbDrone.Core.Profiles.Qualities; namespace Sonarr.Api.V3.Indexers { @@ -22,7 +24,10 @@ namespace Sonarr.Api.V3.Indexers public ReleasePushModule(IMakeDownloadDecision downloadDecisionMaker, IProcessDownloadDecisions downloadDecisionProcessor, IIndexerFactory indexerFactory, - Logger logger) + ILanguageProfileService languageProfileService, + IQualityProfileService qualityProfileService, + Logger logger) : + base(languageProfileService, qualityProfileService) { _downloadDecisionMaker = downloadDecisionMaker; _downloadDecisionProcessor = downloadDecisionProcessor; diff --git a/src/Sonarr.Api.V3/Profiles/Quality/QualityProfileModule.cs b/src/Sonarr.Api.V3/Profiles/Quality/QualityProfileModule.cs index 1c8614312..618438292 100644 --- a/src/Sonarr.Api.V3/Profiles/Quality/QualityProfileModule.cs +++ b/src/Sonarr.Api.V3/Profiles/Quality/QualityProfileModule.cs @@ -7,11 +7,11 @@ namespace Sonarr.Api.V3.Profiles.Quality { public class ProfileModule : SonarrRestModule { - private readonly IProfileService _profileService; + private readonly IQualityProfileService _qualityProfileService; - public ProfileModule(IProfileService profileService) + public ProfileModule(IQualityProfileService qualityProfileService) { - _profileService = profileService; + _qualityProfileService = qualityProfileService; SharedValidator.RuleFor(c => c.Name).NotEmpty(); SharedValidator.RuleFor(c => c.Cutoff).ValidCutoff(); SharedValidator.RuleFor(c => c.Items).ValidItems(); @@ -26,30 +26,30 @@ namespace Sonarr.Api.V3.Profiles.Quality private int Create(QualityProfileResource resource) { var model = resource.ToModel(); - model = _profileService.Add(model); + model = _qualityProfileService.Add(model); return model.Id; } private void DeleteProfile(int id) { - _profileService.Delete(id); + _qualityProfileService.Delete(id); } private void Update(QualityProfileResource resource) { var model = resource.ToModel(); - _profileService.Update(model); + _qualityProfileService.Update(model); } private QualityProfileResource GetById(int id) { - return _profileService.Get(id).ToResource(); + return _qualityProfileService.Get(id).ToResource(); } private List GetAll() { - return _profileService.All().ToResource(); + return _qualityProfileService.All().ToResource(); } } } \ No newline at end of file diff --git a/src/Sonarr.Api.V3/Profiles/Quality/QualityProfileSchemaModule.cs b/src/Sonarr.Api.V3/Profiles/Quality/QualityProfileSchemaModule.cs index c2c7b7f0e..98379e09f 100644 --- a/src/Sonarr.Api.V3/Profiles/Quality/QualityProfileSchemaModule.cs +++ b/src/Sonarr.Api.V3/Profiles/Quality/QualityProfileSchemaModule.cs @@ -5,18 +5,18 @@ namespace Sonarr.Api.V3.Profiles.Quality { public class QualityProfileSchemaModule : SonarrRestModule { - private readonly IProfileService _profileService; + private readonly IQualityProfileService _qualityProfileService; - public QualityProfileSchemaModule(IProfileService profileService) + public QualityProfileSchemaModule(IQualityProfileService qualityProfileService) : base("/qualityprofile/schema") { - _profileService = profileService; + _qualityProfileService = qualityProfileService; GetResourceSingle = GetSchema; } private QualityProfileResource GetSchema() { - var qualityProfile = _profileService.GetDefaultProfile(string.Empty); + var qualityProfile = _qualityProfileService.GetDefaultProfile(string.Empty); return qualityProfile.ToResource(); } diff --git a/src/Sonarr.Api.V3/Queue/QueueModule.cs b/src/Sonarr.Api.V3/Queue/QueueModule.cs index 3519a5d12..e2c9839c4 100644 --- a/src/Sonarr.Api.V3/Queue/QueueModule.cs +++ b/src/Sonarr.Api.V3/Queue/QueueModule.cs @@ -29,7 +29,7 @@ namespace Sonarr.Api.V3.Queue IQueueService queueService, IPendingReleaseService pendingReleaseService, ILanguageProfileService languageProfileService, - QualityProfileService qualityProfileService) + IQualityProfileService qualityProfileService) : base(broadcastSignalRMessage) { _queueService = queueService;