apps

package
v0.2.7 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2022 License: MIT Imports: 24 Imported by: 0

Documentation

Overview

Package apps provides the _incoming_ HTTP methods for notifiarr.com integrations. Methods are included for Radarr, Readrr, Lidarr and Sonarr. This library also holds the site API Key and the base HTTP server abstraction used throughout the Notifiarr client application. The configuration should be derived from a config file; a Router and an Error Log logger must also be provided.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoTMDB    = fmt.Errorf("TMDB ID must not be empty")
	ErrNoGRID    = fmt.Errorf("GRID ID must not be empty")
	ErrNoTVDB    = fmt.Errorf("TVDB ID must not be empty")
	ErrNoMBID    = fmt.Errorf("MBID ID must not be empty")
	ErrNoRadarr  = fmt.Errorf("configured %s ID not found", starr.Radarr)
	ErrNoSonarr  = fmt.Errorf("configured %s ID not found", starr.Sonarr)
	ErrNoLidarr  = fmt.Errorf("configured %s ID not found", starr.Lidarr)
	ErrNoReadarr = fmt.Errorf("configured %s ID not found", starr.Readarr)
	ErrNotFound  = fmt.Errorf("the request returned an empty payload")
	ErrNonZeroID = fmt.Errorf("provided ID must be non-zero")
	// ErrWrongCount is returned when an app returns the wrong item count.
	ErrWrongCount = fmt.Errorf("wrong item count returned")
	ErrInvalidApp = fmt.Errorf("invalid application configuration provided")
)

Errors sent to client web requests.

View Source
var ErrUnknownByteType = fmt.Errorf("unknown byte type")

Functions

func GetURLInto added in v0.2.0

func GetURLInto(timeout time.Duration, url string, params url.Values, into interface{}) error

GetURLInto gets a url and unmarshals the contents into the provided interface pointer.

Types

type APIHandler

type APIHandler func(r *http.Request) (int, interface{})

APIHandler is our custom handler function for APIs. The powers the middleware procedure that stores the app interface in a request context. And the procedures to save and fetch an app interface into/from a request content.

type Apps

type Apps struct {
	APIKey   string            `json:"apiKey" toml:"api_key" xml:"api_key" yaml:"apiKey"`
	ExKeys   []string          `json:"extraKeys" toml:"extra_keys" xml:"extra_keys" yaml:"extraKeys"`
	URLBase  string            `json:"urlbase" toml:"urlbase" xml:"urlbase" yaml:"urlbase"`
	Sonarr   []*SonarrConfig   `json:"sonarr,omitempty" toml:"sonarr" xml:"sonarr" yaml:"sonarr,omitempty"`
	Radarr   []*RadarrConfig   `json:"radarr,omitempty" toml:"radarr" xml:"radarr" yaml:"radarr,omitempty"`
	Lidarr   []*LidarrConfig   `json:"lidarr,omitempty" toml:"lidarr" xml:"lidarr" yaml:"lidarr,omitempty"`
	Readarr  []*ReadarrConfig  `json:"readarr,omitempty" toml:"readarr" xml:"readarr" yaml:"readarr,omitempty"`
	Prowlarr []*ProwlarrConfig `json:"prowlarr,omitempty" toml:"prowlarr" xml:"prowlarr" yaml:"prowlarr,omitempty"`
	Deluge   []*DelugeConfig   `json:"deluge,omitempty" toml:"deluge" xml:"deluge" yaml:"deluge,omitempty"`
	Qbit     []*QbitConfig     `json:"qbit,omitempty" toml:"qbit" xml:"qbit" yaml:"qbit,omitempty"`
	SabNZB   []*SabNZBConfig   `json:"sabnzbd,omitempty" toml:"sabnzbd" xml:"sabnzbd" yaml:"sabnzbd,omitempty"`
	Tautulli *TautulliConfig   `json:"tautulli,omitempty" toml:"tautulli" xml:"tautulli" yaml:"tautulli,omitempty"`
	Router   *mux.Router       `json:"-" toml:"-" xml:"-" yaml:"-"`
	ErrorLog *log.Logger       `json:"-" toml:"-" xml:"-" yaml:"-"`
	DebugLog *log.Logger       `json:"-" toml:"-" xml:"-" yaml:"-"`
	// contains filtered or unexported fields
}

Apps is the input configuration to relay requests to Starr apps.

func (*Apps) CheckAPIKey

func (a *Apps) CheckAPIKey(next http.Handler) http.Handler

CheckAPIKey drops a 403 if the API key doesn't match, otherwise run next handler.

func (*Apps) HandleAPIpath

func (a *Apps) HandleAPIpath(app starr.App, uri string, api APIHandler, method ...string) *mux.Route

