mirror of
https://github.com/Readarr/Readarr
synced 2025-12-12 11:26:06 +01:00
Fixed: Readarr to Readarr import list adds random results
This commit is contained in:
parent
8b9cada59e
commit
d556b77f9d
1 changed files with 27 additions and 14 deletions
|
|
@ -11,6 +11,7 @@
|
|||
using NzbDrone.Core.IndexerSearch;
|
||||
using NzbDrone.Core.Messaging.Commands;
|
||||
using NzbDrone.Core.Messaging.Events;
|
||||
using NzbDrone.Core.MetadataSource;
|
||||
using NzbDrone.Core.MetadataSource.Goodreads;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
|
||||
|
|
@ -23,6 +24,7 @@ public class ImportListSyncService : IExecute<ImportListSyncCommand>
|
|||
private readonly IFetchAndParseImportList _listFetcherAndParser;
|
||||
private readonly IGoodreadsProxy _goodreadsProxy;
|
||||
private readonly IGoodreadsSearchProxy _goodreadsSearchProxy;
|
||||
private readonly IProvideBookInfo _bookInfoProxy;
|
||||
private readonly IAuthorService _authorService;
|
||||
private readonly IBookService _bookService;
|
||||
private readonly IEditionService _editionService;
|
||||
|
|
@ -37,6 +39,7 @@ public ImportListSyncService(IImportListFactory importListFactory,
|
|||
IFetchAndParseImportList listFetcherAndParser,
|
||||
IGoodreadsProxy goodreadsProxy,
|
||||
IGoodreadsSearchProxy goodreadsSearchProxy,
|
||||
IProvideBookInfo bookInfoProxy,
|
||||
IAuthorService authorService,
|
||||
IBookService bookService,
|
||||
IEditionService editionService,
|
||||
|
|
@ -51,6 +54,7 @@ public ImportListSyncService(IImportListFactory importListFactory,
|
|||
_listFetcherAndParser = listFetcherAndParser;
|
||||
_goodreadsProxy = goodreadsProxy;
|
||||
_goodreadsSearchProxy = goodreadsSearchProxy;
|
||||
_bookInfoProxy = bookInfoProxy;
|
||||
_authorService = authorService;
|
||||
_bookService = bookService;
|
||||
_editionService = editionService;
|
||||
|
|
@ -141,6 +145,11 @@ private List<Book> ProcessReports(List<ImportListItemInfo> reports)
|
|||
|
||||
private void MapBookReport(ImportListItemInfo report)
|
||||
{
|
||||
if (report.AuthorGoodreadsId.IsNotNullOrWhiteSpace() && report.BookGoodreadsId.IsNotNullOrWhiteSpace())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (report.EditionGoodreadsId.IsNotNullOrWhiteSpace() && int.TryParse(report.EditionGoodreadsId, out var goodreadsId))
|
||||
{
|
||||
// check the local DB
|
||||
|
|
@ -173,6 +182,14 @@ private void MapBookReport(ImportListItemInfo report)
|
|||
report.EditionGoodreadsId = null;
|
||||
}
|
||||
}
|
||||
else if (report.BookGoodreadsId.IsNotNullOrWhiteSpace())
|
||||
{
|
||||
var mappedBook = _bookInfoProxy.GetBookInfo(report.BookGoodreadsId);
|
||||
|
||||
report.BookGoodreadsId = mappedBook.Item2.ForeignBookId;
|
||||
report.Book = mappedBook.Item2.Title;
|
||||
report.AuthorGoodreadsId = mappedBook.Item3.First().ForeignAuthorId;
|
||||
}
|
||||
else
|
||||
{
|
||||
var mappedBook = _goodreadsSearchProxy.Search($"{report.Book} {report.Author}").FirstOrDefault();
|
||||
|
|
@ -195,12 +212,6 @@ private void MapBookReport(ImportListItemInfo report)
|
|||
|
||||
private void ProcessBookReport(ImportListDefinition importList, ImportListItemInfo report, List<ImportListExclusion> listExclusions, List<Book> booksToAdd, List<Author> authorsToAdd)
|
||||
{
|
||||
if (report.EditionGoodreadsId == null)
|
||||
{
|
||||
_logger.Trace("Skipping report [{0}] due to missing EditionGoodreadsId", report.Book);
|
||||
return;
|
||||
}
|
||||
|
||||
// Check to see if book in DB
|
||||
var existingBook = _bookService.FindById(report.BookGoodreadsId);
|
||||
|
||||
|
|
@ -297,14 +308,7 @@ private void ProcessBookReport(ImportListDefinition importList, ImportListItemIn
|
|||
ForeignBookId = report.BookGoodreadsId,
|
||||
Monitored = monitored,
|
||||
AnyEditionOk = true,
|
||||
Editions = new List<Edition>
|
||||
{
|
||||
new Edition
|
||||
{
|
||||
ForeignEditionId = report.EditionGoodreadsId,
|
||||
Monitored = true
|
||||
}
|
||||
},
|
||||
Editions = new List<Edition>(),
|
||||
Author = toAddAuthor,
|
||||
AddOptions = new AddBookOptions
|
||||
{
|
||||
|
|
@ -314,6 +318,15 @@ private void ProcessBookReport(ImportListDefinition importList, ImportListItemIn
|
|||
}
|
||||
};
|
||||
|
||||
if (report.EditionGoodreadsId.IsNotNullOrWhiteSpace() && int.TryParse(report.EditionGoodreadsId, out var goodreadsId))
|
||||
{
|
||||
toAdd.Editions.Value.Add(new Edition
|
||||
{
|
||||
ForeignEditionId = report.EditionGoodreadsId,
|
||||
Monitored = true
|
||||
});
|
||||
}
|
||||
|
||||
if (importList.ShouldMonitor == ImportListMonitorType.SpecificBook && toAddAuthor.AddOptions != null)
|
||||
{
|
||||
Debug.Assert(toAddAuthor.Id == 0, "new author added but ID is not 0");
|
||||
|
|
|
|||
Loading…
Reference in a new issue