Skip to content

Commit

Permalink
add page size and SupportsPagination
Browse files Browse the repository at this point in the history
  • Loading branch information
mynameisbogdan committed Mar 5, 2023
1 parent fcb7975 commit 236457b
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 10 deletions.
3 changes: 2 additions & 1 deletion src/Jackett.Common/Definitions/anilibria.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ settings:
default: false

search:
pageSize: 100
paths:
# https://github.com/anilibria/docs/blob/master/api_v3.md
- path: "https://api.anilibria.tv/v3/{{ if .Keywords }}searchTitles?search={{ .Keywords }}&{{ else }}getUpdates?{{ end }}filter=names,posters.small.url,code,torrents.list,season.year,description&limit={{ if eq .Query.Limit \"0\" }}100{{ else }}{{ .Query.Limit }}{{ end }}&after={{ .Query.Offset }}"
- path: "https://api.anilibria.tv/v3/{{ if .Keywords }}searchTitles?search={{ .Keywords }}&{{ else }}getUpdates?{{ end }}filter=names,posters.small.url,code,torrents.list,season.year,description&limit={{ if .Query.Limit }}{{ .Query.Limit }}{{ else }}{{ .PageSize }}{{ end }}&after={{ .Query.Offset }}"
response:
type: json

Expand Down
6 changes: 4 additions & 2 deletions src/Jackett.Common/Definitions/animetracker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ login:
text: "The API key was not accepted by {{ .Config.sitelink }}."

search:
pageSize: 100
firstPageNumber: 1
paths:
# https://hdinnovations.github.io/UNIT3D-Community-Edition-Docs/api_endpoints.html
# https://github.com/HDInnovations/UNIT3D-Community-Edition/blob/master/app/Http/Controllers/API/TorrentController.php
Expand All @@ -84,8 +86,8 @@ search:
$raw: "{{ if .Query.Season }}&seasonNumber={{ .Query.Season }}{{ else }}{{ end }}{{ if .Query.Ep }}&episodeNumber={{ .Query.Ep }}{{ else }}{{ end }}{{ if .Query.TMDBID }}&tmdbId={{ .Query.TMDBID }}{{ else }}{{ end }}{{ if .Query.IMDBIDShort }}&imdbId={{ .Query.IMDBIDShort }}{{ else }}{{ end }}{{ if .Query.TVDBID }}&tvdbId={{ .Query.TVDBID }}{{ else }}{{ end }}{{ range .Categories }}&categories[]={{.}}{{end}}{{ if .Config.freeleech }}&free=1{{ else }}{{ end }}"
sortField: "{{ .Config.sort }}"
sortDirection: "{{ .Config.type }}"
perPage: "{{ if eq .Query.Limit \"0\" }}100{{ else }}{{ .Query.Limit }}{{ end }}"
page: 1
perPage: "{{ if .Query.Limit }}{{ .Query.Limit }}{{ else }}{{ .PageSize }}{{ end }}"
page: "{{ .Query.Page }}"

keywordsfilters:
- name: re_replace
Expand Down
3 changes: 2 additions & 1 deletion src/Jackett.Common/Definitions/bigfangroup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ settings:
asc: asc

search:
pageSize: 1
# https://bigfangroup.org/browse.php?search=black+lightning&cat=0&incldead=0&year=0&format=0
paths:
- path: browse.php
Expand All @@ -98,7 +99,7 @@ search:
format: 0
s: "{{ .Config.sort }}"
d: "{{ .Config.type }}"
page: "{{ .Query.CurrentPage0 }}"
page: "{{ .Query.Page }}"

rows:
selector: table > tbody#highlighted > tr:has(a[href^="browse.php?cat="])
Expand Down
4 changes: 3 additions & 1 deletion src/Jackett.Common/Definitions/bitsearch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,16 @@ settings:
asc: asc

search:
pageSize: 1
firstPageNumber: 1
paths:
# https://bitsearch.to/search?q=&sort=date&order=desc
- path: search
inputs:
q: "{{ .Keywords }}"
sort: "{{ .Config.sort }}"
order: "{{ .Config.type }}"
page: "{{ .Query.CurrentPage1 }}"
page: "{{ .Query.Page }}"

keywordsfilters:
- name: re_replace
Expand Down
6 changes: 4 additions & 2 deletions src/Jackett.Common/Definitions/blutopia-api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ login:
text: "The API key was not accepted by {{ .Config.sitelink }}."

