From 538abcc47b24ff2ae8a92c81b01546fba0dd578f Mon Sep 17 00:00:00 2001 From: Bogdan Date: Tue, 7 Mar 2023 01:42:33 +0200 Subject: [PATCH] Fixed: (AvistazBase) Add pagination and `SupportsPagination` --- .../Indexers/Definitions/AvistaZ.cs | 13 ++------- .../Definitions/Avistaz/AvistazBase.cs | 7 +++-- .../Avistaz/AvistazRequestGenerator.cs | 28 +++++++++++++------ .../Indexers/Definitions/CinemaZ.cs | 13 ++------- .../Indexers/Definitions/ExoticaZ.cs | 17 ++++------- .../Indexers/Definitions/PrivateHD.cs | 13 ++------- 6 files changed, 36 insertions(+), 55 deletions(-) diff --git a/src/NzbDrone.Core/Indexers/Definitions/AvistaZ.cs b/src/NzbDrone.Core/Indexers/Definitions/AvistaZ.cs index 7a55f9977..dc4a31c7f 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/AvistaZ.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/AvistaZ.cs @@ -23,17 +23,6 @@ namespace NzbDrone.Core.Indexers.Definitions { } - public override IIndexerRequestGenerator GetRequestGenerator() - { - return new AvistazRequestGenerator - { - Settings = Settings, - HttpClient = _httpClient, - Logger = _logger, - Capabilities = Capabilities - }; - } - public override IParseIndexerResponse GetParser() { return new AvistaZParser(); @@ -43,6 +32,8 @@ namespace NzbDrone.Core.Indexers.Definitions { var caps = new IndexerCapabilities { + LimitsDefault = PageSize, + LimitsMax = PageSize, TvSearchParams = new List { TvSearchParam.Q, TvSearchParam.Season, TvSearchParam.Ep, TvSearchParam.ImdbId, TvSearchParam.TvdbId, TvSearchParam.Genre diff --git a/src/NzbDrone.Core/Indexers/Definitions/Avistaz/AvistazBase.cs b/src/NzbDrone.Core/Indexers/Definitions/Avistaz/AvistazBase.cs index 090406f3a..ba8ba8201 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/Avistaz/AvistazBase.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/Avistaz/AvistazBase.cs @@ -15,7 +15,9 @@ namespace NzbDrone.Core.Indexers.Definitions.Avistaz public override DownloadProtocol Protocol => DownloadProtocol.Torrent; public override bool SupportsRss => true; public override bool SupportsSearch => true; + public override bool SupportsPagination => true; public override int PageSize => 50; + public override TimeSpan RateLimit => TimeSpan.FromSeconds(4); public override IndexerCapabilities Capabilities => SetCapabilities(); protected virtual string LoginUrl => Settings.BaseUrl + "api/v1/jackett/auth"; private IIndexerRepository _indexerRepository; @@ -36,9 +38,10 @@ namespace NzbDrone.Core.Indexers.Definitions.Avistaz return new AvistazRequestGenerator { Settings = Settings, + Capabilities = Capabilities, + PageSize = PageSize, HttpClient = _httpClient, - Logger = _logger, - Capabilities = Capabilities + Logger = _logger }; } diff --git a/src/NzbDrone.Core/Indexers/Definitions/Avistaz/AvistazRequestGenerator.cs b/src/NzbDrone.Core/Indexers/Definitions/Avistaz/AvistazRequestGenerator.cs index dfa9fc168..f5dd45d26 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/Avistaz/AvistazRequestGenerator.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/Avistaz/AvistazRequestGenerator.cs @@ -12,23 +12,35 @@ namespace NzbDrone.Core.Indexers.Definitions.Avistaz public class AvistazRequestGenerator : IIndexerRequestGenerator { public AvistazSettings Settings { get; set; } - public IIndexerHttpClient HttpClient { get; set; } public IndexerCapabilities Capabilities { get; set; } + public int PageSize { get; set; } + public IIndexerHttpClient HttpClient { get; set; } public Logger Logger { get; set; } public Func> GetCookies { get; set; } public Action, DateTime?> CookiesUpdater { get; set; } + protected virtual string SearchUrl => Settings.BaseUrl + "api/v1/jackett/torrents"; // hook to adjust the search category - protected virtual List> GetBasicSearchParameters(int[] categories, string genre) + protected virtual List> GetBasicSearchParameters(SearchCriteriaBase searchCriteria, string genre = null) { + var categories = searchCriteria.Categories ?? Array.Empty(); + var categoryMapping = Capabilities.Categories.MapTorznabCapsToTrackers(categories).Distinct().ToList(); + var qc = new List> // NameValueCollection don't support cat[]=19&cat[]=6 { { "in", "1" }, - { "type", categoryMapping.Any() ? categoryMapping.First() : "0" } + { "type", categoryMapping.FirstIfSingleOrDefault("0") }, + { "limit", Math.Min(PageSize, searchCriteria.Limit.GetValueOrDefault(PageSize)).ToString() } }; + if (searchCriteria.Limit is > 0 && searchCriteria.Offset is > 0) + { + var page = (int)(searchCriteria.Offset / searchCriteria.Limit) + 1; + qc.Add("page", page.ToString()); + } + if (Settings.FreeleechOnly) { qc.Add("discount[]", "1"); @@ -78,7 +90,7 @@ namespace NzbDrone.Core.Indexers.Definitions.Avistaz public IndexerPageableRequestChain GetSearchRequests(MovieSearchCriteria searchCriteria) { - var parameters = GetBasicSearchParameters(searchCriteria.Categories, searchCriteria.Genre); + var parameters = GetBasicSearchParameters(searchCriteria, searchCriteria.Genre); if (searchCriteria.ImdbId.IsNotNullOrWhiteSpace()) { @@ -100,7 +112,7 @@ namespace NzbDrone.Core.Indexers.Definitions.Avistaz public IndexerPageableRequestChain GetSearchRequests(MusicSearchCriteria searchCriteria) { - var parameters = GetBasicSearchParameters(searchCriteria.Categories, null); + var parameters = GetBasicSearchParameters(searchCriteria); parameters.Add("search", GetSearchTerm(searchCriteria.SanitizedSearchTerm).Trim()); @@ -111,7 +123,7 @@ namespace NzbDrone.Core.Indexers.Definitions.Avistaz public IndexerPageableRequestChain GetSearchRequests(TvSearchCriteria searchCriteria) { - var parameters = GetBasicSearchParameters(searchCriteria.Categories, searchCriteria.Genre); + var parameters = GetBasicSearchParameters(searchCriteria, searchCriteria.Genre); if (searchCriteria.ImdbId.IsNotNullOrWhiteSpace()) { @@ -135,7 +147,7 @@ namespace NzbDrone.Core.Indexers.Definitions.Avistaz public IndexerPageableRequestChain GetSearchRequests(BookSearchCriteria searchCriteria) { - throw new NotImplementedException(); + return new IndexerPageableRequestChain(); } // hook to adjust the search term @@ -143,7 +155,7 @@ namespace NzbDrone.Core.Indexers.Definitions.Avistaz public IndexerPageableRequestChain GetSearchRequests(BasicSearchCriteria searchCriteria) { - var parameters = GetBasicSearchParameters(searchCriteria.Categories, null); + var parameters = GetBasicSearchParameters(searchCriteria); parameters.Add("search", GetSearchTerm(searchCriteria.SanitizedSearchTerm).Trim()); diff --git a/src/NzbDrone.Core/Indexers/Definitions/CinemaZ.cs b/src/NzbDrone.Core/Indexers/Definitions/CinemaZ.cs index 16f819574..3f0fdd913 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/CinemaZ.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/CinemaZ.cs @@ -23,21 +23,12 @@ namespace NzbDrone.Core.Indexers.Definitions { } - public override IIndexerRequestGenerator GetRequestGenerator() - { - return new AvistazRequestGenerator - { - Settings = Settings, - HttpClient = _httpClient, - Logger = _logger, - Capabilities = Capabilities - }; - } - protected override IndexerCapabilities SetCapabilities() { var caps = new IndexerCapabilities { + LimitsDefault = PageSize, + LimitsMax = PageSize, TvSearchParams = new List { TvSearchParam.Q, TvSearchParam.Season, TvSearchParam.Ep, TvSearchParam.ImdbId, TvSearchParam.Genre diff --git a/src/NzbDrone.Core/Indexers/Definitions/ExoticaZ.cs b/src/NzbDrone.Core/Indexers/Definitions/ExoticaZ.cs index aa03e6f32..954d2442c 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/ExoticaZ.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/ExoticaZ.cs @@ -24,17 +24,6 @@ namespace NzbDrone.Core.Indexers.Definitions { } - public override IIndexerRequestGenerator GetRequestGenerator() - { - return new AvistazRequestGenerator - { - Settings = Settings, - HttpClient = _httpClient, - Logger = _logger, - Capabilities = Capabilities, - }; - } - public override IParseIndexerResponse GetParser() { return new ExoticaZParser(Capabilities.Categories); @@ -42,7 +31,11 @@ namespace NzbDrone.Core.Indexers.Definitions protected override IndexerCapabilities SetCapabilities() { - var caps = new IndexerCapabilities(); + var caps = new IndexerCapabilities + { + LimitsDefault = PageSize, + LimitsMax = PageSize + }; caps.Categories.AddCategoryMapping(1, NewznabStandardCategory.XXXx264, "Video Clip"); caps.Categories.AddCategoryMapping(2, NewznabStandardCategory.XXXPack, "Video Pack"); diff --git a/src/NzbDrone.Core/Indexers/Definitions/PrivateHD.cs b/src/NzbDrone.Core/Indexers/Definitions/PrivateHD.cs index bc3b34e5a..f12975ee4 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/PrivateHD.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/PrivateHD.cs @@ -23,21 +23,12 @@ namespace NzbDrone.Core.Indexers.Definitions { } - public override IIndexerRequestGenerator GetRequestGenerator() - { - return new AvistazRequestGenerator - { - Settings = Settings, - HttpClient = _httpClient, - Logger = _logger, - Capabilities = Capabilities - }; - } - protected override IndexerCapabilities SetCapabilities() { var caps = new IndexerCapabilities { + LimitsDefault = PageSize, + LimitsMax = PageSize, TvSearchParams = new List { TvSearchParam.Q, TvSearchParam.Season, TvSearchParam.Ep, TvSearchParam.ImdbId, TvSearchParam.TvdbId, TvSearchParam.Genre