HandleAPIpath makes adding APIKey authenticated API paths a little cleaner. An empty App may be passed in, but URI, API and at least one method are required. Automatically adds an id route to routes with an app name. In case you have > 1 of that app.

func (*Apps) InitHandlers

func (a *Apps) InitHandlers()

InitHandlers activates all our handlers. This is part of the web server init.

func (*Apps) Respond

func (a *Apps) Respond(w http.ResponseWriter, stat int, msg interface{})

Respond sends a standard response to our caller. JSON encoded blobs.

func (*Apps) Setup

func (a *Apps) Setup(timeout time.Duration) error

Setup creates request interfaces and sets the timeout for each server. This is part of the config/startup init.

type DelugeConfig added in v0.1.13

type DelugeConfig struct {
	Name     string        `toml:"name" xml:"name"`
	Interval cnfg.Duration `toml:"interval" xml:"interval"`
	*deluge.Config
	*deluge.Deluge
}

type History added in v0.2.0

type History struct {
	TotalSize         SabNZBSize     `json:"total_size"`
	MonthSize         SabNZBSize     `json:"month_size"`
	WeekSize          SabNZBSize     `json:"week_size"`
	DaySize           SabNZBSize     `json:"day_size"`
	Slots             []HistorySlots `json:"slots"`
	Noofslots         int            `json:"noofslots"`
	LastHistoryUpdate int64          `json:"last_history_update"`
	Version           string         `json:"version"`
}

type HistorySlots added in v0.2.0

type HistorySlots struct {
	ID           int64       `json:"id"`
	Completed    int64       `json:"completed"`
	Name         string      `json:"name"`
	NzbName      string      `json:"nzb_name"`
	Category     string      `json:"category"`
	Pp           string      `json:"pp"`
	Script       string      `json:"script"`
	Report       string      `json:"report"`
	URL          string      `json:"url"`
	Status       string      `json:"status"`
	NzoID        string      `json:"nzo_id"`
	Storage      string      `json:"storage"`
	Path         string      `json:"path"`
	ScriptLog    string      `json:"script_log"`
	ScriptLine   string      `json:"script_line"`
	DownloadTime int64       `json:"download_time"`
	PostprocTime int64       `json:"postproc_time"`
	StageLog     []*StageLog `json:"stage_log"`
	Downloaded   int64       `json:"downloaded"`
	Completeness interface{} `json:"completeness"`
	FailMessage  string      `json:"fail_message"`
	URLInfo      string      `json:"url_info"`
	Bytes        int64       `json:"bytes"`
	Meta         interface{} `json:"meta"`
	Series       string      `json:"series"`
	Md5Sum       string      `json:"md5sum"`
	Password     string      `json:"password"`
	ActionLine   string      `json:"action_line"`
	Size         string      `json:"size"`
	Loaded       bool        `json:"loaded"`
	Retry        int         `json:"retry"`
}

HistorySlots is part of the json response from SABnzbd.

type LidarrConfig

type LidarrConfig struct {
	*starr.Config
	*lidarr.Lidarr
	Errorf func(string, ...interface{}) `toml:"-" xml:"-"`
	// contains filtered or unexported fields
}

LidarrConfig represents the input data for a Lidarr server.

type ProwlarrConfig added in v0.2.5

type ProwlarrConfig struct {
	Name     string        `toml:"name" xml:"name"`         // if set, turn on service checks.
	Interval cnfg.Duration `toml:"interval" xml:"interval"` // service check interval.
	Corrupt  string        `toml:"corrupt" xml:"corrupt"`
	Backup   string        `toml:"backup" xml:"backup"`
	*starr.Config
	*prowlarr.Prowlarr
	Errorf func(string, ...interface{}) `toml:"-" xml:"-"`
}

ProwlarrConfig represents the input data for a Prowlarr server.

type QbitConfig added in v0.1.13

type QbitConfig struct {
	Name     string        `toml:"name" xml:"name"`
	Interval cnfg.Duration `toml:"interval" xml:"interval"`
	*qbit.Config
	*qbit.Qbit
}

type Queue added in v0.2.0

