From 24cd56aa35f28ba3c06450a5d9ed59ae3bf3bfa7 Mon Sep 17 00:00:00 2001 From: Qstick Date: Mon, 3 Aug 2020 00:41:24 -0400 Subject: [PATCH] Fixed: Selecting a release from Interactive Search with an unknown album Co-Authored-By: Mark McDowall --- src/Lidarr.Api.V1/Indexers/ReleaseModule.cs | 62 ++++++++++++++++++++- 1 file changed, 60 insertions(+), 2 deletions(-) diff --git a/src/Lidarr.Api.V1/Indexers/ReleaseModule.cs b/src/Lidarr.Api.V1/Indexers/ReleaseModule.cs index 0783a3359..46ba1c2fc 100644 --- a/src/Lidarr.Api.V1/Indexers/ReleaseModule.cs +++ b/src/Lidarr.Api.V1/Indexers/ReleaseModule.cs @@ -4,11 +4,14 @@ using FluentValidation; using Nancy; using NLog; using NzbDrone.Common.Cache; +using NzbDrone.Common.Extensions; using NzbDrone.Core.DecisionEngine; using NzbDrone.Core.Download; using NzbDrone.Core.Exceptions; using NzbDrone.Core.Indexers; using NzbDrone.Core.IndexerSearch; +using NzbDrone.Core.Music; +using NzbDrone.Core.Parser; using NzbDrone.Core.Parser.Model; using NzbDrone.Core.Validation; using HttpStatusCode = System.Net.HttpStatusCode; @@ -17,27 +20,36 @@ namespace Lidarr.Api.V1.Indexers { public class ReleaseModule : ReleaseModuleBase { + private readonly IAlbumService _albumService; + private readonly IArtistService _artistService; private readonly IFetchAndParseRss _rssFetcherAndParser; private readonly ISearchForNzb _nzbSearchService; private readonly IMakeDownloadDecision _downloadDecisionMaker; private readonly IPrioritizeDownloadDecision _prioritizeDownloadDecision; + private readonly IParsingService _parsingService; private readonly IDownloadService _downloadService; private readonly Logger _logger; private readonly ICached _remoteAlbumCache; - public ReleaseModule(IFetchAndParseRss rssFetcherAndParser, + public ReleaseModule(IAlbumService albumService, + IArtistService artistService, + IFetchAndParseRss rssFetcherAndParser, ISearchForNzb nzbSearchService, IMakeDownloadDecision downloadDecisionMaker, IPrioritizeDownloadDecision prioritizeDownloadDecision, + IParsingService parsingService, IDownloadService downloadService, ICacheManager cacheManager, Logger logger) { + _albumService = albumService; + _artistService = artistService; _rssFetcherAndParser = rssFetcherAndParser; _nzbSearchService = nzbSearchService; _downloadDecisionMaker = downloadDecisionMaker; _prioritizeDownloadDecision = prioritizeDownloadDecision; + _parsingService = parsingService; _downloadService = downloadService; _logger = logger; @@ -63,11 +75,57 @@ namespace Lidarr.Api.V1.Indexers try { + if (remoteAlbum.Artist == null) + { + if (release.AlbumId.HasValue) + { + var album = _albumService.GetAlbum(release.AlbumId.Value); + + remoteAlbum.Artist = _artistService.GetArtist(album.ArtistId); + remoteAlbum.Albums = new List { album }; + } + else if (release.ArtistId.HasValue) + { + var artist = _artistService.GetArtist(release.ArtistId.Value); + var albums = _parsingService.GetAlbums(remoteAlbum.ParsedAlbumInfo, artist); + + if (albums.Empty()) + { + throw new NzbDroneClientException(HttpStatusCode.NotFound, "Unable to parse albums in the release"); + } + + remoteAlbum.Artist = artist; + remoteAlbum.Albums = albums; + } + else + { + throw new NzbDroneClientException(HttpStatusCode.NotFound, "Unable to find matching artist and albums"); + } + } + else if (remoteAlbum.Albums.Empty()) + { + var albums = _parsingService.GetAlbums(remoteAlbum.ParsedAlbumInfo, remoteAlbum.Artist); + + if (albums.Empty() && release.AlbumId.HasValue) + { + var album = _albumService.GetAlbum(release.AlbumId.Value); + + albums = new List { album }; + } + + remoteAlbum.Albums = albums; + } + + if (remoteAlbum.Albums.Empty()) + { + throw new NzbDroneClientException(HttpStatusCode.NotFound, "Unable to parse albums in the release"); + } + _downloadService.DownloadReport(remoteAlbum); } catch (ReleaseDownloadException ex) { - _logger.Error(ex, "Getting release from indexer failed"); + _logger.Error(ex, ex.Message); throw new NzbDroneClientException(HttpStatusCode.Conflict, "Getting release from indexer failed"); }