Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using FluentValidation.Results;
using NLog;
Expand Down Expand Up @@ -36,18 +37,19 @@ public override IList<ImportListItemInfo> 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);
Expand All @@ -60,6 +62,26 @@ public override IList<ImportListItemInfo> Fetch()
return CleanupListItems(result);
}

private List<ImportListItemInfo> FetchPage(int page)
{
var series = _seriesInfo.GetSeriesInfo(Settings.SeriesId, page);
var result = new List<ImportListItemInfo>();

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<ValidationFailure> failures)
{
failures.AddIfNotNull(TestConnection());
Expand All @@ -69,7 +91,7 @@ private ValidationFailure TestConnection()
{
try
{
_seriesInfo.GetSeriesInfo(Settings.SeriesId);
_seriesInfo.GetSeriesInfo(Settings.SeriesId, 1);
return null;
}
catch (HttpException e)
Expand Down
3 changes: 2 additions & 1 deletion src/NzbDrone.Core/MetadataSource/Goodreads/GoodreadsProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/NzbDrone.Core/MetadataSource/IProvideSeriesInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Loading