search:
pageSize: 100
firstPageNumber: 1
paths:
# https://hdinnovations.github.io/UNIT3D-Community-Edition-Docs/api_endpoints.html
# https://github.com/HDInnovations/UNIT3D-Community-Edition/blob/master/app/Http/Controllers/API/TorrentController.php
Expand All @@ -76,8 +78,8 @@ search:
$raw: "{{ if .Query.Season }}&seasonNumber={{ .Query.Season }}{{ else }}{{ end }}{{ if .Query.Ep }}&episodeNumber={{ .Query.Ep }}{{ else }}{{ end }}{{ if .Query.TMDBID }}&tmdbId={{ .Query.TMDBID }}{{ else }}{{ end }}{{ if .Query.IMDBIDShort }}&imdbId={{ .Query.IMDBIDShort }}{{ else }}{{ end }}{{ if .Query.TVDBID }}&tvdbId={{ .Query.TVDBID }}{{ else }}{{ end }}{{ range .Categories }}&categories[]={{.}}{{end}}{{ if .Config.freeleech }}&free[]=100{{ else }}{{ end }}"
sortField: "{{ .Config.sort }}"
sortDirection: "{{ .Config.type }}"
perPage: 100
page: 1
perPage: "{{ if .Query.Limit }}{{ .Query.Limit }}{{ else }}{{ .PageSize }}{{ end }}"
page: "{{ .Query.Page }}"

keywordsfilters:
- name: re_replace
Expand Down
3 changes: 2 additions & 1 deletion src/Jackett.Common/Definitions/digitalcore.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ login:
cookie: "{{ .Config.cookie }}"

search:
pageSize: 100
paths:
- path: api/v1/torrents
response:
Expand All @@ -107,7 +108,7 @@ search:
extendedSearch: false
freeleech: "{{ if .Config.freeleech }}true{{ else }}false{{ end }}"
index: "{{ .Query.Offset }}"
limit: "{{ if eq .Query.Limit \"0\" }}100{{ else }}{{ .Query.Limit }}{{ end }}"
limit: "{{ if .Query.Limit }}{{ .Query.Limit }}{{ else }}{{ .PageSize }}{{ end }}"
order: "{{ .Config.type }}"
page: search
searchText: "{{ if .Query.IMDBID }}{{ .Query.IMDBID }} {{ else }}{{ end }}{{ .Keywords }}"
Expand Down
12 changes: 10 additions & 2 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 bool SupportsPagination => Definition.Search != null && Definition.Search.PageSize > 0;

protected IndexerDefinition Definition;
protected WebResult landingResult;
protected IHtmlDocument landingResultDocument;
Expand Down Expand Up @@ -1310,8 +1312,6 @@ protected override async Task<IEnumerable<ReleaseInfo>> PerformQuery(TorznabQuer
variables[".Query.Year"] = query.Year?.ToString() ?? null;
variables[".Query.Limit"] = query.Limit.ToString() ?? null;
variables[".Query.Offset"] = query.Offset.ToString() ?? null;
variables[".Query.CurrentPage0"] = Math.Max(0, query.Offset > 0 && query.Limit > 0 ? query.Offset / query.Limit : 0).ToString();
variables[".Query.CurrentPage1"] = Math.Max(1, query.Offset > 0 && query.Limit > 0 ? (query.Offset / query.Limit) + 1 : 1).ToString();
variables[".Query.Extended"] = query.Extended.ToString();
variables[".Query.Categories"] = query.Categories;
variables[".Query.APIKey"] = query.ApiKey;
Expand Down Expand Up @@ -1355,6 +1355,14 @@ 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 = Search.PageSize;

if (pageSize > 0)
variables[".PageSize"] = pageSize.ToString();

var page = query.Limit > 0 && query.Offset > 0 ? (query.Offset / query.Limit) + Search.FirstPageNumber : Search.FirstPageNumber;
variables[".Query.Page"] = page.ToString();

// TODO: prepare queries first and then send them parallel
var SearchPaths = Search.Paths;
foreach (var SearchPath in SearchPaths)
Expand Down
2 changes: 2 additions & 0 deletions src/Jackett.Common/Models/IndexerDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ public class ratioBlock : selectorBlock

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

0 comments on commit 236457b

Please sign in to comment.