Skip to content

Commit

Permalink
[toru] add the ability to pass a nyaa proxy site like sukebei.nyaa.si…
Browse files Browse the repository at this point in the history
… oor nyaa.ink.sii
  • Loading branch information
sweetbbak committed Feb 20, 2024
1 parent 88c5aa2 commit 4cd52de
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
2 changes: 1 addition & 1 deletion cmd/toru/flags.go
Expand Up @@ -51,7 +51,7 @@ type Search struct {
List bool `short:"l" long:"list" description:"list all accepted arguments for searching by categories"`
Json bool `short:"j" long:"json" description:"output search results as Json"`
Stdout bool `short:"P" long:"print" description:"output search results in a pretty and readable format to stdout"`
Interactive bool `short:"i" long:"fzf" description:"interact with the search results using fzf"`
Interactive bool `short:"i" long:"interactive" description:"interact with the search results using fzf"`

// actual search query, doesn't matter where it is placed and is OPTIONAL
Args struct {
Expand Down
26 changes: 19 additions & 7 deletions cmd/toru/search.go
Expand Up @@ -3,6 +3,7 @@ package main
import (
"errors"
"fmt"
"log"
"os"
"path"

Expand All @@ -21,9 +22,9 @@ func runSearch(cl *libtorrent.Client) error {
return nil
}

if searchopts.Interactive {
return InteractiveSearch(cl)
}
// if searchopts.Interactive {
// return InteractiveSearch(cl)
// }

// build the query
if searchopts.Category != "" {
Expand Down Expand Up @@ -58,6 +59,10 @@ func runSearch(cl *libtorrent.Client) error {
}
}

if searchopts.Proxy != "" {
s.ProxyURL = searchopts.Proxy
}

// make the request for results to nyaa.si
m, err := s.Query()
if err != nil {
Expand All @@ -77,7 +82,7 @@ func runSearch(cl *libtorrent.Client) error {
m.PrintResults()
}

if searchopts.Stream {
if searchopts.Stream || searchopts.Interactive {
return SelectAndPlay(cl, m)
}

Expand All @@ -104,7 +109,10 @@ func InteractiveSearch(cl *libtorrent.Client) error {
}

cj := path.Join(cl.DataDir, "cache.json")
m.Cache(cj)
err = m.Cache(cj)
if err != nil {
log.Println(err)
}

LOOP:
choice, err := fzfMenu(m.Media)
Expand All @@ -126,7 +134,9 @@ LOOP:
case "select":
goto LOOP
case "search":
InteractiveSearch(cl)
if err := InteractiveSearch(cl); err != nil {
log.Fatal(err)
}
case "exit":
os.Exit(0)
}
Expand Down Expand Up @@ -158,7 +168,9 @@ LOOP:
case "select":
goto LOOP
case "search":
InteractiveSearch(cl)
if err := InteractiveSearch(cl); err != nil {
log.Fatal(err)
}
case "exit":
os.Exit(0)
}
Expand Down
7 changes: 6 additions & 1 deletion pkg/search/search.go
Expand Up @@ -142,7 +142,12 @@ func (search *Search) Query() (*Results, error) {
s.Category = cat
res := &Results{}

// error parsing html or error getting nyaa page
res.Media, err = nyaa.Search(search.Args.Query, s)
if err != nil {
return nil, err
}

return res, nil
}

Expand All @@ -159,7 +164,7 @@ func LatestAnime(query, proxy string, page uint) (*Results, error) {
p.Proxy = proxy
}

m, err := nyaa.Search(query)
m, err := nyaa.Search(query, p)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 4cd52de

Please sign in to comment.