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

39
main.go
View File

@@ -1,6 +1,7 @@
package main
import (
"api/jackett"
"api/model"
"embed"
_ "embed"
@@ -18,7 +19,6 @@ import (
"github.com/autobrr/go-qbittorrent"
"github.com/jmoiron/sqlx"
"github.com/joho/godotenv"
"github.com/kylesanderson/go-jackett"
_ "github.com/mattn/go-sqlite3"
)
@@ -44,30 +44,13 @@ type JackettTorrent struct {
}
func checkForNewTorrents(jackettClient *jackett.Client, db *sqlx.DB, m *model.Model, item *model.Item) error {
results, err := jackettClient.TVSearch(jackett.TVSearchOptions{
Query: item.Query,
})
results, err := jackettClient.Search(item.Query, item.Category)
if err != nil {
return fmt.Errorf("couldn't get to jackett api: %v\n", err)
}
for _, torrent := range results.Channel.Item {
size := toIntOr(torrent.Size, 0)
category := toIntOr(torrent.Category[0], 5000)
pubDate, _ := time.Parse(time.RFC1123Z, torrent.PubDate)
seeders := 0
peers := 0
for _, attr := range torrent.Attr {
if attr.Name == "seeders" {
seeders = toIntOr(attr.Value, 0)
}
if attr.Name == "peers" {
peers = toIntOr(attr.Value, 0)
}
}
guidTorrent, _ := m.GetTorrentByGuidAndItemId(torrent.Guid, item.ID)
for _, torrent := range results {
guidTorrent, _ := m.GetTorrentByGuidAndItemId(torrent.GUID, item.ID)
if guidTorrent != nil {
// already have this exact one, for this item. ABORT!
continue
@@ -76,14 +59,14 @@ func checkForNewTorrents(jackettClient *jackett.Client, db *sqlx.DB, m *model.Mo
// this shit will duplicate. idk if it's ok or not, but fuck it. we ball
_, err = db.NamedExec("INSERT INTO torrents (title, guid, indexer, pubdate, size, download_url, seeders, peers, category, item_id) VALUES (:title, :guid, :indexer, :pubdate, :size, :download_url, :seeders, :peers, :category, :item_id)", map[string]any{
"title": torrent.Title,
"guid": torrent.Guid,
"indexer": torrent.Jackettindexer.ID,
"pubdate": pubDate,
"size": size,
"guid": torrent.GUID,
"indexer": torrent.TrackerID,
"pubdate": torrent.PublishDate,
"size": torrent.Size,
"download_url": torrent.Link,
"seeders": seeders,
"peers": peers,
"category": category,
"seeders": torrent.Seeders,
"peers": torrent.Peers,
"category": torrent.Category[0],
"item_id": item.ID,
})
if err != nil {