add jackett client package instead of external library

also, fixed non-tv category searches resulting in 0 results
This commit is contained in:
2026-02-19 16:53:03 +03:00
parent 67a9887058
commit e293f68c4a
5 changed files with 122 additions and 31 deletions

20
jackett/client.go Normal file
View File

@@ -0,0 +1,20 @@
package jackett
type Config struct {
Host string
APIKey string
}
type Client struct {
conf Config
}
func NewClient(conf Config) *Client {
return &Client{
conf: conf,
}
}
func (c *Client) buildUrl(path string) string {
return c.conf.Host + path
}

91
jackett/search.go Normal file
View File

@@ -0,0 +1,91 @@
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
}