From 8cca919f6b8c9d0ccc4e0af4243c6802d5202f91 Mon Sep 17 00:00:00 2001 From: Bogdan Date: Tue, 9 Jan 2024 03:50:17 +0200 Subject: [PATCH] Add custom format score to parse endpoint --- src/Lidarr.Api.V1/Parse/ParseController.cs | 26 ++++++++++++++++++++-- src/Lidarr.Api.V1/Parse/ParseResource.cs | 3 +++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/Lidarr.Api.V1/Parse/ParseController.cs b/src/Lidarr.Api.V1/Parse/ParseController.cs index 2c8bfffaa..ddaed6411 100644 --- a/src/Lidarr.Api.V1/Parse/ParseController.cs +++ b/src/Lidarr.Api.V1/Parse/ParseController.cs @@ -1,7 +1,11 @@ using Lidarr.Api.V1.Albums; using Lidarr.Api.V1.Artist; +using Lidarr.Api.V1.CustomFormats; using Lidarr.Http; using Microsoft.AspNetCore.Mvc; +using NzbDrone.Common.Extensions; +using NzbDrone.Core.CustomFormats; +using NzbDrone.Core.Download.Aggregation; using NzbDrone.Core.Parser; namespace Lidarr.Api.V1.Parse @@ -10,16 +14,27 @@ namespace Lidarr.Api.V1.Parse public class ParseController : Controller { private readonly IParsingService _parsingService; + private readonly IRemoteAlbumAggregationService _aggregationService; + private readonly ICustomFormatCalculationService _formatCalculator; - public ParseController(IParsingService parsingService) + public ParseController(IParsingService parsingService, + IRemoteAlbumAggregationService aggregationService, + ICustomFormatCalculationService formatCalculator) { _parsingService = parsingService; + _aggregationService = aggregationService; + _formatCalculator = formatCalculator; } [HttpGet] [Produces("application/json")] public ParseResource Parse(string title) { + if (title.IsNullOrWhiteSpace()) + { + return null; + } + var parsedAlbumInfo = Parser.ParseAlbumTitle(title); if (parsedAlbumInfo == null) @@ -34,12 +49,19 @@ namespace Lidarr.Api.V1.Parse if (remoteAlbum != null) { + _aggregationService.Augment(remoteAlbum); + + remoteAlbum.CustomFormats = _formatCalculator.ParseCustomFormat(remoteAlbum, 0); + remoteAlbum.CustomFormatScore = remoteAlbum?.Artist?.QualityProfile?.Value.CalculateCustomFormatScore(remoteAlbum.CustomFormats) ?? 0; + return new ParseResource { Title = title, ParsedAlbumInfo = remoteAlbum.ParsedAlbumInfo, Artist = remoteAlbum.Artist.ToResource(), - Albums = remoteAlbum.Albums.ToResource() + Albums = remoteAlbum.Albums.ToResource(), + CustomFormats = remoteAlbum.CustomFormats?.ToResource(false), + CustomFormatScore = remoteAlbum.CustomFormatScore }; } else diff --git a/src/Lidarr.Api.V1/Parse/ParseResource.cs b/src/Lidarr.Api.V1/Parse/ParseResource.cs index b7b22de3c..52c5310d3 100644 --- a/src/Lidarr.Api.V1/Parse/ParseResource.cs +++ b/src/Lidarr.Api.V1/Parse/ParseResource.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using Lidarr.Api.V1.Albums; using Lidarr.Api.V1.Artist; +using Lidarr.Api.V1.CustomFormats; using Lidarr.Http.REST; using NzbDrone.Core.Parser.Model; @@ -12,5 +13,7 @@ namespace Lidarr.Api.V1.Parse public ParsedAlbumInfo ParsedAlbumInfo { get; set; } public ArtistResource Artist { get; set; } public List Albums { get; set; } + public List CustomFormats { get; set; } + public int CustomFormatScore { get; set; } } }