Documentation ¶
Overview ¶
Package starr is a library for interacting with the APIs in Radarr, Lidarr, Sonarr and Readarr. It consists of the main starr package and one sub package for each starr application. In the basic use, you create a starr Config that contains an API key and an App URL. Pass this into one of the other packages (like radarr), and it's used as an interface to make API calls.
You can either call starr.New() to build an http.Client for you, or create a starr.Config that contains one you control. If you pass a starr.Config into a sub package without an http Client, it will be created for you. There are a lot of option to set this code up from simple and easy to more advanced.
The sub package contain methods and data structures for a number of API endpoints. Each app has somewhere between 50 and 100 API endpoints. This library currently covers about 10% of those. You can retrieve things like movies, albums, series and books. You can retrieve server status, authors, artists and items in queues. You can also add new media to each application with this library.
Index ¶
- Constants
- Variables
- func AdjustPerPage(records, total, collected, perPage int) int
- func Client(timeout time.Duration, verifySSL bool) *http.Client
- func ClientWithDebug(timeout time.Duration, verifySSL bool, logConfig debuglog.Config) *http.Client
- func False() *bool
- func Int64(s int64) *int64
- func SetAPIPath(uriPath string) string
- func SetPerPage(records, perPage int) int
- func String(s string) *string
- func True() *bool
- type APIer
- type App
- type ApplyTags
- type BackupFile
- type BaseQuality
- type Config
- func (c *Config) Delete(ctx context.Context, req Request) (*http.Response, error)
- func (c *Config) DeleteAny(ctx context.Context, req Request) error
- func (c *Config) Get(ctx context.Context, req Request) (*http.Response, error)
- func (c *Config) GetInitializeJS(ctx context.Context) (*InitializeJS, error)
- func (c *Config) GetInto(ctx context.Context, req Request, output interface{}) error
- func (c *Config) Login(ctx context.Context) error
- func (c *Config) Post(ctx context.Context, req Request) (*http.Response, error)
- func (c *Config) PostInto(ctx context.Context, req Request, output interface{}) error
- func (c *Config) Put(ctx context.Context, req Request) (*http.Response, error)
- func (c *Config) PutInto(ctx context.Context, req Request, output interface{}) error
- func (c *Config) Req(ctx context.Context, method string, req Request) (*http.Response, error)
- func (c *Config) SetHeaders(req *http.Request)
- type FieldInput
- type FieldOutput
- type Filtering
- type FormatItem
- type Image
- type InitializeJS
- type IsLoaded
- type KeyValue
- type Link
- type OpenRatings
- type PageReq
- type Path
- type PlayTime
- type Quality
- type QualityRevision
- type QueueDeleteOpts
- type Ratings
- type RemotePathMapping
- type ReqError
- type Request
- type SelectOption
- type Sorting
- type StatusMessage
- type Tag
- type Value
Constants ¶
const API = "api"
API is the beginning of every API path.
const CalendarTimeFilterFormat = "2006-01-02T03:04:05.000Z"
CalendarTimeFilterFormat is the Go time format the calendar expects the filter to be in.
const (
DefaultTimeout = 30 * time.Second
)
Defaults for New().
Variables ¶
var ( // ErrInvalidStatusCode matches ANY ReqError when using errors.Is. // You should instead use errors.As if you need the response data. // Find an example of errors.As in the Login() method. ErrInvalidStatusCode = &ReqError{Code: -1} // ErrNilClient is returned if you attempt a request with a nil http.Client. ErrNilClient = fmt.Errorf("http.Client must not be nil") // ErrNilInterface is returned by *Into() methods when a nil interface is provided. ErrNilInterface = fmt.Errorf("cannot unmarshal data into a nil or empty interface") // ErrInvalidAPIKey is returned if we know the API key didn't work. ErrInvalidAPIKey = fmt.Errorf("API Key may be incorrect") // ErrRequestError is returned when bad input is provided. ErrRequestError = fmt.Errorf("request error") )
Errors you may receive from this package.
Functions ¶
func AdjustPerPage ¶
AdjustPerPage to make sure we don't go over, or ask for more records than exist. This is used by paginated methods in the starr modules. 'records' is the number requested, 'total' is the number in the app, 'collected' is how many we have so far, and 'perPage' is the current perPage setting.
func ClientWithDebug ¶
ClientWithDebug returns an http client with a debug logger enabled.
func SetAPIPath ¶
SetAPIPath makes sure the path starts with /api.
func SetPerPage ¶
SetPerPage returns a proper perPage value that is not equal to zero, and not larger than the record count desired. If the count is zero, then perPage can be anything other than zero. This is used by paginated methods in the starr modules.
Types ¶
type APIer ¶
type APIer interface { GetInitializeJS(ctx context.Context) (*InitializeJS, error) // Login is used for non-API paths, like downloading backups or the initialize.js file. Login(ctx context.Context) error // Normal data, returns response. Do not use these in starr app methods. // These methods are generally for non-api paths and will not ensure an /api uri prefix. Get(ctx context.Context, req Request) (*http.Response, error) // Get request; Params are optional. Post(ctx context.Context, req Request) (*http.Response, error) // Post request; Params should contain io.Reader. Put(ctx context.Context, req Request) (*http.Response, error) // Put request; Params should contain io.Reader. Delete(ctx context.Context, req Request) (*http.Response, error) // Delete request; Params are optional. // Normal data, unmarshals into provided interface. Use these because they close the response body. GetInto(ctx context.Context, req Request, output interface{}) error // API GET Request. PostInto(ctx context.Context, req Request, output interface{}) error // API POST Request. PutInto(ctx context.Context, req Request, output interface{}) error // API PUT Request. DeleteAny(ctx context.Context, req Request) error // API Delete request. }
APIer is used by the sub packages to allow mocking the http methods in tests. It changes once in a while, so avoid making hard dependencies on it.
type App ¶
type App string
App can be used to satisfy a context value key. It is not used in this library; provided for convenience.
type ApplyTags ¶
type ApplyTags string
ApplyTags is an enum used as an input for Bulk editors, and perhaps other places.
const ( TagsAdd ApplyTags = "add" TagsRemove ApplyTags = "remove" TagsReplace ApplyTags = "replace" )
ApplyTags enum constants. Use these as inputs for "ApplyTags" member values. Schema doc'd here: https://radarr.video/docs/api/#/MovieEditor/put_api_v3_movie_editor
type BackupFile ¶
type BackupFile struct { Name string `json:"name"` Path string `json:"path"` Type string `json:"type"` Time time.Time `json:"time"` ID int64 `json:"id"` Size int64 `json:"size"` }
BackupFile comes from the system/backup paths in all apps.
type BaseQuality ¶
type BaseQuality struct { ID int64 `json:"id"` Name string `json:"name"` Source string `json:"source,omitempty"` Resolution int `json:"resolution,omitempty"` Modifier string `json:"modifier,omitempty"` }
BaseQuality is a base quality profile.
type Config ¶
type Config struct { APIKey string `json:"apiKey" toml:"api_key" xml:"api_key" yaml:"apiKey"` URL string `json:"url" toml:"url" xml:"url" yaml:"url"` HTTPPass string `json:"httpPass" toml:"http_pass" xml:"http_pass" yaml:"httpPass"` HTTPUser string `json:"httpUser" toml:"http_user" xml:"http_user" yaml:"httpUser"` Username string `json:"username" toml:"username" xml:"username" yaml:"username"` Password string `json:"password" toml:"password" xml:"password" yaml:"password"` Client *http.Client `json:"-" toml:"-" xml:"-" yaml:"-"` // contains filtered or unexported fields }
Config is the data needed to poll Radarr or Sonarr or Lidarr or Readarr. At a minimum, provide a URL and API Key. HTTPUser and HTTPPass are used for Basic HTTP auth, if enabled (not common). Username and Password are for non-API paths with native authentication enabled.
func New ¶
New returns a *starr.Config pointer. This pointer is safe to modify further before passing it into one of the starr app New() procedures.
func (*Config) DeleteAny ¶
DeleteAny performs an HTTP DELETE against an API path, output is ignored.
func (*Config) GetInitializeJS ¶
func (c *Config) GetInitializeJS(ctx context.Context) (*InitializeJS, error)
GetInitializeJS returns the data from the initialize.js file. If the instance requires authentication, you must call Login() before this method.
func (*Config) GetInto ¶
GetInto performs an HTTP GET against an API path and unmarshals the payload into the provided pointer interface.
func (*Config) Login ¶
Login POSTs to the login form in a Starr app and saves the authentication cookie for future use.
func (*Config) PostInto ¶
PostInto performs an HTTP POST against an API path and unmarshals the payload into the provided pointer interface.
func (*Config) PutInto ¶
PutInto performs an HTTP PUT against an API path and unmarshals the payload into the provided pointer interface.
func (*Config) Req ¶
Req makes an authenticated request to a starr application and returns the response. Do not forget to read and close the response Body if there is no error.
func (*Config) SetHeaders ¶
SetHeaders sets all our request headers based on method and other data.
type FieldInput ¶
type FieldInput struct { Name string `json:"name"` Value interface{} `json:"value,omitempty"` }
FieldInput is generic Name/Value struct applied to a few places.
type FieldOutput ¶
type FieldOutput struct { Advanced bool `json:"advanced,omitempty"` Order int64 `json:"order,omitempty"` HelpLink string `json:"helpLink,omitempty"` HelpText string `json:"helpText,omitempty"` Hidden string `json:"hidden,omitempty"` Label string `json:"label,omitempty"` Name string `json:"name"` SelectOptionsProviderAction string `json:"selectOptionsProviderAction,omitempty"` Type string `json:"type,omitempty"` Privacy string `json:"privacy"` Value interface{} `json:"value,omitempty"` SelectOptions []*SelectOption `json:"selectOptions,omitempty"` }
FieldOutput is generic Name/Value struct applied to a few places.
type Filtering ¶
type Filtering int
Filtering is used as a request parameter value to filter lists, like History and Queue. The filter values are different per-app, so find their values in their respective modules.
type FormatItem ¶
type FormatItem struct { Format int64 `json:"format"` Name string `json:"name"` Score int64 `json:"score"` }
FormatItem is part of a quality profile.
type Image ¶
type Image struct { CoverType string `json:"coverType"` URL string `json:"url,omitempty"` RemoteURL string `json:"remoteUrl,omitempty"` Extension string `json:"extension,omitempty"` }
Image is used in a few places.
type InitializeJS ¶
type InitializeJS struct { App string APIRoot string APIKey string Release string Version string InstanceName string Theme string Branch string Analytics string UserHash string URLBase string IsProduction bool }
InitializeJS is the data contained in the initialize.js file.
type IsLoaded ¶
type IsLoaded struct {
IsLoaded bool `json:"isLoaded"`
}
IsLoaded is a generic struct used in a few places.
type OpenRatings ¶
OpenRatings is a ratings type that has a source and type.
type PageReq ¶
type PageReq struct { PageSize int // 10 is default if not provided. Page int // 1 is default if not provided. SortKey string // date, timeleft, others? SortDir Sorting // ascending, descending Filter Filtering // enums for eventTypes. App specific. url.Values // Additional values that may be set. }
PageReq is the input to search requests that have page-able responses. These are turned into HTTP parameters.
type PlayTime ¶
PlayTime is used in at least Sonarr, maybe other places. Holds a string duration converted from hh:mm:ss.
func (*PlayTime) MarshalJSON ¶
func (*PlayTime) UnmarshalJSON ¶
UnmarshalJSON parses a run time duration in format hh:mm:ss.
type Quality ¶
type Quality struct { Name string `json:"name,omitempty"` ID int `json:"id,omitempty"` Quality *BaseQuality `json:"quality,omitempty"` Items []*Quality `json:"items,omitempty"` Allowed bool `json:"allowed"` Revision *QualityRevision `json:"revision,omitempty"` // Not sure which app had this.... }
Quality is a download quality profile attached to a movie, book, track or series. It may contain 1 or more profiles. Sonarr nor Readarr use Name or ID in this struct.
type QualityRevision ¶
type QualityRevision struct { Version int64 `json:"version"` Real int64 `json:"real"` IsRepack bool `json:"isRepack,omitempty"` }
QualityRevision is probably used in Sonarr.
type QueueDeleteOpts ¶
type QueueDeleteOpts struct { // Default True, use starr.False() to change it. RemoveFromClient *bool // Default False BlockList bool // Default False SkipRedownload bool }
QueueDeleteOpts are the extra inputs when deleting an item from the Activity Queue. Set these appropriately for your expectations. All inputs are the same in all apps. Providing this input to the QueueDelete methods is optional; nil sets the defaults shown.
func (*QueueDeleteOpts) Values ¶
func (o *QueueDeleteOpts) Values() url.Values
Values turns delete options into http get query parameters.
type Ratings ¶
type Ratings struct { Votes int64 `json:"votes"` Value float64 `json:"value"` Popularity float64 `json:"popularity,omitempty"` Type string `json:"type,omitempty"` }
Ratings belong to a few types.
type RemotePathMapping ¶
type RemotePathMapping struct { ID int64 `json:"id,omitempty"` Host string `json:"host"` RemotePath string `json:"remotePath"` LocalPath string `json:"localPath"` }
RemotePathMapping is the remotePathMapping endpoint.
type ReqError ¶
type ReqError struct { Code int Body []byte Msg string Name string Err error // sub error, often nil, or not useful. http.Header }
ReqError is returned when a Starr app returns an invalid status code.
type Request ¶
type Request struct { URI string // Required: path portion of the URL. Query url.Values // GET parameters work for any request type. Body io.Reader // Used in PUT, POST, DELETE. Not for GET. }
Request contains the GET and/or POST values for an HTTP request.
type SelectOption ¶
type SelectOption struct { DividerAfter bool `json:"dividerAfter,omitempty"` Order int64 `json:"order"` Value int64 `json:"value"` Hint string `json:"hint"` Name string `json:"name"` }
SelectOption is part of Field.
type Sorting ¶
type Sorting string
Sorting is used as a request parameter value to sort lists, like History and Queue.
type StatusMessage ¶
StatusMessage represents the status of the item. All apps use this.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package debuglog provides a RoundTripper you can put into an HTTP client Transport to log requests made with that client.
|
Package debuglog provides a RoundTripper you can put into an HTTP client Transport to log requests made with that client. |
Package starrcmd provides the bindings to consume a custom script command hook from any Starr app.
|
Package starrcmd provides the bindings to consume a custom script command hook from any Starr app. |
Package starrtest provides methods that are shared by all the tests in the other sub packages.
|
Package starrtest provides methods that are shared by all the tests in the other sub packages. |