indexer

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 21, 2026 License: MIT Imports: 20 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	HealthUnknown           = "unknown"
	HealthOK                = "ok"
	HealthDefinitionMissing = "definition_missing"
	HealthFailing           = "failing"
)

Indexer health states.

  • unknown/ok/definition_missing are maintained by AuditCatalog (definition-resolution dimension, boot + daily refresh).
  • failing is maintained by RecordSearchOutcome (live search dimension): N consecutive search failures flip an indexer to failing; one success flips it back to ok. Unlike definition_missing, failing indexers are still synced to services — they may recover on their own.

Variables

This section is empty.

Functions

func CatalogLanguages

func CatalogLanguages() []string

CatalogLanguages returns the distinct languages present in the catalog.

func IsLikelyIPBan added in v0.4.0

func IsLikelyIPBan(lastError string) bool

IsLikelyIPBan reports whether a search error message looks like a Cloudflare IP ban (vs an ordinary failure). Used by the API to offer the "Rotate VPN IP" action in context.

func SetCatalogSource

func SetCatalogSource(fn func() []CatalogEntry)

SetCatalogSource replaces the catalog provider function. Call this once at startup after creating a ProwlarrCatalog.

Types

type AssignmentInput

type AssignmentInput struct {
	IndexerID string `json:"indexer_id"`
	ServiceID string `json:"service_id"`
	Overrides string `json:"overrides"`
}

AssignmentInput specifies how to assign an indexer to a service.

type AutoAssigner

type AutoAssigner struct {
	// contains filtered or unexported fields
}

AutoAssigner handles automatic indexer-to-service assignment based on category↔capability matching.

func NewAutoAssigner

func NewAutoAssigner(q db.Querier, pusher *Pusher, logger *slog.Logger) *AutoAssigner

NewAutoAssigner creates a new AutoAssigner.

func (*AutoAssigner) AssignExistingIndexersToService

func (a *AutoAssigner) AssignExistingIndexersToService(ctx context.Context, serviceID string)

AssignExistingIndexersToService finds all unassigned indexers whose categories match the service's content:* capabilities and creates assignments. Called when a new service registers.

func (*AutoAssigner) AssignIndexerToMatchingServices

func (a *AutoAssigner) AssignIndexerToMatchingServices(ctx context.Context, indexerID string, categories []string)

AssignIndexerToMatchingServices finds all services whose content:* capabilities match the indexer's categories and creates assignments. Called when an indexer is created.

type CatalogEntry

type CatalogEntry struct {
	ID          string   `json:"id"`
	Name        string   `json:"name"`
	Description string   `json:"description"`
	Language    string   `json:"language"`
	Protocol    string   `json:"protocol"`   // torrent, usenet
	Privacy     string   `json:"privacy"`    // public, semi-private, private
	Categories  []string `json:"categories"` // Movies, TV, Audio, Books, XXX, Other
	URLs        []string `json:"urls"`
	Settings    []Field  `json:"settings"` // config fields required to add this indexer
}

CatalogEntry describes an available indexer that users can browse and add. This is the "template" — not yet configured or saved.

func Catalog

func Catalog() []CatalogEntry

Catalog returns the current catalog entries (from Prowlarr or static fallback).

func FilterCatalog

func FilterCatalog(filter CatalogFilter) []CatalogEntry

FilterCatalog returns catalog entries matching the given filter.

type CatalogFilter

type CatalogFilter struct {
	Query    string `json:"query,omitempty"`
	Protocol string `json:"protocol,omitempty"`
	Privacy  string `json:"privacy,omitempty"`
	Category string `json:"category,omitempty"`
	Language string `json:"language,omitempty"`
}

CatalogFilter holds the query parameters for browsing the catalog.

type Field

type Field struct {
	Name        string        `json:"name"`
	Type        string        `json:"type"` // text, password, checkbox, select, info
	Label       string        `json:"label"`
	HelpText    string        `json:"help_text,omitempty"`
	Required    bool          `json:"required"`
	Default     string        `json:"default,omitempty"`
	Placeholder string        `json:"placeholder,omitempty"`
	Options     []FieldOption `json:"options,omitempty"` // for select type
}

