diff --git a/cmd/toru/flags.go b/cmd/toru/flags.go index b5d56ad..254adcd 100644 --- a/cmd/toru/flags.go +++ b/cmd/toru/flags.go @@ -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 { diff --git a/cmd/toru/search.go b/cmd/toru/search.go index d70d155..7803740 100644 --- a/cmd/toru/search.go +++ b/cmd/toru/search.go @@ -3,6 +3,7 @@ package main import ( "errors" "fmt" + "log" "os" "path" @@ -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 != "" { @@ -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 { @@ -77,7 +82,7 @@ func runSearch(cl *libtorrent.Client) error { m.PrintResults() } - if searchopts.Stream { + if searchopts.Stream || searchopts.Interactive { return SelectAndPlay(cl, m) } @@ -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) @@ -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) } @@ -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) } diff --git a/pkg/search/search.go b/pkg/search/search.go index 11c50d3..e5e0dc0 100644 --- a/pkg/search/search.go +++ b/pkg/search/search.go @@ -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 } @@ -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 }