diff --git a/src/NzbDrone.Core/ImportLists/Plex/PlexImport.cs b/src/NzbDrone.Core/ImportLists/Plex/PlexImport.cs index c1f5f61e8..5edb0fa91 100644 --- a/src/NzbDrone.Core/ImportLists/Plex/PlexImport.cs +++ b/src/NzbDrone.Core/ImportLists/Plex/PlexImport.cs @@ -31,6 +31,7 @@ namespace NzbDrone.Core.ImportLists.Plex } public override string Name => "Plex Watchlist"; + public override int PageSize => 50; public override IList Fetch() { @@ -48,7 +49,7 @@ namespace NzbDrone.Core.ImportLists.Plex public override IImportListRequestGenerator GetRequestGenerator() { - return new PlexListRequestGenerator(_plexTvService) + return new PlexListRequestGenerator(_plexTvService, PageSize) { Settings = Settings }; diff --git a/src/NzbDrone.Core/ImportLists/Plex/PlexListRequestGenerator.cs b/src/NzbDrone.Core/ImportLists/Plex/PlexListRequestGenerator.cs index 2913cbb81..30909dd61 100644 --- a/src/NzbDrone.Core/ImportLists/Plex/PlexListRequestGenerator.cs +++ b/src/NzbDrone.Core/ImportLists/Plex/PlexListRequestGenerator.cs @@ -6,11 +6,13 @@ namespace NzbDrone.Core.ImportLists.Plex public class PlexListRequestGenerator : IImportListRequestGenerator { private readonly IPlexTvService _plexTvService; + private readonly int _pageSize; public PlexListSettings Settings { get; set; } - public PlexListRequestGenerator(IPlexTvService plexTvService) + public PlexListRequestGenerator(IPlexTvService plexTvService, int pageSize) { _plexTvService = plexTvService; + _pageSize = pageSize; } public virtual ImportListPageableRequestChain GetListItems() @@ -24,9 +26,12 @@ namespace NzbDrone.Core.ImportLists.Plex private IEnumerable GetSeriesRequest() { - var request = new ImportListRequest(_plexTvService.GetWatchlist(Settings.AccessToken)); + var maxPages = 10; - yield return request; + for (var page = 0; page < maxPages; page++) + { + yield return new ImportListRequest(_plexTvService.GetWatchlist(Settings.AccessToken, _pageSize, page * _pageSize)); + } } } } diff --git a/src/NzbDrone.Core/Notifications/Plex/PlexTv/PlexTvService.cs b/src/NzbDrone.Core/Notifications/Plex/PlexTv/PlexTvService.cs index 280c73bd2..ecc2c4392 100644 --- a/src/NzbDrone.Core/Notifications/Plex/PlexTv/PlexTvService.cs +++ b/src/NzbDrone.Core/Notifications/Plex/PlexTv/PlexTvService.cs @@ -1,7 +1,6 @@ using System; using System.Linq; using System.Net.Http; -using System.Text; using NzbDrone.Common.Cache; using NzbDrone.Common.EnvironmentInfo; using NzbDrone.Common.Http; @@ -15,7 +14,7 @@ namespace NzbDrone.Core.Notifications.Plex.PlexTv PlexTvSignInUrlResponse GetSignInUrl(string callbackUrl, int pinId, string pinCode); string GetAuthToken(int pinId); void Ping(string authToken); - HttpRequest GetWatchlist(string authToken); + HttpRequest GetWatchlist(string authToken, int pageSize, int pageOffset); } public class PlexTvService : IPlexTvService @@ -94,7 +93,7 @@ namespace NzbDrone.Core.Notifications.Plex.PlexTv _cache.Get(authToken, () => _proxy.Ping(_configService.PlexClientIdentifier, authToken), TimeSpan.FromHours(24)); } - public HttpRequest GetWatchlist(string authToken) + public HttpRequest GetWatchlist(string authToken, int pageSize, int pageOffset) { Ping(authToken); @@ -110,7 +109,9 @@ namespace NzbDrone.Core.Notifications.Plex.PlexTv .AddQueryParam("includeFields", "title,type,year,ratingKey") .AddQueryParam("includeElements", "Guid") .AddQueryParam("sort", "watchlistedAt:desc") - .AddQueryParam("type", (int)PlexMediaType.Show); + .AddQueryParam("type", (int)PlexMediaType.Show) + .AddQueryParam("X-Plex-Container-Size", pageSize) + .AddQueryParam("X-Plex-Container-Start", pageOffset); if (!string.IsNullOrWhiteSpace(authToken)) {