Field describes a single user-configurable setting for an indexer.

type FieldOption

type FieldOption struct {
	Name  string `json:"name"`
	Value string `json:"value"`
}

FieldOption is a name/value pair for select fields.

type IndexerInfo

type IndexerInfo struct {
	db.Indexer
	AssignedServices []string `json:"assigned_services,omitempty"`
}

IndexerInfo is the enriched view with assignments.

type Input

type Input struct {
	Name     string `json:"name"`
	Kind     string `json:"kind"`
	Enabled  bool   `json:"enabled"`
	Priority int    `json:"priority"`
	URL      string `json:"url"`
	APIKey   string `json:"api_key"`
	Settings string `json:"settings"`
}

Input is the data required to create or update an indexer.

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager handles centralized indexer management.

func NewManager

func NewManager(q db.Querier, bus *events.Bus, logger *slog.Logger) *Manager

NewManager creates a new indexer manager.

func (*Manager) Assign

func (m *Manager) Assign(ctx context.Context, input AssignmentInput) (*db.IndexerAssignment, error)

Assign links an indexer to a service.

func (*Manager) AuditCatalog added in v0.4.0

func (m *Manager) AuditCatalog(ctx context.Context, resolve func(name, url string) string)

AuditCatalog cross-checks every configured indexer against the loaded Prowlarr definition catalog and records the result in the indexer's health columns. It runs after each definition load (boot and the daily refresh), using the same resolver the torznab proxy uses at search time so the audit can never disagree with what a search would hit.

Without this, an indexer whose upstream definition was removed (the 2026-08-16 TorrentGalaxyClone incident — TorrentGalaxy shut down and Prowlarr deleted the definition) stays configured and assigned forever, and the first place it fails is every user search.

A transition into or out of definition_missing changes what ListIndexersForService returns, so assigned services are push-notified to re-sync on those transitions only.

func (*Manager) AutoAssigner

func (m *Manager) AutoAssigner() *AutoAssigner

AutoAssigner returns the auto-assigner for use by other packages (e.g., service registry for retroactive assignment on registration).

func (*Manager) Create

func (m *Manager) Create(ctx context.Context, input Input) (*db.Indexer, error)

Create adds a new indexer.

func (*Manager) Delete

func (m *Manager) Delete(ctx context.Context, id string) error

Delete removes an indexer and its assignments, and notifies all affected services so they can remove the indexer locally.

func (*Manager) Get

func (m *Manager) Get(ctx context.Context, id string) (*db.Indexer, error)

Get returns a single indexer.

func (*Manager) List

func (m *Manager) List(ctx context.Context) ([]db.Indexer, error)

List returns all indexers.

func (*Manager) ListAssignments

func (m *Manager) ListAssignments(ctx context.Context, indexerID string) ([]db.IndexerAssignment, error)

ListAssignments returns all assignments for an indexer.

func (*Manager) ListEnabled

func (m *Manager) ListEnabled(ctx context.Context) ([]db.Indexer, error)

ListEnabled returns only enabled indexers.

func (*Manager) ListForService

func (m *Manager) ListForService(ctx context.Context, serviceID string) ([]db.Indexer, error)

ListForService returns indexers assigned to a specific service.

func (*Manager) RecordSearchOutcome added in v0.4.0

func (m *Manager) RecordSearchOutcome(ctx context.Context, indexerID string, searchErr error)

RecordSearchOutcome updates an indexer's search-health counters after a proxied search. searchErr == nil records a success (resets the failure streak and, if the indexer was failing, restores it to ok).

func (*Manager) Unassign

func (m *Manager) Unassign(ctx context.Context, indexerID, serviceID string) error

Unassign removes an indexer-service link.

func (*Manager) Update

func (m *Manager) Update(ctx context.Context, id string, input Input) (*db.Indexer, error)

Update modifies an existing indexer.

type ProwlarrCatalog

type ProwlarrCatalog struct {
	// contains filtered or unexported fields
}

ProwlarrCatalog manages a catalog sourced from Prowlarr's GitHub repo.

