1
0
mirror of https://github.com/mxpv/podsync.git synced 2024-05-11 05:55:04 +00:00

Fix exception when Vimeo client requests more pages then channel has

This commit is contained in:
Maksym Pavlenko
2017-01-13 17:47:58 -08:00
parent 2b0706cb4a
commit 01ba37e70c
2 changed files with 15 additions and 2 deletions

View File

@@ -79,7 +79,11 @@ namespace Podsync.Services.Videos.Vimeo
{ {
var pageSize = Math.Min(count, MaxPageSize); var pageSize = Math.Min(count, MaxPageSize);
await GetPage(path, pageIndex, pageSize, collection); var isLast = await GetPage(path, pageIndex, pageSize, collection);
if (isLast)
{
break;
}
count -= pageSize; count -= pageSize;
pageIndex++; pageIndex++;
@@ -88,7 +92,7 @@ namespace Podsync.Services.Videos.Vimeo
return collection; return collection;
} }
private async Task GetPage(string path, int pageIndex, int pageSize, List<Video> output) private async Task<bool> GetPage(string path, int pageIndex, int pageSize, List<Video> output)
{ {
dynamic resp = await QueryApi($"{path}?per_page={pageSize}&page={pageIndex}"); dynamic resp = await QueryApi($"{path}?per_page={pageSize}&page={pageIndex}");
@@ -120,6 +124,9 @@ namespace Podsync.Services.Videos.Vimeo
output.Add(video); output.Add(video);
} }
// Is last page?
return string.IsNullOrEmpty(resp.paging?.next?.ToString());
} }
private async Task<Group> QueryGroup(string path) private async Task<Group> QueryGroup(string path)

View File

@@ -57,6 +57,12 @@ namespace Podsync.Tests.Services.Videos.Vimeo
ValidateCollection(videos); ValidateCollection(videos);
} }
[Fact]
public Task PaginationTest()
{
return _client.GroupVideos("scifilondon48hr2012", 300);
}
[Fact] [Fact]
public async Task UserVideosTest() public async Task UserVideosTest()
{ {