From 20f67c8035c6ec24e08a0cb2f8b3419d687f2d7c Mon Sep 17 00:00:00 2001 From: bakerboy448 <55419169+bakerboy448@users.noreply.github.com> Date: Mon, 25 Jul 2022 14:03:04 -0500 Subject: [PATCH] Fixed: Importing Readarr Lists Fixes #1747 --- .../ImportLists/Readarr/ReadarrAPIResource.cs | 2 ++ .../ImportLists/Readarr/ReadarrImport.cs | 21 +++++++++++++------ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/NzbDrone.Core/ImportLists/Readarr/ReadarrAPIResource.cs b/src/NzbDrone.Core/ImportLists/Readarr/ReadarrAPIResource.cs index d3c040ba6..21a160892 100644 --- a/src/NzbDrone.Core/ImportLists/Readarr/ReadarrAPIResource.cs +++ b/src/NzbDrone.Core/ImportLists/Readarr/ReadarrAPIResource.cs @@ -5,6 +5,7 @@ namespace NzbDrone.Core.ImportLists.Readarr public class ReadarrAuthor { public string AuthorName { get; set; } + public int Id { get; set; } public string ForeignAuthorId { get; set; } public string Overview { get; set; } public List Images { get; set; } @@ -30,6 +31,7 @@ public class ReadarrBook public List Images { get; set; } public bool Monitored { get; set; } public ReadarrAuthor Author { get; set; } + public int AuthorId { get; set; } public List Editions { get; set; } } diff --git a/src/NzbDrone.Core/ImportLists/Readarr/ReadarrImport.cs b/src/NzbDrone.Core/ImportLists/Readarr/ReadarrImport.cs index bbf7c520a..69e53ccb4 100644 --- a/src/NzbDrone.Core/ImportLists/Readarr/ReadarrImport.cs +++ b/src/NzbDrone.Core/ImportLists/Readarr/ReadarrImport.cs @@ -35,20 +35,28 @@ public override IList Fetch() try { var remoteBooks = _readarrV1Proxy.GetBooks(Settings); + var remoteAuthors = _readarrV1Proxy.GetAuthors(Settings); + + var authorDict = remoteAuthors.ToDictionary(x => x.Id); foreach (var remoteBook in remoteBooks) { - if ((!Settings.ProfileIds.Any() || Settings.ProfileIds.Contains(remoteBook.Author.QualityProfileId)) && - (!Settings.TagIds.Any() || Settings.TagIds.Any(x => remoteBook.Author.Tags.Any(y => y == x))) && - remoteBook.Monitored && remoteBook.Author.Monitored) + var remoteAuthor = authorDict[remoteBook.AuthorId]; + + if ((!Settings.ProfileIds.Any() || Settings.ProfileIds.Contains(remoteAuthor.QualityProfileId)) && + (!Settings.TagIds.Any() || Settings.TagIds.Any(x => remoteAuthor.Tags.Any(y => y == x))) && + remoteBook.Monitored && remoteAuthor.Monitored) { authorsAndBooks.Add(new ImportListItemInfo { BookGoodreadsId = remoteBook.ForeignBookId, Book = remoteBook.Title, - EditionGoodreadsId = remoteBook.Editions.Single(x => x.Monitored).ForeignEditionId, - Author = remoteBook.Author.AuthorName, - AuthorGoodreadsId = remoteBook.Author.ForeignAuthorId + + // ToDo: Fix me. Edition is no longer in the book resource; rethink edition logic + // Bandaid fix for now...This will cause the imported book to possibly not be same edition as the source + // EditionGoodreadsId = remoteBook.Editions.Single(x => x.Monitored).ForeignEditionId, + Author = remoteAuthor.AuthorName, + AuthorGoodreadsId = remoteAuthor.ForeignAuthorId }); } } @@ -57,6 +65,7 @@ public override IList Fetch() } catch { + _logger.Warn("List Import Sync Task Failed for List [{0}]", Definition.Name); _importListStatusService.RecordFailure(Definition.Id); }