func NewProwlarrCatalog

func NewProwlarrCatalog(logger *slog.Logger) *ProwlarrCatalog

NewProwlarrCatalog creates a catalog that pulls from Prowlarr's definitions. It initializes with the static fallback and fetches live data asynchronously.

func (*ProwlarrCatalog) AllRawYAML

func (pc *ProwlarrCatalog) AllRawYAML() map[string][]byte

AllRawYAML returns all raw YAML bytes, keyed by catalog ID.

func (*ProwlarrCatalog) Entries

func (pc *ProwlarrCatalog) Entries() []CatalogEntry

Entries returns the current catalog entries.

func (*ProwlarrCatalog) LastFetched

func (pc *ProwlarrCatalog) LastFetched() time.Time

LastFetched returns when the catalog was last refreshed from Prowlarr.

func (*ProwlarrCatalog) LoadLocal added in v0.4.0

func (pc *ProwlarrCatalog) LoadLocal() (string, error)

LoadLocal populates the catalog without touching the network, preferring the freshest source: the on-disk cache written after the last successful GitHub fetch, then the snapshot embedded at build time. It returns which source was used ("disk-cache" or "embedded").

func (*ProwlarrCatalog) RawYAML

func (pc *ProwlarrCatalog) RawYAML(catalogID string) ([]byte, bool)

RawYAML returns the raw YAML bytes for a catalog entry, used by the scraper engine.

func (*ProwlarrCatalog) Refresh

func (pc *ProwlarrCatalog) Refresh(ctx context.Context) error

Refresh fetches the latest definitions from Prowlarr's GitHub repo. On failure it keeps the existing catalog (previous fetch, local cache, or static fallback).

func (*ProwlarrCatalog) SetCachePath added in v0.4.0

func (pc *ProwlarrCatalog) SetCachePath(path string)

SetCachePath enables persisting each successfully fetched definitions zipball to path, and makes LoadLocal prefer that file over the embedded snapshot. Call before LoadLocal / StartRefreshLoop.

func (*ProwlarrCatalog) SetUpdateFunc added in v0.4.0

func (pc *ProwlarrCatalog) SetUpdateFunc(fn func(map[string][]byte))

SetUpdateFunc registers fn to be called with a copy of the raw YAML definition map whenever definitions are (re)loaded from any source — local load at startup and every successful GitHub refresh. Call before LoadLocal / StartRefreshLoop.

func (*ProwlarrCatalog) StartRefreshLoop

func (pc *ProwlarrCatalog) StartRefreshLoop(ctx context.Context, interval time.Duration)

StartRefreshLoop refreshes the catalog immediately, then periodically.

type Pusher

type Pusher struct {
	// contains filtered or unexported fields
}

Pusher notifies services when their indexer assignments change. It POSTs to each affected service's sync webhook endpoint.

func NewPusher

func NewPusher(q db.Querier, logger *slog.Logger) *Pusher

NewPusher creates a new Pusher.

func (*Pusher) NotifyAllAssigned

func (p *Pusher) NotifyAllAssigned(ctx context.Context, indexerID string)

NotifyAllAssigned notifies all services that have the given indexer assigned.

func (*Pusher) NotifyService

func (p *Pusher) NotifyService(ctx context.Context, serviceID string)

NotifyService sends a sync trigger to a service's Pulse webhook. The endpoint is: POST {service.api_url}/api/v1/hooks/pulse/sync

func (*Pusher) NotifyServiceAsync

func (p *Pusher) NotifyServiceAsync(serviceID string)

NotifyServiceAsync is a fire-and-forget version of NotifyService.

type TestResult

type TestResult struct {
	Success  bool   `json:"success"`
	Message  string `json:"message"`
	Duration string `json:"duration"`
}

TestResult holds the outcome of probing an indexer.

func TestIndexer

func TestIndexer(ctx context.Context, kind, url, apiKey string) TestResult

TestIndexer probes an indexer URL to validate connectivity and credentials. For Torznab/Newznab it performs a caps query; for generic URLs it checks HTTP status.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL