92 lines
2.8 KiB
Go
92 lines
2.8 KiB
Go
package jackett
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"net/http"
|
|
"net/url"
|
|
"strconv"
|
|
"strings"
|
|
)
|
|
|
|
type Response struct {
|
|
Results []Result `json:"results"`
|
|
Indexers []Indexer `json:"indexers"`
|
|
}
|
|
|
|
type Result struct {
|
|
FirstSeen string `json:"FirstSeen"`
|
|
Tracker string `json:"Tracker"`
|
|
TrackerID string `json:"TrackerId"`
|
|
TrackerType string `json:"TrackerType"`
|
|
CategoryDesc string `json:"CategoryDesc"`
|
|
BlackholeLink string `json:"BlackholeLink"`
|
|
Title string `json:"Title"`
|
|
GUID string `json:"Guid"`
|
|
Link string `json:"Link"`
|
|
Details string `json:"Details"`
|
|
PublishDate string `json:"PublishDate"`
|
|
Category []int `json:"Category"`
|
|
Size int64 `json:"Size"`
|
|
Files any `json:"Files"`
|
|
Grabs int `json:"Grabs"`
|
|
Description string `json:"Description"`
|
|
RageID any `json:"RageID"`
|
|
TVDBID any `json:"TVDBId"`
|
|
Imdb any `json:"Imdb"`
|
|
TMDb any `json:"TMDb"`
|
|
DoubanID any `json:"DoubanId"`
|
|
Author string `json:"Author"`
|
|
BookTitle string `json:"BookTitle"`
|
|
Seeders int `json:"Seeders"`
|
|
Peers int `json:"Peers"`
|
|
Poster any `json:"Poster"`
|
|
InfoHash any `json:"InfoHash"`
|
|
MagnetURI any `json:"MagnetUri"`
|
|
MinimumRatio any `json:"MinimumRatio"`
|
|
MinimumSeedTime any `json:"MinimumSeedTime"`
|
|
DownloadVolumeFactor float64 `json:"DownloadVolumeFactor"`
|
|
UploadVolumeFactor float64 `json:"UploadVolumeFactor"`
|
|
Gain float64 `json:"Gain"`
|
|
}
|
|
|
|
type Indexer struct {
|
|
ID string `json:"ID"`
|
|
Name string `json:"Name"`
|
|
Status int `json:"Status"`
|
|
Results int `json:"Results"`
|
|
Error string `json:"Error"`
|
|
}
|
|
|
|
func (c *Client) Search(q string, categories ...int) ([]Result, error) {
|
|
req, err := http.NewRequest("GET", c.buildUrl("/api/v2.0/indexers/all/results"), nil)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("failed to create request: %v", err)
|
|
}
|
|
|
|
query := url.Values{}
|
|
query.Add("apikey", c.conf.APIKey)
|
|
query.Add("Query", q)
|
|
|
|
categoryList := []string{}
|
|
for _, c := range categories {
|
|
categoryList = append(categoryList, strconv.Itoa(c))
|
|
}
|
|
query.Add("Category[]", strings.Join(categoryList, ","))
|
|
|
|
req.URL.RawQuery = query.Encode()
|
|
|
|
resp, err := http.DefaultClient.Do(req)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("failed to send request: %v", err)
|
|
}
|
|
defer resp.Body.Close()
|
|
|
|
response := new(Response)
|
|
if err := json.NewDecoder(resp.Body).Decode(response); err != nil {
|
|
return nil, fmt.Errorf("failed to decode response: %v", err)
|
|
}
|
|
|
|
return response.Results, nil
|
|
}
|