Fixed: Selecting a release from Interactive Search with an unknown album

Co-Authored-By: Mark McDowall <markus101@users.noreply.github.com>
pull/1689/head
Qstick 4 years ago
parent 140f3f88c4
commit 24cd56aa35

@ -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<RemoteAlbum> _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> { 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> { 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");
}

Loading…
Cancel
Save