Skip to content

Commit

Permalink
Fixed: Sorting interactive search by quality for unknown artist results
Browse files Browse the repository at this point in the history
Fixes #1587
  • Loading branch information
Qstick committed Jun 5, 2022
1 parent 26b5db3 commit 423b489
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 24 deletions.
3 changes: 3 additions & 0 deletions src/Lidarr.Api.V1/Indexers/ReleaseController.cs
Expand Up @@ -14,6 +14,7 @@
using NzbDrone.Core.Music;
using NzbDrone.Core.Parser;
using NzbDrone.Core.Parser.Model;
using NzbDrone.Core.Profiles.Qualities;
using NzbDrone.Core.Validation;
using HttpStatusCode = System.Net.HttpStatusCode;

Expand Down Expand Up @@ -43,7 +44,9 @@ public class ReleaseController : ReleaseControllerBase
IParsingService parsingService,
IDownloadService downloadService,
ICacheManager cacheManager,
IQualityProfileService qualityProfileService,
Logger logger)
: base(qualityProfileService)
{
_albumService = albumService;
_artistService = artistService;
Expand Down
15 changes: 9 additions & 6 deletions src/Lidarr.Api.V1/Indexers/ReleaseControllerBase.cs
Expand Up @@ -2,11 +2,19 @@
using System.Collections.Generic;
using Lidarr.Http.REST;
using NzbDrone.Core.DecisionEngine;
using NzbDrone.Core.Profiles.Qualities;

namespace Lidarr.Api.V1.Indexers
{
public abstract class ReleaseControllerBase : RestController<ReleaseResource>
{
private readonly QualityProfile _qualityProfile;

public ReleaseControllerBase(IQualityProfileService qualityProfileService)
{
_qualityProfile = qualityProfileService.GetDefaultProfile(string.Empty);
}

public override ReleaseResource GetResourceById(int id)
{
throw new NotImplementedException();
Expand All @@ -32,12 +40,7 @@ protected virtual ReleaseResource MapDecision(DownloadDecision decision, int ini

release.ReleaseWeight = initialWeight;

if (decision.RemoteAlbum.Artist != null)
{
release.QualityWeight = decision.RemoteAlbum
.Artist
.QualityProfile.Value.GetIndex(release.Quality.Quality).Index * 100;
}
release.QualityWeight = _qualityProfile.GetIndex(release.Quality.Quality).Index * 100;

release.QualityWeight += release.Quality.Revision.Real * 10;
release.QualityWeight += release.Quality.Revision.Version;
Expand Down
3 changes: 3 additions & 0 deletions src/Lidarr.Api.V1/Indexers/ReleasePushController.cs
Expand Up @@ -11,6 +11,7 @@
using NzbDrone.Core.Download;
using NzbDrone.Core.Indexers;
using NzbDrone.Core.Parser.Model;
using NzbDrone.Core.Profiles.Qualities;

namespace Lidarr.Api.V1.Indexers
{
Expand All @@ -25,7 +26,9 @@ public class ReleasePushController : ReleaseControllerBase
public ReleasePushController(IMakeDownloadDecision downloadDecisionMaker,
IProcessDownloadDecisions downloadDecisionProcessor,
IIndexerFactory indexerFactory,
IQualityProfileService qualityProfileService,
Logger logger)
: base(qualityProfileService)
{
_downloadDecisionMaker = downloadDecisionMaker;
_downloadDecisionProcessor = downloadDecisionProcessor;
Expand Down
16 changes: 8 additions & 8 deletions src/Lidarr.Api.V1/Profiles/Quality/QualityProfileController.cs
Expand Up @@ -11,11 +11,11 @@ namespace Lidarr.Api.V1.Profiles.Quality
[V1ApiController]
public class QualityProfileController : RestController<QualityProfileResource>
{
private readonly IProfileService _profileService;
private readonly IQualityProfileService _qualityProfileService;

public QualityProfileController(IProfileService profileService)
public QualityProfileController(IQualityProfileService qualityProfileService)
{
_profileService = profileService;
_qualityProfileService = qualityProfileService;
SharedValidator.RuleFor(c => c.Name).NotEmpty();
SharedValidator.RuleFor(c => c.Cutoff).ValidCutoff();
SharedValidator.RuleFor(c => c.Items).ValidItems();
Expand All @@ -25,35 +25,35 @@ public QualityProfileController(IProfileService profileService)
public ActionResult<QualityProfileResource> Create(QualityProfileResource resource)
{
var model = resource.ToModel();
model = _profileService.Add(model);
model = _qualityProfileService.Add(model);
return Created(model.Id);
}

[RestDeleteById]
public void DeleteProfile(int id)
{
_profileService.Delete(id);
_qualityProfileService.Delete(id);
}

[RestPutById]
public ActionResult<QualityProfileResource> Update(QualityProfileResource resource)
{
var model = resource.ToModel();

_profileService.Update(model);
_qualityProfileService.Update(model);

return Accepted(model.Id);
}

public override QualityProfileResource GetResourceById(int id)
{
return _profileService.Get(id).ToResource();
return _qualityProfileService.Get(id).ToResource();
}

[HttpGet]
public List<QualityProfileResource> GetAll()
{
return _profileService.All().ToResource();
return _qualityProfileService.All().ToResource();
}
}
}
Expand Up @@ -7,9 +7,9 @@ namespace Lidarr.Api.V1.Profiles.Quality
[V1ApiController("qualityprofile/schema")]
public class QualityProfileSchemaController : Controller
{
private readonly IProfileService _profileService;
private readonly IQualityProfileService _profileService;

public QualityProfileSchemaController(IProfileService profileService)
public QualityProfileSchemaController(IQualityProfileService profileService)
{
_profileService = profileService;
}
Expand Down
Expand Up @@ -52,7 +52,7 @@ public class ImportDecisionMaker : IMakeImportDecision
private readonly IAugmentingService _augmentingService;
private readonly IIdentificationService _identificationService;
private readonly IRootFolderService _rootFolderService;
private readonly IProfileService _qualityProfileService;
private readonly IQualityProfileService _qualityProfileService;
private readonly Logger _logger;

public ImportDecisionMaker(IEnumerable<IImportDecisionEngineSpecification<LocalTrack>> trackSpecifications,
Expand All @@ -62,7 +62,7 @@ public class ImportDecisionMaker : IMakeImportDecision
IAugmentingService augmentingService,
IIdentificationService identificationService,
IRootFolderService rootFolderService,
IProfileService qualityProfileService,
IQualityProfileService qualityProfileService,
Logger logger)
{
_trackSpecifications = trackSpecifications;
Expand Down
4 changes: 2 additions & 2 deletions src/NzbDrone.Core/Music/Services/AlbumCutoffService.cs
Expand Up @@ -14,9 +14,9 @@ public interface IAlbumCutoffService
public class AlbumCutoffService : IAlbumCutoffService
{
private readonly IAlbumRepository _albumRepository;
private readonly IProfileService _profileService;
private readonly IQualityProfileService _profileService;

public AlbumCutoffService(IAlbumRepository albumRepository, IProfileService profileService)
public AlbumCutoffService(IAlbumRepository albumRepository, IQualityProfileService profileService)
{
_albumRepository = albumRepository;
_profileService = profileService;
Expand Down
4 changes: 2 additions & 2 deletions src/NzbDrone.Core/Profiles/Qualities/QualityProfileService.cs
Expand Up @@ -10,7 +10,7 @@

namespace NzbDrone.Core.Profiles.Qualities
{
public interface IProfileService
public interface IQualityProfileService
{
QualityProfile Add(QualityProfile profile);
void Update(QualityProfile profile);
Expand All @@ -21,7 +21,7 @@ public interface IProfileService
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 IArtistService _artistService;
Expand Down
4 changes: 2 additions & 2 deletions src/NzbDrone.Core/Validation/QualityProfileExistsValidator.cs
Expand Up @@ -5,9 +5,9 @@ namespace NzbDrone.Core.Validation
{
public class QualityProfileExistsValidator : PropertyValidator
{
private readonly IProfileService _profileService;
private readonly IQualityProfileService _profileService;

public QualityProfileExistsValidator(IProfileService profileService)
public QualityProfileExistsValidator(IQualityProfileService profileService)
: base("Quality Profile does not exist")
{
_profileService = profileService;
Expand Down

0 comments on commit 423b489

Please sign in to comment.