diff --git a/src/NzbDrone.Core/Indexers/Definitions/RetroFlix.cs b/src/NzbDrone.Core/Indexers/Definitions/RetroFlix.cs index c62b97115..85b2583b9 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/RetroFlix.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/RetroFlix.cs @@ -40,7 +40,7 @@ namespace NzbDrone.Core.Indexers.Definitions BookSearchParams = new List { BookSearchParam.Q, - }, + } }; caps.Categories.AddCategoryMapping(401, NewznabStandardCategory.Movies, "Movies"); diff --git a/src/NzbDrone.Core/Indexers/Definitions/SpeedApp.cs b/src/NzbDrone.Core/Indexers/Definitions/SpeedApp.cs index b4ba75ada..c1dfc58ba 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/SpeedApp.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/SpeedApp.cs @@ -8,8 +8,8 @@ namespace NzbDrone.Core.Indexers.Definitions public class SpeedApp : SpeedAppBase { public override string Name => "SpeedApp.io"; - public override string[] IndexerUrls => new string[] { "https://speedapp.io/" }; - public override string[] LegacyUrls => new string[] { "https://speedapp.io" }; + public override string[] IndexerUrls => new[] { "https://speedapp.io/" }; + public override string[] LegacyUrls => new[] { "https://speedapp.io" }; public override string Description => "SpeedApp is a ROMANIAN Private Torrent Tracker for MOVIES / TV / GENERAL"; public override string Language => "ro-RO"; public override IndexerPrivacy Privacy => IndexerPrivacy.Private; @@ -38,7 +38,7 @@ namespace NzbDrone.Core.Indexers.Definitions BookSearchParams = new List { BookSearchParam.Q, - }, + } }; caps.Categories.AddCategoryMapping(38, NewznabStandardCategory.Movies, "Movie Packs"); diff --git a/src/NzbDrone.Core/Indexers/Definitions/SpeedApp/SpeedAppBase.cs b/src/NzbDrone.Core/Indexers/Definitions/SpeedApp/SpeedAppBase.cs index 1fed8e6fe..eb8309205 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/SpeedApp/SpeedAppBase.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/SpeedApp/SpeedAppBase.cs @@ -31,6 +31,7 @@ namespace NzbDrone.Core.Indexers.Definitions private string LoginUrl => Settings.BaseUrl + "api/login"; public override Encoding Encoding => Encoding.UTF8; public override DownloadProtocol Protocol => DownloadProtocol.Torrent; + public override int PageSize => 100; public override IndexerCapabilities Capabilities => SetCapabilities(); protected virtual int MinimumSeedTime => 172800; // 48 hours private IIndexerRepository _indexerRepository; @@ -43,7 +44,7 @@ namespace NzbDrone.Core.Indexers.Definitions public override IIndexerRequestGenerator GetRequestGenerator() { - return new SpeedAppRequestGenerator(Capabilities, Settings); + return new SpeedAppRequestGenerator(Capabilities, Settings, PageSize); } public override IParseIndexerResponse GetParser() @@ -168,26 +169,25 @@ namespace NzbDrone.Core.Indexers.Definitions protected virtual IndexerCapabilities SetCapabilities() { - var caps = new IndexerCapabilities(); - - return caps; + return new IndexerCapabilities(); } } public class SpeedAppRequestGenerator : IIndexerRequestGenerator { + private readonly IndexerCapabilities _capabilities; + private readonly SpeedAppSettings _settings; + private readonly int _pageSize; + public Func> GetCookies { get; set; } public Action, DateTime?> CookiesUpdater { get; set; } - private IndexerCapabilities Capabilities { get; } - - private SpeedAppSettings Settings { get; } - - public SpeedAppRequestGenerator(IndexerCapabilities capabilities, SpeedAppSettings settings) + public SpeedAppRequestGenerator(IndexerCapabilities capabilities, SpeedAppSettings settings, int pageSize) { - Capabilities = capabilities; - Settings = settings; + _capabilities = capabilities; + _settings = settings; + _pageSize = pageSize; } public IndexerPageableRequestChain GetSearchRequests(MovieSearchCriteria searchCriteria) @@ -219,54 +219,62 @@ namespace NzbDrone.Core.Indexers.Definitions { var pageableRequests = new IndexerPageableRequestChain(); - pageableRequests.Add(GetPagedRequests($"{searchCriteria.SanitizedSearchTerm}", searchCriteria.Categories, imdbId, season, episode)); + pageableRequests.Add(GetPagedRequests($"{searchCriteria.SanitizedSearchTerm}", searchCriteria.Categories, searchCriteria.Limit ?? _pageSize, searchCriteria.Offset ?? 0, imdbId, season, episode)); return pageableRequests; } - private IEnumerable GetPagedRequests(string term, int[] categories, string imdbId = null, int? season = null, string episode = null) + private IEnumerable GetPagedRequests(string term, int[] categories, int limit, int offset, string imdbId = null, int? season = null, string episode = null) { - var qc = new NameValueCollection() + limit = Math.Min(_pageSize, limit); + offset = Math.Max(0, offset); + + var parameters = new NameValueCollection { - { "itemsPerPage", "100" }, + { "itemsPerPage", limit.ToString() }, { "sort", "torrent.createdAt" }, { "direction", "desc" } }; + if (limit > 0 && offset > 0) + { + var page = (offset / limit) + 1; + parameters.Set("page", page.ToString()); + } + if (imdbId.IsNotNullOrWhiteSpace()) { - qc.Add("imdbId", imdbId); + parameters.Set("imdbId", imdbId); } else { - qc.Add("search", term); + parameters.Set("search", term); } if (season != null) { - qc.Add("season", season.Value.ToString()); + parameters.Set("season", season.Value.ToString()); } if (episode != null) { - qc.Add("episode", episode); + parameters.Set("episode", episode); } - var cats = Capabilities.Categories.MapTorznabCapsToTrackers(categories); - + var cats = _capabilities.Categories.MapTorznabCapsToTrackers(categories); if (cats.Count > 0) { foreach (var cat in cats) { - qc.Add("categories[]", cat); + parameters.Add("categories[]", cat); } } - var searchUrl = Settings.BaseUrl + "api/torrent?" + qc.GetQueryString(duplicateKeysIfMulti: true); + var searchUrl = _settings.BaseUrl + "api/torrent?" + parameters.GetQueryString(duplicateKeysIfMulti: true); var request = new IndexerRequest(searchUrl, HttpAccept.Json); - request.HttpRequest.Headers.Set("Authorization", $"Bearer {Settings.ApiKey}"); + request.HttpRequest.Headers.Set("Authorization", $"Bearer {_settings.ApiKey}"); yield return request; }