Files
bvandeusenandClaude Opus 5.5 a2e1890d4c
release / govulncheck (push) Successful in 34s
release / web (push) Successful in 1m13s
release / go (push) Successful in 2m12s
release / integration (push) Successful in 4m6s
release / Build signed APK (releases and dev) (push) Successful in 8m41s
release / android (push) Successful in 9m47s
release / Attach APK to the Release (tag releases only) (push) Skipped
release / Build + push container image (push) Successful in 59s
release / Verify release artifacts (tag releases only) (push) Skipped
feat: indexers and download clients you add and configure (M502 #5518)
Admin → Integrations gains "Indexers and download clients": two lists of
connections the operator adds, Fabled Librarian's model. Nothing is seeded
or copied from Lidarr.

- Indexers: Prowlarr (its native /api/v1/search, which asks every indexer
  at once; Prowlarr has no aggregate Torznab feed) and any Torznab feed.
- Download clients: qBittorrent (WebUI v2, with re-login on an expired
  session) and FabledExchange, one entry with a switch per job:
  downloads (/api/downloads), search (/api/search) and release details
  (/api/torrents/{infohash}). All three start on; its key is optional.
- Each entry: enable, name, address, a write-only key or password, Test.
  A download client's Test lists its torrents and checks the downloads
  folder is visible and writable from Minstrel; an Exchange's Test
  reports each job switched on.
- Download clients carry a path mapping (Minstrel's /downloads vs the
  client's own name for it); search sources carry searches per hour.

Migration 0079 adds acquisition_services with its CHECKs. Ported from
Fabled Librarian: internal/indexer (Torznab, 429 Retry-After, magnet
redirects), internal/prowlarr, internal/exchange, internal/downloader,
and internal/acquire's one builder per kind, which Test already uses
so a passing Test vouches for the path a grab will take.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-09 20:34:51 -04:00

59 lines
1.7 KiB
Go

package indexer
import (
"bytes"
"errors"
"net/http"
)
// MagnetLink is a download link that turned out to be a magnet. Returned as
// an error by a .torrent fetch so the grab hands the magnet to the download
// client instead. Public trackers do this routinely: Prowlarr's download link
// answers with a redirect to `magnet:?xt=…`, which Go's client would otherwise
// fail on as an unsupported scheme.
type MagnetLink struct{ URI string }
func (m *MagnetLink) Error() string { return "the download link is a magnet link" }
// AsMagnet says whether err is a magnet link, and which.
func AsMagnet(err error) (string, bool) {
var m *MagnetLink
if errors.As(err, &m) && m.URI != "" {
return m.URI, true
}
return "", false
}
// StopAtMagnet returns a copy of c that stops at a redirect to a magnet URI
// and reports it as a *MagnetLink. Every other redirect behaves as c would.
func StopAtMagnet(c *http.Client) *http.Client {
if c == nil {
c = http.DefaultClient
}
out := *c
next := c.CheckRedirect
out.CheckRedirect = func(req *http.Request, via []*http.Request) error {
if req.URL != nil && req.URL.Scheme == "magnet" {
return &MagnetLink{URI: req.URL.String()}
}
if next != nil {
return next(req, via)
}
if len(via) >= 10 {
return errors.New("stopped after 10 redirects")
}
return nil
}
return &out
}
// MagnetBody is a response whose whole body is a magnet URI, which some
// indexers send with a 200 instead of a redirect. Nil otherwise.
func MagnetBody(body []byte) error {
trimmed := bytes.TrimSpace(body)
if bytes.HasPrefix(trimmed, []byte("magnet:")) && !bytes.ContainsAny(trimmed, " \n<") {
return &MagnetLink{URI: string(trimmed)}
}
return nil
}