New: Fetch up to 1000 series from Plex Watchlist

pull/7236/head
Bogdan 5 months ago committed by Mark McDowall
parent 27da041388
commit 0fa8e24f48

@ -14,11 +14,15 @@ namespace NzbDrone.Core.ImportLists.Plex
{ {
public class PlexImport : HttpImportListBase<PlexListSettings> public class PlexImport : HttpImportListBase<PlexListSettings>
{ {
public readonly IPlexTvService _plexTvService; public override string Name => _localizationService.GetLocalizedString("ImportListsPlexSettingsWatchlistName");
public override ImportListType ListType => ImportListType.Plex; public override ImportListType ListType => ImportListType.Plex;
public override TimeSpan MinRefreshInterval => TimeSpan.FromHours(6); public override TimeSpan MinRefreshInterval => TimeSpan.FromHours(6);
public override int PageSize => 100;
public override TimeSpan RateLimit => TimeSpan.FromSeconds(5);
private readonly IPlexTvService _plexTvService;
public PlexImport(IPlexTvService plexTvService, public PlexImport(IPlexTvService plexTvService,
IHttpClient httpClient, IHttpClient httpClient,
IImportListStatusService importListStatusService, IImportListStatusService importListStatusService,
@ -31,15 +35,10 @@ namespace NzbDrone.Core.ImportLists.Plex
_plexTvService = plexTvService; _plexTvService = plexTvService;
} }
public override string Name => _localizationService.GetLocalizedString("ImportListsPlexSettingsWatchlistName");
public override int PageSize => 50;
public override ImportListFetchResult Fetch() public override ImportListFetchResult Fetch()
{ {
Settings.Validate().Filter("AccessToken").ThrowOnError(); Settings.Validate().Filter("AccessToken").ThrowOnError();
// var generator = GetRequestGenerator();
return FetchItems(g => g.GetListItems()); return FetchItems(g => g.GetListItems());
} }
@ -50,10 +49,7 @@ namespace NzbDrone.Core.ImportLists.Plex
public override IImportListRequestGenerator GetRequestGenerator() public override IImportListRequestGenerator GetRequestGenerator()
{ {
return new PlexListRequestGenerator(_plexTvService, PageSize) return new PlexListRequestGenerator(_plexTvService, Settings, PageSize);
{
Settings = Settings
};
} }
public override object RequestAction(string action, IDictionary<string, string> query) public override object RequestAction(string action, IDictionary<string, string> query)

@ -5,13 +5,16 @@ namespace NzbDrone.Core.ImportLists.Plex
{ {
public class PlexListRequestGenerator : IImportListRequestGenerator public class PlexListRequestGenerator : IImportListRequestGenerator
{ {
private const int MaxPages = 10;
private readonly IPlexTvService _plexTvService; private readonly IPlexTvService _plexTvService;
private readonly PlexListSettings _settings;
private readonly int _pageSize; private readonly int _pageSize;
public PlexListSettings Settings { get; set; }
public PlexListRequestGenerator(IPlexTvService plexTvService, int pageSize) public PlexListRequestGenerator(IPlexTvService plexTvService, PlexListSettings settings, int pageSize)
{ {
_plexTvService = plexTvService; _plexTvService = plexTvService;
_settings = settings;
_pageSize = pageSize; _pageSize = pageSize;
} }
@ -26,11 +29,9 @@ namespace NzbDrone.Core.ImportLists.Plex
private IEnumerable<ImportListRequest> GetSeriesRequest() private IEnumerable<ImportListRequest> GetSeriesRequest()
{ {
var maxPages = 10; for (var page = 0; page < MaxPages; page++)
for (var page = 0; page < maxPages; page++)
{ {
yield return new ImportListRequest(_plexTvService.GetWatchlist(Settings.AccessToken, _pageSize, page * _pageSize)); yield return new ImportListRequest(_plexTvService.GetWatchlist(_settings.AccessToken, _pageSize, page * _pageSize));
} }
} }
} }

Loading…
Cancel
Save