|
|
@ -4,11 +4,14 @@ using FluentValidation;
|
|
|
|
using Nancy;
|
|
|
|
using Nancy;
|
|
|
|
using NLog;
|
|
|
|
using NLog;
|
|
|
|
using NzbDrone.Common.Cache;
|
|
|
|
using NzbDrone.Common.Cache;
|
|
|
|
|
|
|
|
using NzbDrone.Common.Extensions;
|
|
|
|
using NzbDrone.Core.DecisionEngine;
|
|
|
|
using NzbDrone.Core.DecisionEngine;
|
|
|
|
using NzbDrone.Core.Download;
|
|
|
|
using NzbDrone.Core.Download;
|
|
|
|
using NzbDrone.Core.Exceptions;
|
|
|
|
using NzbDrone.Core.Exceptions;
|
|
|
|
using NzbDrone.Core.Indexers;
|
|
|
|
using NzbDrone.Core.Indexers;
|
|
|
|
using NzbDrone.Core.IndexerSearch;
|
|
|
|
using NzbDrone.Core.IndexerSearch;
|
|
|
|
|
|
|
|
using NzbDrone.Core.Music;
|
|
|
|
|
|
|
|
using NzbDrone.Core.Parser;
|
|
|
|
using NzbDrone.Core.Parser.Model;
|
|
|
|
using NzbDrone.Core.Parser.Model;
|
|
|
|
using NzbDrone.Core.Validation;
|
|
|
|
using NzbDrone.Core.Validation;
|
|
|
|
using HttpStatusCode = System.Net.HttpStatusCode;
|
|
|
|
using HttpStatusCode = System.Net.HttpStatusCode;
|
|
|
@ -17,27 +20,36 @@ namespace Lidarr.Api.V1.Indexers
|
|
|
|
{
|
|
|
|
{
|
|
|
|
public class ReleaseModule : ReleaseModuleBase
|
|
|
|
public class ReleaseModule : ReleaseModuleBase
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
private readonly IAlbumService _albumService;
|
|
|
|
|
|
|
|
private readonly IArtistService _artistService;
|
|
|
|
private readonly IFetchAndParseRss _rssFetcherAndParser;
|
|
|
|
private readonly IFetchAndParseRss _rssFetcherAndParser;
|
|
|
|
private readonly ISearchForNzb _nzbSearchService;
|
|
|
|
private readonly ISearchForNzb _nzbSearchService;
|
|
|
|
private readonly IMakeDownloadDecision _downloadDecisionMaker;
|
|
|
|
private readonly IMakeDownloadDecision _downloadDecisionMaker;
|
|
|
|
private readonly IPrioritizeDownloadDecision _prioritizeDownloadDecision;
|
|
|
|
private readonly IPrioritizeDownloadDecision _prioritizeDownloadDecision;
|
|
|
|
|
|
|
|
private readonly IParsingService _parsingService;
|
|
|
|
private readonly IDownloadService _downloadService;
|
|
|
|
private readonly IDownloadService _downloadService;
|
|
|
|
private readonly Logger _logger;
|
|
|
|
private readonly Logger _logger;
|
|
|
|
|
|
|
|
|
|
|
|
private readonly ICached<RemoteAlbum> _remoteAlbumCache;
|
|
|
|
private readonly ICached<RemoteAlbum> _remoteAlbumCache;
|
|
|
|
|
|
|
|
|
|
|
|
public ReleaseModule(IFetchAndParseRss rssFetcherAndParser,
|
|
|
|
public ReleaseModule(IAlbumService albumService,
|
|
|
|
|
|
|
|
IArtistService artistService,
|
|
|
|
|
|
|
|
IFetchAndParseRss rssFetcherAndParser,
|
|
|
|
ISearchForNzb nzbSearchService,
|
|
|
|
ISearchForNzb nzbSearchService,
|
|
|
|
IMakeDownloadDecision downloadDecisionMaker,
|
|
|
|
IMakeDownloadDecision downloadDecisionMaker,
|
|
|
|
IPrioritizeDownloadDecision prioritizeDownloadDecision,
|
|
|
|
IPrioritizeDownloadDecision prioritizeDownloadDecision,
|
|
|
|
|
|
|
|
IParsingService parsingService,
|
|
|
|
IDownloadService downloadService,
|
|
|
|
IDownloadService downloadService,
|
|
|
|
ICacheManager cacheManager,
|
|
|
|
ICacheManager cacheManager,
|
|
|
|
Logger logger)
|
|
|
|
Logger logger)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
_albumService = albumService;
|
|
|
|
|
|
|
|
_artistService = artistService;
|
|
|
|
_rssFetcherAndParser = rssFetcherAndParser;
|
|
|
|
_rssFetcherAndParser = rssFetcherAndParser;
|
|
|
|
_nzbSearchService = nzbSearchService;
|
|
|
|
_nzbSearchService = nzbSearchService;
|
|
|
|
_downloadDecisionMaker = downloadDecisionMaker;
|
|
|
|
_downloadDecisionMaker = downloadDecisionMaker;
|
|
|
|
_prioritizeDownloadDecision = prioritizeDownloadDecision;
|
|
|
|
_prioritizeDownloadDecision = prioritizeDownloadDecision;
|
|
|
|
|
|
|
|
_parsingService = parsingService;
|
|
|
|
_downloadService = downloadService;
|
|
|
|
_downloadService = downloadService;
|
|
|
|
_logger = logger;
|
|
|
|
_logger = logger;
|
|
|
|
|
|
|
|
|
|
|
@ -63,11 +75,57 @@ namespace Lidarr.Api.V1.Indexers
|
|
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
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);
|
|
|
|
_downloadService.DownloadReport(remoteAlbum);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (ReleaseDownloadException ex)
|
|
|
|
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");
|
|
|
|
throw new NzbDroneClientException(HttpStatusCode.Conflict, "Getting release from indexer failed");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|