From 0484ab7d408dd49f0b42410cd29fac78eea609e1 Mon Sep 17 00:00:00 2001 From: HellLord Date: Fri, 17 Apr 2026 13:47:26 +0600 Subject: [PATCH] fix: handle large goodreads series import list --- .../Series/GoodreadsSeriesImportList.cs | 44 ++++++++++++++----- .../Goodreads/GoodreadsProxy.cs | 3 +- .../MetadataSource/IProvideSeriesInfo.cs | 2 +- 3 files changed, 36 insertions(+), 13 deletions(-) diff --git a/src/NzbDrone.Core/ImportLists/Goodreads/Series/GoodreadsSeriesImportList.cs b/src/NzbDrone.Core/ImportLists/Goodreads/Series/GoodreadsSeriesImportList.cs index 5276e98732..9ae2b2344c 100644 --- a/src/NzbDrone.Core/ImportLists/Goodreads/Series/GoodreadsSeriesImportList.cs +++ b/src/NzbDrone.Core/ImportLists/Goodreads/Series/GoodreadsSeriesImportList.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Net; using FluentValidation.Results; using NLog; @@ -36,18 +37,19 @@ public override IList Fetch() try { - var series = _seriesInfo.GetSeriesInfo(Settings.SeriesId); - - foreach (var work in series.Works) + var pageNum = 1; + while (true) { - result.Add(new ImportListItemInfo + var page = FetchPage(pageNum++); + + if (page.Any()) + { + result.AddRange(page); + } + else { - BookGoodreadsId = work.Id.ToString(), - Book = work.OriginalTitle, - EditionGoodreadsId = work.BestBook.Id.ToString(), - Author = work.BestBook.AuthorName, - AuthorGoodreadsId = work.BestBook.AuthorId.ToString() - }); + break; + } } _importListStatusService.RecordSuccess(Definition.Id); @@ -60,6 +62,26 @@ public override IList Fetch() return CleanupListItems(result); } + private List FetchPage(int page) + { + var series = _seriesInfo.GetSeriesInfo(Settings.SeriesId, page); + var result = new List(); + + foreach (var work in series.Works) + { + result.Add(new ImportListItemInfo + { + BookGoodreadsId = work.Id.ToString(), + Book = work.OriginalTitle, + EditionGoodreadsId = work.BestBook.Id.ToString(), + Author = work.BestBook.AuthorName, + AuthorGoodreadsId = work.BestBook.AuthorId.ToString() + }); + } + + return result; + } + protected override void Test(List failures) { failures.AddIfNotNull(TestConnection()); @@ -69,7 +91,7 @@ private ValidationFailure TestConnection() { try { - _seriesInfo.GetSeriesInfo(Settings.SeriesId); + _seriesInfo.GetSeriesInfo(Settings.SeriesId, 1); return null; } catch (HttpException e) diff --git a/src/NzbDrone.Core/MetadataSource/Goodreads/GoodreadsProxy.cs b/src/NzbDrone.Core/MetadataSource/Goodreads/GoodreadsProxy.cs index d671d64817..1855b24491 100644 --- a/src/NzbDrone.Core/MetadataSource/Goodreads/GoodreadsProxy.cs +++ b/src/NzbDrone.Core/MetadataSource/Goodreads/GoodreadsProxy.cs @@ -37,13 +37,14 @@ public GoodreadsProxy(ICachedHttpResponseService cachedHttpClient, .CreateFactory(); } - public SeriesResource GetSeriesInfo(int foreignSeriesId, bool useCache = false) + public SeriesResource GetSeriesInfo(int foreignSeriesId, int page, bool useCache = false) { _logger.Debug("Getting Series with GoodreadsId of {0}", foreignSeriesId); var httpRequest = _requestBuilder.Create() .SetSegment("route", $"series/{foreignSeriesId}") .AddQueryParam("format", "xml") + .AddQueryParam("page", page) .Build(); httpRequest.AllowAutoRedirect = true; diff --git a/src/NzbDrone.Core/MetadataSource/IProvideSeriesInfo.cs b/src/NzbDrone.Core/MetadataSource/IProvideSeriesInfo.cs index a8fa2e8240..f03bd1057e 100644 --- a/src/NzbDrone.Core/MetadataSource/IProvideSeriesInfo.cs +++ b/src/NzbDrone.Core/MetadataSource/IProvideSeriesInfo.cs @@ -4,6 +4,6 @@ namespace NzbDrone.Core.MetadataSource { public interface IProvideSeriesInfo { - SeriesResource GetSeriesInfo(int id, bool useCache = true); + SeriesResource GetSeriesInfo(int id, int page, bool useCache = true); } }