type Queue struct {
	Version           string       `json:"version"`
	PauseInt          string       `json:"pause_int"`
	Diskspace1        float64      `json:"diskspace1,string"`
	Diskspace2        float64      `json:"diskspace2,string"`
	Diskspace1Norm    SabNZBSize   `json:"diskspace1_norm"`
	Diskspace2Norm    SabNZBSize   `json:"diskspace2_norm"`
	Diskspacetotal1   float64      `json:"diskspacetotal1,string"`
	Diskspacetotal2   float64      `json:"diskspacetotal2,string"`
	Loadavg           string       `json:"loadavg"`
	Speedlimit        int          `json:"speedlimit,string"`
	SpeedlimitAbs     string       `json:"speedlimit_abs"`
	HaveWarnings      string       `json:"have_warnings"`
	Finishaction      interface{}  `json:"finishaction"`
	Quota             string       `json:"quota"`
	LeftQuota         string       `json:"left_quota"`
	CacheArt          string       `json:"cache_art"`
	CacheSize         SabNZBSize   `json:"cache_size"`
	CacheMax          int64        `json:"cache_max,string"`
	Kbpersec          float64      `json:"kbpersec,string"`
	Speed             SabNZBSize   `json:"speed"`
	Mbleft            float64      `json:"mbleft,string"`
	Mb                float64      `json:"mb,string"`
	Sizeleft          SabNZBSize   `json:"sizeleft"`
	Size              SabNZBSize   `json:"size"`
	NoofslotsTotal    int          `json:"noofslots_total"`
	Status            string       `json:"status"`
	Timeleft          string       `json:"timeleft"`
	Eta               string       `json:"eta"`
	RefreshRate       string       `json:"refresh_rate"`
	InterfaceSettings string       `json:"interface_settings"`
	Scripts           []string     `json:"scripts"`
	Categories        []string     `json:"categories"`
	Noofslots         int          `json:"noofslots"`
	Start             int64        `json:"start"`
	Limit             int64        `json:"limit"`
	Finish            int64        `json:"finish"`
	Slots             []QueueSlots `json:"slots"`
	PausedAll         bool         `json:"paused_all"`
	RatingEnable      bool         `json:"rating_enable"`
	Paused            bool         `json:"paused"`
	HaveQuota         bool         `json:"have_quota"`
}

type QueueSlots added in v0.2.0

type QueueSlots struct {
	Status     string     `json:"status"`
	Index      int        `json:"index"`
	Password   string     `json:"password"`
	AvgAge     string     `json:"avg_age"`
	Script     string     `json:"script"`
	HasRating  bool       `json:"has_rating"`
	Mb         string     `json:"mb"`
	Mbleft     float64    `json:"mbleft,string"`
	Mbmissing  float64    `json:"mbmissing,string"`
	Size       SabNZBSize `json:"size"`
	Sizeleft   SabNZBSize `json:"sizeleft"`
	Filename   string     `json:"filename"`
	Labels     []string   `json:"labels"`
	Priority   string     `json:"priority"`
	Cat        string     `json:"cat"`
	Eta        SabNZBDate `json:"eta"`
	Timeleft   string     `json:"timeleft"`
	Percentage int        `json:"percentage,string"`
	NzoID      string     `json:"nzo_id"`
	Unpackopts string     `json:"unpackopts"`
}

QueueSlots has the following data structure.

{
  "index": 1,
  "nzo_id": "SABnzbd_nzo_xnfbbdbh",
  "unpackopts": "3",
  "priority": "Normal",
  "script": "wtfnzb-renamer.py",
  "filename": "Rick Astley - Never Gonna Give You Up (1987)(24bit flac vinyl)",
  "labels": [],
  "password": "",
  "cat": "prowlarr",
  "mbleft": "593.67",
  "mb": "701.34",
  "size": "701.3 MB",
  "sizeleft": "593.7 MB",
  "percentage": "15",
  "mbmissing": "0.00",
  "direct_unpack": 0,
  "status": "Downloading",
  "timeleft": "0:03:57",
  "eta": "13:42 Sun 17 Oct",
  "avg_age": "2537d",
  "has_rating": false
}

Payload for this structure.

type RadarrConfig

type RadarrConfig struct {
	Name      string        `toml:"name" xml:"name"`
	Interval  cnfg.Duration `toml:"interval" xml:"interval"`
	StuckItem bool          `toml:"stuck_items" xml:"stuck_items"`
	Corrupt   string        `toml:"corrupt" xml:"corrupt"`
	Backup    string        `toml:"backup" xml:"backup"`
	*starr.Config
	*radarr.Radarr
	Errorf func(string, ...interface{}) `toml:"-" xml:"-"`
}

RadarrConfig represents the input data for a Radarr server.

type ReadarrConfig

type ReadarrConfig struct {
	Name      string        `toml:"name" xml:"name"`
	Interval  cnfg.Duration `toml:"interval" xml:"interval"`
	StuckItem bool          `toml:"stuck_items" xml:"stuck_items"`
	Corrupt   string        `toml:"corrupt" xml:"corrupt"`
	Backup    string        `toml:"backup" xml:"backup"`
	*starr.Config
	*readarr.Readarr
	Errorf func(string, ...interface{}) `toml:"-" xml:"-"`
}

ReadarrConfig represents the input data for a Readarr server.

type SabNZBConfig added in v0.2.0

