Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cardigann: check for page size #14287

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/Jackett.Common/Definitions/1337x.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ legacylinks:
- https://1337x.unblockit.click/

caps:
limitsDefault: 80
limitsMax: 80
categorymappings:
# Anime
- {id: 28, cat: TV/Anime, desc: "Anime/Anime"}
Expand Down Expand Up @@ -181,6 +183,9 @@ download:
attribute: href

search:
pageSize: 20
pageable: "{{ if or .Query.Album .Query.Artist .Keywords }}true{{ else }}false{{ end }}"

paths:
# present first page of movies tv and music results if there are no search parms supplied (20 hits per page)
- path: "{{ if or .Query.Album .Query.Artist .Keywords }}sort-search{{ else }}cat/Movies{{ end }}{{ if or .Query.Album .Query.Artist }}/{{ or .Query.Album .Query.Artist }}{{ else }}/{{ .Keywords }}{{ end }}{{ if or .Query.Album .Query.Artist .Keywords }}/{{ else }}{{ end }}{{ .Config.sort }}/{{ .Config.type }}/1/"
Expand Down
5 changes: 5 additions & 0 deletions src/Jackett.Common/Definitions/movietorrent.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ links:
- https://movietorrent.co/

caps:
limitsDefault: 36
limitsMax: 36
categorymappings:
- {id: 1, cat: Movies, desc: "Bollywood"}
- {id: 2, cat: Movies/HD, desc: "1080p"}
Expand Down Expand Up @@ -74,6 +76,9 @@ download:
- name: validfilename

search:
pageSize: 12
pageable: true

paths:
- path: "?s={{ .Keywords }}"
- path: "/page/2/?s={{ .Keywords }}"
Expand Down
22 changes: 22 additions & 0 deletions src/Jackett.Common/Definitions/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,14 @@
"type": "object",
"additionalProperties": false,
"properties": {
"limitsDefault": {
"type": "integer",
"minimum": 1
},
"limitsMax": {
"type": "integer",
"minimum": 1
},
"categories": {
"type": "object",
"additionalProperties": false,
Expand Down Expand Up @@ -482,6 +490,20 @@
"type": "object",
"additionalProperties": false,
"properties": {
"pageSize": {
"type": "integer",
"minimum": 1
},
"pageable": {
"oneOf": [
{
"type": "boolean"
},
{
"type": "string"
}
]
},
"path": {
"type": "string"
},
Expand Down
1 change: 1 addition & 0 deletions src/Jackett.Common/Indexers/BaseIndexer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public abstract class BaseIndexer : IIndexer
public virtual string Type { get; protected set; }

public virtual bool SupportsPagination => false;
public virtual int PageSize => 0;

public virtual bool IsConfigured { get; protected set; }
public virtual string[] Tags { get; protected set; }
Expand Down
25 changes: 25 additions & 0 deletions src/Jackett.Common/Indexers/CardigannIndexer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ namespace Jackett.Common.Indexers
{
public class CardigannIndexer : BaseWebIndexer
{
public override int PageSize => Definition.Search != null && Definition.Search.PageSize > 0 ? Definition.Search.PageSize : 1;

protected IndexerDefinition Definition;
protected WebResult landingResult;
protected IHtmlDocument landingResultDocument;
Expand Down Expand Up @@ -124,6 +126,8 @@ private new ConfigurationData configData
TorznabCaps = new TorznabCapabilities();
TorznabCaps.ParseCardigannSearchModes(Definition.Caps.Modes);
TorznabCaps.SupportsRawSearch = Definition.Caps.Allowrawsearch;
TorznabCaps.LimitsDefault = Definition.Caps.LimitsDefault ?? TorznabCaps.LimitsDefault;
TorznabCaps.LimitsMax = Definition.Caps.LimitsMax ?? TorznabCaps.LimitsMax;

// init config Data
configData = new ConfigurationData();
Expand Down Expand Up @@ -1353,6 +1357,13 @@ protected override async Task<IEnumerable<ReleaseInfo>> PerformQuery(TorznabQuer
variables[".Query.Keywords"] = string.Join(" ", KeywordTokens);
variables[".Keywords"] = applyFilters((string)variables[".Query.Keywords"], Search.Keywordsfilters, variables);

var pageSize = PageSize;

if (!bool.TryParse(applyGoTemplateText(Search.Pageable, variables), out var pageable))
{
pageable = false;
}

// TODO: prepare queries first and then send them parallel
var SearchPaths = Search.Paths;
foreach (var SearchPath in SearchPaths)
Expand Down Expand Up @@ -1734,14 +1745,28 @@ protected override async Task<IEnumerable<ReleaseInfo>> PerformQuery(TorznabQuer
OnParseError(results, ex);
}
}

pageSize = pageSize == 1 ? releases.Count : pageSize;

if (pageable && !IsFullPage(releases, pageSize))
{
break;
}
}

if (query.Limit > 0)
{
releases = releases.Take(query.Limit).ToList();
}

return releases;
}

protected virtual bool IsFullPage(IList<ReleaseInfo> page, int pageSize)
{
return pageSize != 0 && page.Count >= pageSize;
}

protected async Task<WebResult> handleRequest(requestBlock request, Dictionary<string, object> variables = null, string referer = null)
{
var requestLinkStr = resolvePath(applyGoTemplateText(request.Path, variables)).ToString();
Expand Down
4 changes: 4 additions & 0 deletions src/Jackett.Common/Models/IndexerDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ public class CategorymappingBlock

public class capabilitiesBlock
{
public int? LimitsMax { get; set; }
public int? LimitsDefault { get; set; }
public Dictionary<string, string> Categories { get; set; }
public List<CategorymappingBlock> Categorymappings { get; set; }
public Dictionary<string, List<string>> Modes { get; set; }
Expand Down Expand Up @@ -137,6 +139,8 @@ public class ratioBlock : selectorBlock

public class searchBlock
{
public int PageSize { get; set; }
public string Pageable { get; set; }
public string Path { get; set; }
public List<searchPathBlock> Paths { get; set; }
public Dictionary<string, List<string>> Headers { get; set; }
Expand Down