arrapi

package
v0.1.21 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2026 License: GPL-2.0, GPL-3.0 Imports: 17 Imported by: 0

Documentation

Overview

Package arrapi provides Sonarr and Radarr API clients.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client talks to a Sonarr or Radarr instance.

func NewClient

func NewClient(baseURL, apiKey string, opts ...ClientOption) (*Client, error)

NewClient creates an arr API client. Returns an error if baseURL or apiKey are invalid.

func (*Client) Close

func (c *Client) Close()

Close releases idle connections held by the client's transport. Safe to call multiple times.

func (*Client) GetEpisodeByID

func (c *Client) GetEpisodeByID(ctx context.Context, id int) (*api.Episode, error)

GetEpisodeByID fetches a single episode by internal ID.

func (*Client) GetEpisodes

func (c *Client) GetEpisodes(ctx context.Context, seriesID int) ([]api.Episode, error)

GetEpisodes returns all episodes for a series from Sonarr. Concurrent calls for the same seriesID are coalesced via singleflight.

func (*Client) GetHistorySince

func (c *Client) GetHistorySince(ctx context.Context, since time.Time, eventType api.HistoryEventType) ([]api.HistoryEntry, error)

GetHistorySince returns history events since the given time. Pass eventType to filter (0 = all types).

Wrapped in retryWithBackoff so transient 5xx / 429 responses during the poller cycle survive brief arr restarts. The history endpoint is idempotent so retry is safe.

func (*Client) GetMovieByID

func (c *Client) GetMovieByID(ctx context.Context, id int) (*api.Movie, error)

GetMovieByID fetches a single movie by internal ID.

func (*Client) GetMovies

func (c *Client) GetMovies(ctx context.Context) ([]api.Movie, error)

GetMovies fetches all movies from Radarr. Concurrent calls are coalesced via singleflight to avoid redundant HTTP requests.

func (*Client) GetSeries

func (c *Client) GetSeries(ctx context.Context) ([]api.Series, error)

GetSeries fetches all series from Sonarr. Concurrent calls are coalesced via singleflight to avoid redundant HTTP requests.

func (*Client) GetSeriesByID

func (c *Client) GetSeriesByID(ctx context.Context, id int) (*api.Series, error)

GetSeriesByID fetches a single series by internal ID.

func (*Client) GetWantedEpisodes

func (c *Client) GetWantedEpisodes(ctx context.Context, excludeTagIDs map[int]struct{}, fn func(api.Series, api.Episode) error) error

GetWantedEpisodes returns episodes that need subtitle searches. Fetches the full series list first (closes the connection), then fetches episodes per series concurrently (bounded to 6 goroutines). The callback fn is invoked sequentially after all episodes are collected. Series or episodes with any excludeTagID are skipped.

func (*Client) GetWantedMovies

func (c *Client) GetWantedMovies(ctx context.Context, excludeTagIDs map[int]struct{}, fn func(api.Movie) error) error

GetWantedMovies returns movies that need subtitle searches. Fetches the full movie list first (closes the connection), then iterates locally. Movies with any excludeTagID are skipped.

func (*Client) Ping

func (c *Client) Ping(ctx context.Context) error

Ping tests connectivity to the arr instance by hitting the system/status endpoint. Returns nil on success, an error describing the failure otherwise. Uses a short timeout (5s) to fail fast during config validation.

func (*Client) RefreshMovie

func (c *Client) RefreshMovie(ctx context.Context, movieID int) error

RefreshMovie tells Radarr to rescan a movie for new files.

func (*Client) RefreshSeries

func (c *Client) RefreshSeries(ctx context.Context, seriesID int) error

RefreshSeries tells Sonarr to rescan a series for new files (including subtitles).

func (*Client) ResolveExcludeTagIDs

func (c *Client) ResolveExcludeTagIDs(ctx context.Context, names []string, logMissing bool) map[int]struct{}

ResolveExcludeTagIDs fetches tags from the arr API and returns the IDs matching the given tag names. When logMissing is true, unknown names are logged once at INFO level; coverage API calls pass false to avoid repeating the message on every page load.

type ClientOption

type ClientOption func(*Client)

ClientOption configures optional Client parameters.

type CommandName

type CommandName string

CommandName is a typed string for arr API command names.

const (
	// CommandRescanSeries tells Sonarr to rescan a series for new files.
	CommandRescanSeries CommandName = "RescanSeries"
	// CommandRescanMovie tells Radarr to rescan a movie for new files.
	CommandRescanMovie CommandName = "RescanMovie"
)

func (CommandName) Valid

func (c CommandName) Valid() bool

Valid reports whether c is a known command name.

type StatusError

type StatusError struct {
	Body string
	Path string
	Code int
	// contains filtered or unexported fields
}

StatusError represents a non-OK HTTP response from an arr API. Callers can use errors.As to inspect the status code and distinguish transient (5xx) from permanent (4xx) failures.

func (*StatusError) Error

func (e *StatusError) Error() string

func (*StatusError) IsTransient

func (e *StatusError) IsTransient() bool

IsTransient returns true for HTTP status codes that indicate a retryable failure (5xx server errors and 429 Too Many Requests).

Jump to

Keyboard shortcuts

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