type SabNZBConfig struct {
	Name     string        `toml:"name" xml:"name"`
	Interval cnfg.Duration `toml:"interval" xml:"interval"`
	Timeout  cnfg.Duration `toml:"timeout" xml:"timeout"`
	URL      string        `toml:"url" xml:"url"`
	APIKey   string        `toml:"api_key" xml:"api_key"`
}

func (*SabNZBConfig) GetHistory added in v0.2.0

func (s *SabNZBConfig) GetHistory() (*History, error)

GetHistory returns the history items in SABnzbd.

func (*SabNZBConfig) GetQueue added in v0.2.0

func (s *SabNZBConfig) GetQueue() (*Queue, error)

GetHistory returns the active queued items in SABnzbd.

type SabNZBDate added in v0.2.0

type SabNZBDate struct {
	String string
	time.Time
}

SabNZBDate is used to parse a custm date format from the json api.

func (*SabNZBDate) UnmarshalJSON added in v0.2.0

func (s *SabNZBDate) UnmarshalJSON(b []byte) (err error)

UnmarshalJSON exists because weird date formats and "unknown" seem sane in json output.

type SabNZBSize added in v0.2.0

type SabNZBSize struct {
	Bytes  int64
	String string
}

SabNZBSize deals with bytes encoded as strings.

func (*SabNZBSize) UnmarshalJSON added in v0.2.0

func (s *SabNZBSize) UnmarshalJSON(b []byte) (err error)

UnmarshalJSON exists because someone decided that bytes should be strings with letters.

type SonarrConfig

type SonarrConfig struct {
	Name      string        `toml:"name" xml:"name"`
	Interval  cnfg.Duration `toml:"interval" xml:"interval"`
	StuckItem bool          `toml:"stuck_items" xml:"stuck_items"`
	Corrupt   string        `toml:"corrupt" xml:"corrupt"`
	Backup    string        `toml:"backup" xml:"backup"`
	*starr.Config
	*sonarr.Sonarr
	Errorf func(string, ...interface{}) `toml:"-" xml:"-"`
}

SonarrConfig represents the input data for a Sonarr server.

type StageLog added in v0.2.0

type StageLog struct {
	Name    string   `json:"name"`
	Actions []string `json:"actions"`
}

StageLog is part of the json response from SABnzbd.

type TautulliConfig added in v0.2.0

type TautulliConfig struct {
	Name     string        `toml:"name" xml:"name"`
	Interval cnfg.Duration `toml:"interval" xml:"interval"`
	Timeout  cnfg.Duration `toml:"timeout" xml:"timeout"`
	URL      string        `toml:"url" xml:"url"`
	APIKey   string        `toml:"api_key" xml:"api_key"`
}

func (*TautulliConfig) GetUsers added in v0.2.0

func (t *TautulliConfig) GetUsers() (*TautulliUsers, error)

GetUsers returns the Tautulli users.

type TautulliUser added in v0.2.0

type TautulliUser struct {
	RowID           int64  `json:"row_id"`
	UserID          int64  `json:"user_id"`
	Username        string `json:"username"`
	FriendlyName    string `json:"friendly_name"`
	Thumb           string `json:"thumb"`
	Email           string `json:"email"`
	ServerToken     string `json:"server_token"`
	SharedLibraries string `json:"shared_libraries"`
	FilterAll       string `json:"filter_all"`
	FilterMovies    string `json:"filter_movies"`
	FilterTv        string `json:"filter_tv"`
	FilterMusic     string `json:"filter_music"`
	FilterPhotos    string `json:"filter_photos"`
	IsActive        int    `json:"is_active"`     // 1,0 (bool)
	IsAdmin         int    `json:"is_admin"`      // 1,0 (bool)
	IsHomeUser      int    `json:"is_home_user"`  // 1,0 (bool)
	IsAllowSync     int    `json:"is_allow_sync"` // 1,0 (bool)
	IsRestricted    int    `json:"is_restricted"` // 1,0 (bool)
	DoNotify        int    `json:"do_notify"`     // 1,0 (bool)
	KeepHistory     int    `json:"keep_history"`  // 1,0 (bool)
	AllowGuest      int    `json:"allow_guest"`   // 1,0 (bool)
}

TautulliUser is the user data from the get_users API call.

type TautulliUsers added in v0.2.0

type TautulliUsers struct {
	Response struct {
		Result  string         `json:"result"`  // success, error
		Message string         `json:"message"` // error msg
		Data    []TautulliUser `json:"data"`
	} `json:"response"`
}

TautulliUsers is the entire get_users API response.

func (*TautulliUsers) MapEmailName added in v0.2.0

func (t *TautulliUsers) MapEmailName() map[string]string

MapEmailName returns a map of email => name for Tautulli users.

Jump to

Keyboard shortcuts

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