From 463741da1fdbba5a88107063d64f518bb315bcee Mon Sep 17 00:00:00 2001 From: Bogdan Date: Tue, 17 Sep 2024 23:19:27 +0300 Subject: [PATCH] New: Fetch up to 1000 movies from Plex Watchlist --- .../ImportLists/Plex/PlexImport.cs | 20 +++++++++---------- .../Plex/PlexListRequestGenerator.cs | 17 ++++++++-------- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/src/NzbDrone.Core/ImportLists/Plex/PlexImport.cs b/src/NzbDrone.Core/ImportLists/Plex/PlexImport.cs index 2d54213d6..66af4f4f8 100644 --- a/src/NzbDrone.Core/ImportLists/Plex/PlexImport.cs +++ b/src/NzbDrone.Core/ImportLists/Plex/PlexImport.cs @@ -13,10 +13,18 @@ namespace NzbDrone.Core.ImportLists.Plex { public class PlexImport : HttpImportListBase { - public readonly IPlexTvService _plexTvService; + public override string Name => "Plex Watchlist"; public override ImportListType ListType => ImportListType.Plex; public override TimeSpan MinRefreshInterval => TimeSpan.FromHours(6); + public override bool Enabled => true; + public override bool EnableAuto => false; + + public override int PageSize => 100; + public override TimeSpan RateLimit => TimeSpan.FromSeconds(5); + + private readonly IPlexTvService _plexTvService; + public PlexImport(IPlexTvService plexTvService, IHttpClient httpClient, IImportListStatusService importListStatusService, @@ -28,11 +36,6 @@ public PlexImport(IPlexTvService plexTvService, _plexTvService = plexTvService; } - public override string Name => "Plex Watchlist"; - public override int PageSize => 50; - public override bool Enabled => true; - public override bool EnableAuto => false; - public override ImportListFetchResult Fetch() { Settings.Validate().Filter("AccessToken").ThrowOnError(); @@ -47,10 +50,7 @@ public override IParseImportListResponse GetParser() public override IImportListRequestGenerator GetRequestGenerator() { - return new PlexListRequestGenerator(_plexTvService, PageSize) - { - Settings = Settings - }; + return new PlexListRequestGenerator(_plexTvService, Settings, PageSize); } public override object RequestAction(string action, IDictionary query) diff --git a/src/NzbDrone.Core/ImportLists/Plex/PlexListRequestGenerator.cs b/src/NzbDrone.Core/ImportLists/Plex/PlexListRequestGenerator.cs index f8ef08439..d64dcbf43 100644 --- a/src/NzbDrone.Core/ImportLists/Plex/PlexListRequestGenerator.cs +++ b/src/NzbDrone.Core/ImportLists/Plex/PlexListRequestGenerator.cs @@ -5,13 +5,16 @@ namespace NzbDrone.Core.ImportLists.Plex { public class PlexListRequestGenerator : IImportListRequestGenerator { - private readonly IPlexTvService _plexTvService; - private readonly int _pageSize; - public PlexListSettings Settings { get; set; } + private const int MaxPages = 10; - public PlexListRequestGenerator(IPlexTvService plexTvService, int pageSize) + private readonly IPlexTvService _plexTvService; + private readonly PlexListSettings _settings; + private readonly int _pageSize; + + public PlexListRequestGenerator(IPlexTvService plexTvService, PlexListSettings settings, int pageSize) { _plexTvService = plexTvService; + _settings = settings; _pageSize = pageSize; } @@ -26,11 +29,9 @@ public virtual ImportListPageableRequestChain GetMovies() private IEnumerable GetMoviesRequest() { - 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)); } } }