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

Add OrderBy search option #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Feel free to check [open issues](https://github.com/irevenko/go-nyaa/issues).
* [nyaa](#nyaa "Goto #nyaa-")
* [sukebei](#sukebei "Goto #sukebei-")
* [SortBy](#sortby "Goto #sortby-")
* [OrderBy](#orderby "Goto #orderby-")
* [Filter](#filter "Goto #filter-")
* [TorrentComments](#torrentcomments "Goto #torrentcomments-")
* [TorrentDescription](#torrentdescription "Goto #torrentdescription-")
Expand All @@ -58,6 +59,7 @@ func main() {
Query: "LN",
Category: "literature",
SortBy: "seeders",
OrderBy: "desc",
Filter: "trusted-only",
}

Expand All @@ -77,6 +79,7 @@ type SearchOptions struct {
Query string
Category string
SortBy string
OrderBy string
Filter string
}
```
Expand Down Expand Up @@ -135,6 +138,10 @@ type SearchOptions struct {
- ```leechers```
- ```size```

## OrderBy
- ```desc```
- ```asc```

## Filter
- ```no-filter```
- ```no-remakes```
Expand Down
1 change: 1 addition & 0 deletions nyaa/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ type SearchOptions struct {
Query string
Category string
SortBy string
OrderBy string
Filter string
}

Expand Down
25 changes: 19 additions & 6 deletions nyaa/url.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@ const (
nyaaView = "https://nyaa.si/view/"
sukebeiView = "https://sukebei.nyaa.si/view/"

sortByComments = "&s=comments&o=desc"
sortBySeeders = "&s=seeders&o=desc"
sortByLeechers = "&s=leechers&o=desc"
sortByDownloads = "&s=downloads&o=desc"
sortBySize = "&s=size&o=desc"
sortByDate = "&s=id&o=desc"
sortByComments = "&s=comments"
sortBySeeders = "&s=seeders"
sortByLeechers = "&s=leechers"
sortByDownloads = "&s=downloads"
sortBySize = "&s=size"
sortByDate = "&s=id"

orderByAsc = "&o=asc"
orderByDesc = "&o=desc"

filterNoFilter = "&f=0"
filterNoRemakes = "&f=1"
Expand Down Expand Up @@ -186,6 +189,16 @@ func buildURL(opts SearchOptions) (string, error) {
}
}

switch opts.OrderBy {
case "desc", "":
url += orderByDesc
case "asc":
url += orderByAsc
default:
err := fmt.Errorf("such order option does not exitst\nsee docs: https://github.com/irevenko/go-nyaa#sortby")
return "", err
}

if opts.Filter != "" {
switch opts.Filter {
case "no-filter":
Expand Down