Fixed: Sorting interactive search by quality for unknown series results

This commit is contained in:
Mark McDowall 2020-09-15 22:18:48 -07:00
parent 068d9eef8d
commit 7ed347269f
10 changed files with 57 additions and 44 deletions

View File

@ -7,11 +7,11 @@ namespace NzbDrone.Api.Profiles
{
public class ProfileModule : SonarrRestModule<ProfileResource>
{
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<ProfileResource> GetAll()
{
return _profileService.All().ToResource();
return _qualityProfileService.All().ToResource();
}
}
}

View File

@ -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<ApplicationStartedEvent>
public class QualityProfileService : IQualityProfileService, IHandle<ApplicationStartedEvent>
{
private readonly IProfileRepository _profileRepository;
private readonly IImportListFactory _importListFactory;

View File

@ -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<QualitiesBelowCutoff>();
var languagesBelowCutoff = new List<LanguagesBelowCutoff>();
var profiles = _profileService.All();
var profiles = _qualityProfileService.All();
var languageProfiles = _languageProfileService.All();
//Get all items less than the cutoff

View File

@ -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);
}
}
}

View File

@ -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;

View File

@ -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<ReleaseResource>
{
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<ReleaseResource> MapDecisions(IEnumerable<DownloadDecision> decisions)
{
var result = new List<ReleaseResource>();
@ -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;

View File

@ -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;

View File

@ -7,11 +7,11 @@ namespace Sonarr.Api.V3.Profiles.Quality
{
public class ProfileModule : SonarrRestModule<QualityProfileResource>
{
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<QualityProfileResource> GetAll()
{
return _profileService.All().ToResource();
return _qualityProfileService.All().ToResource();
}
}
}

View File

@ -5,18 +5,18 @@ namespace Sonarr.Api.V3.Profiles.Quality
{
public class QualityProfileSchemaModule : SonarrRestModule<QualityProfileResource>
{
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();
}

View File

@ -29,7 +29,7 @@ namespace Sonarr.Api.V3.Queue
IQueueService queueService,
IPendingReleaseService pendingReleaseService,
ILanguageProfileService languageProfileService,
QualityProfileService qualityProfileService)
IQualityProfileService qualityProfileService)
: base(broadcastSignalRMessage)
{
_queueService = queueService;