From d556b77f9d6bb76f89c4230cd6540671f67414fc Mon Sep 17 00:00:00 2001 From: Qstick Date: Sat, 4 Feb 2023 22:25:44 -0600 Subject: [PATCH] Fixed: Readarr to Readarr import list adds random results --- .../ImportLists/ImportListSyncService.cs | 41 ++++++++++++------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/src/NzbDrone.Core/ImportLists/ImportListSyncService.cs b/src/NzbDrone.Core/ImportLists/ImportListSyncService.cs index 701701cdc..3a5f2f5a7 100644 --- a/src/NzbDrone.Core/ImportLists/ImportListSyncService.cs +++ b/src/NzbDrone.Core/ImportLists/ImportListSyncService.cs @@ -11,6 +11,7 @@ using NzbDrone.Core.ImportLists.Exclusions; 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 @@ namespace NzbDrone.Core.ImportLists 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 @@ namespace NzbDrone.Core.ImportLists IFetchAndParseImportList listFetcherAndParser, IGoodreadsProxy goodreadsProxy, IGoodreadsSearchProxy goodreadsSearchProxy, + IProvideBookInfo bookInfoProxy, IAuthorService authorService, IBookService bookService, IEditionService editionService, @@ -51,6 +54,7 @@ namespace NzbDrone.Core.ImportLists _listFetcherAndParser = listFetcherAndParser; _goodreadsProxy = goodreadsProxy; _goodreadsSearchProxy = goodreadsSearchProxy; + _bookInfoProxy = bookInfoProxy; _authorService = authorService; _bookService = bookService; _editionService = editionService; @@ -141,6 +145,11 @@ namespace NzbDrone.Core.ImportLists 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 @@ namespace NzbDrone.Core.ImportLists 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 @@ namespace NzbDrone.Core.ImportLists private void ProcessBookReport(ImportListDefinition importList, ImportListItemInfo report, List listExclusions, List booksToAdd, List 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 @@ namespace NzbDrone.Core.ImportLists ForeignBookId = report.BookGoodreadsId, Monitored = monitored, AnyEditionOk = true, - Editions = new List - { - new Edition - { - ForeignEditionId = report.EditionGoodreadsId, - Monitored = true - } - }, + Editions = new List(), Author = toAddAuthor, AddOptions = new AddBookOptions { @@ -314,6 +318,15 @@ namespace NzbDrone.Core.ImportLists } }; + 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");