Fixed: Don't Crash on Manual Grabs

This commit is contained in:
Qstick
2020-10-09 21:47:27 -04:00
parent 00dcc5de86
commit 086e3b3240
2 changed files with 115 additions and 40 deletions
@@ -85,53 +85,72 @@ namespace NzbDrone.Core.DecisionEngine
} }
} }
if (parsedBookInfo != null) if (parsedBookInfo != null && !parsedBookInfo.AuthorName.IsNullOrWhiteSpace())
{ {
if (!parsedBookInfo.AuthorName.IsNullOrWhiteSpace()) var remoteBook = _parsingService.Map(parsedBookInfo, searchCriteria);
// try parsing again using the search criteria, in case it parsed but parsed incorrectly
if ((remoteBook.Author == null || remoteBook.Books.Empty()) && searchCriteria != null)
{ {
var remoteBook = _parsingService.Map(parsedBookInfo, searchCriteria); _logger.Debug("Author/Book null for {0}, reparsing with search criteria", report.Title);
var parsedBookInfoWithCriteria = Parser.Parser.ParseBookTitleWithSearchCriteria(report.Title,
searchCriteria.Author,
searchCriteria.Books);
// try parsing again using the search criteria, in case it parsed but parsed incorrectly if (parsedBookInfoWithCriteria != null && parsedBookInfoWithCriteria.AuthorName.IsNotNullOrWhiteSpace())
if ((remoteBook.Author == null || remoteBook.Books.Empty()) && searchCriteria != null)
{ {
_logger.Debug("Author/Book null for {0}, reparsing with search criteria", report.Title); remoteBook = _parsingService.Map(parsedBookInfoWithCriteria, searchCriteria);
var parsedBookInfoWithCriteria = Parser.Parser.ParseBookTitleWithSearchCriteria(report.Title,
searchCriteria.Author,
searchCriteria.Books);
if (parsedBookInfoWithCriteria != null && parsedBookInfoWithCriteria.AuthorName.IsNotNullOrWhiteSpace())
{
remoteBook = _parsingService.Map(parsedBookInfoWithCriteria, searchCriteria);
}
} }
}
remoteBook.Release = report; remoteBook.Release = report;
if (remoteBook.Author == null) if (remoteBook.Author == null)
{
decision = new DownloadDecision(remoteBook, new Rejection("Unknown Author"));
// shove in the searched author in case of forced download in interactive search
if (searchCriteria != null)
{ {
decision = new DownloadDecision(remoteBook, new Rejection("Unknown Author")); remoteBook.Author = searchCriteria.Author;
remoteBook.Books = searchCriteria.Books;
}
}
else if (remoteBook.Books.Empty())
{
decision = new DownloadDecision(remoteBook, new Rejection("Unable to parse books from release name"));
if (searchCriteria != null)
{
remoteBook.Books = searchCriteria.Books;
}
}
else
{
_aggregationService.Augment(remoteBook);
remoteBook.DownloadAllowed = remoteBook.Books.Any();
decision = GetDecisionForReport(remoteBook, searchCriteria);
}
}
// shove in the searched author in case of forced download in interactive search if (searchCriteria != null)
if (searchCriteria != null) {
{ if (parsedBookInfo == null)
remoteBook.Author = searchCriteria.Author; {
remoteBook.Books = searchCriteria.Books; parsedBookInfo = new ParsedBookInfo
}
}
else if (remoteBook.Books.Empty())
{ {
decision = new DownloadDecision(remoteBook, new Rejection("Unable to parse books from release name")); Quality = QualityParser.ParseQuality(report.Title)
if (searchCriteria != null) };
{ }
remoteBook.Books = searchCriteria.Books;
} if (parsedBookInfo.AuthorName.IsNullOrWhiteSpace())
} {
else var remoteBook = new RemoteBook
{ {
_aggregationService.Augment(remoteBook); Release = report,
remoteBook.DownloadAllowed = remoteBook.Books.Any(); ParsedBookInfo = parsedBookInfo
decision = GetDecisionForReport(remoteBook, searchCriteria); };
}
decision = new DownloadDecision(remoteBook, new Rejection("Unable to parse release"));
} }
} }
} }
+60 -4
View File
@@ -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.Books;
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.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;
@@ -22,6 +25,9 @@ namespace Readarr.Api.V1.Indexers
private readonly IMakeDownloadDecision _downloadDecisionMaker; private readonly IMakeDownloadDecision _downloadDecisionMaker;
private readonly IPrioritizeDownloadDecision _prioritizeDownloadDecision; private readonly IPrioritizeDownloadDecision _prioritizeDownloadDecision;
private readonly IDownloadService _downloadService; private readonly IDownloadService _downloadService;
private readonly IAuthorService _authorService;
private readonly IBookService _bookService;
private readonly IParsingService _parsingService;
private readonly Logger _logger; private readonly Logger _logger;
private readonly ICached<RemoteBook> _remoteBookCache; private readonly ICached<RemoteBook> _remoteBookCache;
@@ -31,6 +37,9 @@ namespace Readarr.Api.V1.Indexers
IMakeDownloadDecision downloadDecisionMaker, IMakeDownloadDecision downloadDecisionMaker,
IPrioritizeDownloadDecision prioritizeDownloadDecision, IPrioritizeDownloadDecision prioritizeDownloadDecision,
IDownloadService downloadService, IDownloadService downloadService,
IAuthorService authorService,
IBookService bookService,
IParsingService parsingService,
ICacheManager cacheManager, ICacheManager cacheManager,
Logger logger) Logger logger)
{ {
@@ -39,6 +48,9 @@ namespace Readarr.Api.V1.Indexers
_downloadDecisionMaker = downloadDecisionMaker; _downloadDecisionMaker = downloadDecisionMaker;
_prioritizeDownloadDecision = prioritizeDownloadDecision; _prioritizeDownloadDecision = prioritizeDownloadDecision;
_downloadService = downloadService; _downloadService = downloadService;
_authorService = authorService;
_bookService = bookService;
_parsingService = parsingService;
_logger = logger; _logger = logger;
GetResourceAll = GetReleases; GetResourceAll = GetReleases;
@@ -63,6 +75,52 @@ namespace Readarr.Api.V1.Indexers
try try
{ {
if (remoteBook.Author == null)
{
if (release.BookId.HasValue)
{
var book = _bookService.GetBook(release.BookId.Value);
remoteBook.Author = _authorService.GetAuthor(book.AuthorId);
remoteBook.Books = new List<Book> { book };
}
else if (release.AuthorId.HasValue)
{
var author = _authorService.GetAuthor(release.AuthorId.Value);
var books = _parsingService.GetAlbums(remoteBook.ParsedBookInfo, author);
if (books.Empty())
{
throw new NzbDroneClientException(HttpStatusCode.NotFound, "Unable to parse books in the release");
}
remoteBook.Author = author;
remoteBook.Books = books;
}
else
{
throw new NzbDroneClientException(HttpStatusCode.NotFound, "Unable to find matching author and books");
}
}
else if (remoteBook.Books.Empty())
{
var books = _parsingService.GetAlbums(remoteBook.ParsedBookInfo, remoteBook.Author);
if (books.Empty() && release.BookId.HasValue)
{
var book = _bookService.GetBook(release.BookId.Value);
books = new List<Book> { book };
}
remoteBook.Books = books;
}
if (remoteBook.Books.Empty())
{
throw new NzbDroneClientException(HttpStatusCode.NotFound, "Unable to parse books in the release");
}
_downloadService.DownloadReport(remoteBook); _downloadService.DownloadReport(remoteBook);
} }
catch (ReleaseDownloadException ex) catch (ReleaseDownloadException ex)
@@ -101,9 +159,8 @@ namespace Readarr.Api.V1.Indexers
catch (Exception ex) catch (Exception ex)
{ {
_logger.Error(ex, "Book search failed"); _logger.Error(ex, "Book search failed");
throw new NzbDroneClientException(HttpStatusCode.InternalServerError, ex.Message);
} }
return new List<ReleaseResource>();
} }
private List<ReleaseResource> GetAuthorReleases(int authorId) private List<ReleaseResource> GetAuthorReleases(int authorId)
@@ -118,9 +175,8 @@ namespace Readarr.Api.V1.Indexers
catch (Exception ex) catch (Exception ex)
{ {
_logger.Error(ex, "Author search failed"); _logger.Error(ex, "Author search failed");
throw new NzbDroneClientException(HttpStatusCode.InternalServerError, ex.Message);
} }
return new List<ReleaseResource>();
} }
private List<ReleaseResource> GetRss() private List<ReleaseResource> GetRss()