sabnzbd

package module
v2.3.0 Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2023 License: MIT Imports: 16 Imported by: 0

README

go-sabnzbd

Golang API bindings for SABnzbd

For full API documentation, see: http://wiki.sabnzbd.org/api

See cmd/example/example.go for a usage example

Disclaimer

This is ancient code from an almost decade-old fork.
I'm currently using it for a project and updating routes as I go, and need.

Both the history and queue mode/routes are up to spec of SABnzbd 3.7.1.
For the rest I really got no clue; haven't used them yet.
Some fields may be missing, others may exist but don't exist in SABnzbd anymore and therefore are never set.

Installation

go get github.com/d0x7/go-sabnzbd/v2

Example

func main() {
  // Either create a simple client, using a host *with* port and an API key
  client, err := sabnzbd.SimpleClient("localhost:8080", "key")
  // Or create a secure client, which both always uses HTTPS and port 443
  client, err =  sabnzbd.SecureClient("sabnzbd.domain.tld", "key")
  // If you need a more advanced client, you can create one yourself, see the example in cmd/example/example.go for that

  // Check for errors, then call Auth to check if the API key is valid, and check again for potential errors
  _, err := client.Auth()
  // return value is not important; it's just the method of authentication used (apikey in this case)

  // You can check the remote server's version with Version()
  version, err := client.Version()

  // Get the current queue and whether it's paused, the current download speed, et cetera
  // SimpleQueue takes on parameters, whereas the normal Queue method takes paiging parameters (start, limit)
  queue, err := client.SimpleQueue()

  fmt.Printf("SpeedLimit is set to %v%%, aka. %s/s absolute\n", queue.SpeedLimitPercentage, queue.SpeedLimit)
  fmt.Printf("There is %s of %s free space left\n", queue.DownloadDiskFreeSpace, queue.DownloadDiskTotalSpace)
  fmt.Printf("Of the %d downloads, there are %s of %s downloaded already\n", queue.NoOfSlotsTotal, queue.Bytes, queue.BytesTotal)
  fmt.Printf("The remaining %s will be downloaded ", queue.BytesLeft)

  if queue.Paused {
      fmt.Printf("once the downloads are remained.\n")
  } else {
      fmt.Printf("in ETA %s\n", queue.TimeLeft)
  }

  //	=> SpeedLimit is set to 40%, aka. 5.03 MB/s absolute
  //	=> There is 15.86 TB of 18.50 TB free space left
  //	=> Of the 2 downloads, there are 779.35 MB of 9.55 GB downloaded already
  //	=> The remaining 8.77 GB will be downloaded in ETA 30m25s

  // Accessing the server stats is also possible
  stats, err := client.ServerStats()
  fmt.Printf("Total downloaded since start is %s, this month %s, this week %s and today %s\n", stats.Total, stats.Month, stats.Week, stats.Day)

  //	=> Total downloaded since start is 447.73 GB, this month 344.22 GB, this week 38.46 GB and today 965.50 MB

}

Check out cmd/example/example.go to find a more advanced client creation and how to send NZBs to SABnzbd from Go.

Documentation

Index

Constants

View Source
const (
	PriorityDefault PriorityType = -100
	PriorityPaused               = -2
	PriorityLow                  = -1
	PriorityNormal               = 0
	PriorityHigh                 = 1
	PriorityForced               = 2
)
View Source
const (
	Byte  = 1
	KByte = Byte * 1000
	MByte = KByte * 1000
	GByte = MByte * 1000
	TByte = GByte * 1000
	PByte = TByte * 1000
	EByte = PByte * 1000
)
View Source
const (
	KiByte = 1 << ((iota + 1) * 10)
	MiByte = KByte * 1000
	GiByte = MByte * 1000
	TiByte = GByte * 1000
	PiByte = TByte * 1000
	EiByte = PByte * 1000
)

Variables

View Source
var (
	ErrApikeyIncorrect error = errors.New("API Key Incorrect")
	ErrApikeyRequired  error = errors.New("API Key Required")
)
View Source
var ErrInvalidQueueCompleteAction error = errors.New("invalid queue complete action")

Functions

This section is empty.

Types

type AddNzbOption

type AddNzbOption func(*addNzbConfig) error

func AddNzbCategory

func AddNzbCategory(category string) AddNzbOption

func AddNzbName

func AddNzbName(name string) AddNzbOption

func AddNzbPriority

func AddNzbPriority(priority int) AddNzbOption

func AddNzbScript

func AddNzbScript(script string) AddNzbOption

func AddNzbUnpackingOption

func AddNzbUnpackingOption(unpackingOption int) AddNzbOption

func AddNzbUrl

func AddNzbUrl(url string) AddNzbOption

func AddNzbXCategory

func AddNzbXCategory(xcategory string) AddNzbOption

type BytesFromB

type BytesFromB int

func (BytesFromB) String added in v2.1.0

func (b BytesFromB) String() string

func (*BytesFromB) UnmarshalJSON

func (b *BytesFromB) UnmarshalJSON(data []byte) error

type BytesFromGB

type BytesFromGB int

func (BytesFromGB) String added in v2.1.0

func (b BytesFromGB) String() string

func (*BytesFromGB) UnmarshalJSON

func (b *BytesFromGB) UnmarshalJSON(data []byte) error

type BytesFromKB

type BytesFromKB int

func (BytesFromKB) String added in v2.1.0

func (b BytesFromKB) String() string

func (*BytesFromKB) UnmarshalJSON

func (b *BytesFromKB) UnmarshalJSON(data []byte) error

type BytesFromMB

type BytesFromMB int

func (BytesFromMB) String added in v2.1.0

func (b BytesFromMB) String() string

func (*BytesFromMB) UnmarshalJSON

func (b *BytesFromMB) UnmarshalJSON(data []byte) error

type HistoryResponse

type HistoryResponse struct {
	TotalSize         string        `json:"total_size"`
	MonthSize         string        `json:"month_size"`
	WeekSize          string        `json:"week_size"`
	DaySize           string        `json:"day_size"`
	Slots             []HistorySlot `json:"slots"`
	NoOfSlots         int           `json:"noofslots"`
	Version           string        `json:"version"`
	LastHistoryUpdate int           `json:"last_history_update"`
	// contains filtered or unexported fields
}

func (HistoryResponse) Error

func (e HistoryResponse) Error() string

func (*HistoryResponse) UnmarshalJSON

func (r *HistoryResponse) UnmarshalJSON(data []byte) error

type HistorySlot

type HistorySlot struct {
	ID                     int   `json:"id"`
	CompletedUnix          int64 `json:"completed"`
	Completed              time.Time
	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"`
	DownloadDuration       time.Duration
	PostProcessingTime     int64 `json:"postproc_time"`
	PostProcessingDuration time.Duration
	StageLogs              []HistoryStageLog `json:"stage_log"`
	Downloaded             int64             `json:"downloaded"` // represents downloaded bytes, not time
	Completeness           int               `json:"completeness"`
	FailMessage            string            `json:"fail_message"`
	URLInfo                string            `json:"url_info"`
	Bytes                  int               `json:"bytes"`
	Meta                   string            `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
}

func (*HistorySlot) UnmarshalJSON added in v2.3.0

func (r *HistorySlot) UnmarshalJSON(data []byte) error

type HistoryStageLog

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

type ItemFile

type ItemFile struct {
	ID        string      `json:"id"`
	NzfID     string      `json:"nzf_id"`
	Status    string      `json:"status"`
	Filename  string      `json:"filename"`
	Age       string      `json:"age"`
	Bytes     BytesFromB  `json:"bytes"`
	BytesLeft BytesFromMB `json:"mbleft"`
}

func (*ItemFile) UnmarshalJSON

func (f *ItemFile) UnmarshalJSON(data []byte) (err error)

type ItemFilesResponse

type ItemFilesResponse struct {
	Files []ItemFile `json:"files"`
	// contains filtered or unexported fields
}

func (ItemFilesResponse) Error

func (e ItemFilesResponse) Error() string

type Option

type Option func(*Sabnzbd) error

func Addr

func Addr(addr string) Option

func ApikeyAuth

func ApikeyAuth(apikey string) Option

func LoginAuth

func LoginAuth(username, password string) Option

func NoneAuth

func NoneAuth() Option

func Path

func Path(path string) Option

func SecureAddr

func SecureAddr(host string) Option

func UseHTTPAuth

func UseHTTPAuth(user, pass string) Option

func UseHttp

func UseHttp() Option

func UseHttps

func UseHttps() Option

func UseInsecureHTTP

func UseInsecureHTTP() Option

func UseRoundTripper

func UseRoundTripper(rt http.RoundTripper) Option

type PostProcessingMethod

type PostProcessingMethod uint
const (
	PostProcessingSkip PostProcessingMethod = iota
	PostProcessingRepair
	PostProcessingRepairUnpack
	PostProcessingRepairUnpackDelete
)

type PriorityType

type PriorityType int

type QueueCompleteAction

type QueueCompleteAction uint
const (
	QueueCompleteShutdownPC QueueCompleteAction = iota
	QueueCompleteHibernatePC
	QueueCompleteStandbyPC
	QueueCompleteShutdownProgram
)

type QueueResponse

type QueueResponse struct {
	Version                string      `json:"version"`
	Paused                 bool        `json:"paused"`
	PauseInt               string      `json:"pause_int"`
	PausedAll              bool        `json:"paused_all"`
	DownloadDiskFreeSpace  BytesFromGB `json:"diskspace1"`
	CompleteDiskFreeSpace  BytesFromGB `json:"diskspace2"`
	Diskspace1Norm         string      `json:"diskspace1_norm"`
	Diskspace2Norm         string      `json:"diskspace2_norm"`
	DownloadDiskTotalSpace BytesFromGB `json:"diskspacetotal1"`
	CompleteDiskTotalSpace BytesFromGB `json:"diskspacetotal2"`
	SpeedLimitPercentage   int         `json:"speedlimit,string"`
	SpeedLimit             BytesFromB  `json:"speedlimit_abs"`
	HaveWarnings           string      `json:"have_warnings"`
	FinishAction           *string     `json:"finishaction"`
	Quota                  string      `json:"quota"`
	HaveQuota              bool        `json:"have_quota"`
	LeftQuota              string      `json:"left_quota"`
	CacheArt               string      `json:"cache_art"`
	CacheSize              string      `json:"cache_size"`
	BytesPerSecond         BytesFromKB `json:"kbpersec"`
	Speed                  string      `json:"speed"`
	BytesLeft              BytesFromMB `json:"mbleft"`
	BytesTotal             BytesFromMB `json:"mb"`
	Bytes                  BytesFromMB
	SizeLeft               string      `json:"sizeleft"`
	Size                   string      `json:"size"`
	NoOfSlotsTotal         int         `json:"noofslots_total"`
	NoOfSlots              int         `json:"noofslots"`
	Start                  int         `json:"start"`
	Limit                  int         `json:"limit"`
	Finish                 int         `json:"finish"`
	Status                 string      `json:"status"`
	TimeLeft               SabDuration `json:"timeleft"`
	Slots                  []QueueSlot `json:"slots"`
	// contains filtered or unexported fields
}

func (QueueResponse) Error

func (e QueueResponse) Error() string

func (*QueueResponse) UnmarshalJSON

func (r *QueueResponse) UnmarshalJSON(data []byte) error

type QueueSlot

type QueueSlot struct {
	Index        int         `json:"index"`
	NzoID        string      `json:"nzo_id"`
	UnpackOpts   string      `json:"unpackopts"`
	Priority     string      `json:"priority"`
	Script       string      `json:"script"`
	Filename     string      `json:"filename"`
	Labels       []string    `json:"labels"`
	Password     string      `json:"password"`
	Category     string      `json:"cat"`
	BytesLeft    BytesFromMB `json:"mbleft"`
	BytesTotal   BytesFromMB `json:"mb"`
	Size         string      `json:"size"`
	SizeLeft     string      `json:"sizeleft"`
	Percentage   int         `json:"percentage,string"`
	MBMissing    BytesFromMB `json:"mbmissing"` // doesn't seem to be working
	Bytes        BytesFromMB
	DirectUnpack string      `json:"direct_unpack"`
	Status       string      `json:"status"`
	TimeLeft     SabDuration `json:"timeleft"`
	AverageAge   string      `json:"avg_age"`
}

func (*QueueSlot) UnmarshalJSON added in v2.3.0

func (r *QueueSlot) UnmarshalJSON(data []byte) error

type SabDuration

type SabDuration time.Duration

func (SabDuration) String added in v2.1.0

func (d SabDuration) String() string

func (*SabDuration) UnmarshalJSON

func (d *SabDuration) UnmarshalJSON(data []byte) error

type Sabnzbd

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

func New

func New(options ...Option) (s *Sabnzbd, err error)

func SecureClient

func SecureClient(host, apikey string) (*Sabnzbd, error)

func SimpleClient

func SimpleClient(addr, apikey string) (*Sabnzbd, error)

func (*Sabnzbd) AddFile

func (s *Sabnzbd) AddFile(filename string, options ...AddNzbOption) (nzoids []string, err error)

func (*Sabnzbd) AddLocalfile

func (s *Sabnzbd) AddLocalfile(filename string, options ...AddNzbOption) (nzoids []string, err error)

func (*Sabnzbd) AddReader

func (s *Sabnzbd) AddReader(reader io.Reader, filename string, options ...AddNzbOption) (nzoids []string, err error)

func (*Sabnzbd) AddURL

func (s *Sabnzbd) AddURL(options ...AddNzbOption) (nzoids []string, err error)

func (*Sabnzbd) Auth

func (s *Sabnzbd) Auth() (auth string, err error)

func (*Sabnzbd) Categories

func (s *Sabnzbd) Categories() (categories []string, err error)

func (*Sabnzbd) ChangeCategory

func (s *Sabnzbd) ChangeCategory(nzoid, category string) (err error)

func (*Sabnzbd) ChangeName

func (s *Sabnzbd) ChangeName(nzoid, name string) (err error)

func (*Sabnzbd) ChangePostProcessing

func (s *Sabnzbd) ChangePostProcessing(nzoid string, method PostProcessingMethod) (err error)

func (*Sabnzbd) ChangePriority

func (s *Sabnzbd) ChangePriority(nzoid string, priority PriorityType) (err error)

func (*Sabnzbd) ChangeQueueCompleteAction

func (s *Sabnzbd) ChangeQueueCompleteAction(action QueueCompleteAction) (err error)

func (*Sabnzbd) ChangeScript

func (s *Sabnzbd) ChangeScript(nzoid, script string) (err error)

func (*Sabnzbd) Delete

func (s *Sabnzbd) Delete(removeFiles bool, nzos ...string) (err error)

func (*Sabnzbd) DeleteAll

func (s *Sabnzbd) DeleteAll(removeFiles bool) (err error)

func (*Sabnzbd) DeleteAllHistory

func (s *Sabnzbd) DeleteAllHistory(removeFailedFiles bool) (err error)

func (*Sabnzbd) DeleteFailedHistory

func (s *Sabnzbd) DeleteFailedHistory(removeFailedFiles bool) (err error)

func (*Sabnzbd) DeleteHistory

func (s *Sabnzbd) DeleteHistory(removeFailedFiles bool, nzos ...string) (err error)

func (*Sabnzbd) GetItemFiles

func (s *Sabnzbd) GetItemFiles(nzoid string) (files []ItemFile, err error)

func (*Sabnzbd) History

func (s *Sabnzbd) History(start, limit int) (r *HistoryResponse, err error)

func (*Sabnzbd) Move

func (s *Sabnzbd) Move(nzo1, nzo2 string) (err error)

todo deal with return value { "result": { "priority": int, "position": int } }

func (*Sabnzbd) MoveByPriority

func (s *Sabnzbd) MoveByPriority(nzo string, priority int) (err error)

func (*Sabnzbd) Pause

func (s *Sabnzbd) Pause() (err error)

func (*Sabnzbd) PauseItem

func (s *Sabnzbd) PauseItem(nzoid string) (err error)

func (*Sabnzbd) PausePostProcessing

func (s *Sabnzbd) PausePostProcessing() (err error)

func (*Sabnzbd) PauseTemporarily

func (s *Sabnzbd) PauseTemporarily(t time.Duration) (err error)

PauseTemporarily will pause for a time duration. The lowest possible value is one minute. Durations below one minute will resume the queue.

func (*Sabnzbd) Queue added in v2.1.0

func (s *Sabnzbd) Queue(start, limit int) (r *QueueResponse, err error)

func (*Sabnzbd) Restart

func (s *Sabnzbd) Restart() (err error)

func (*Sabnzbd) Resume

func (s *Sabnzbd) Resume() (err error)

func (*Sabnzbd) ResumeItem

func (s *Sabnzbd) ResumeItem(nzoid string) (err error)

func (*Sabnzbd) ResumePostProcessing

func (s *Sabnzbd) ResumePostProcessing() (err error)

func (*Sabnzbd) Retry

func (s *Sabnzbd) Retry(nzoid string) (err error)

func (*Sabnzbd) Scripts

func (s *Sabnzbd) Scripts() (scripts []string, err error)

func (*Sabnzbd) ServerStats added in v2.2.0

func (c *Sabnzbd) ServerStats() (r *ServerStatsResponse, err error)

func (*Sabnzbd) SetOptions

func (s *Sabnzbd) SetOptions(options ...Option) (err error)

func (*Sabnzbd) Shutdown

func (s *Sabnzbd) Shutdown() (err error)

func (*Sabnzbd) SimpleHistory

func (s *Sabnzbd) SimpleHistory() (r *HistoryResponse, err error)

func (*Sabnzbd) SimpleQueue

func (s *Sabnzbd) SimpleQueue() (r *QueueResponse, err error)

func (*Sabnzbd) SpeedLimit

func (s *Sabnzbd) SpeedLimit(kbps int) (err error)

func (*Sabnzbd) Version

func (s *Sabnzbd) Version() (version string, err error)

func (*Sabnzbd) Warnings

func (s *Sabnzbd) Warnings() (warnings []string, err error)

type ServerStatsDate added in v2.2.0

type ServerStatsDate string

type ServerStatsResponse added in v2.2.0

type ServerStatsResponse struct {
	Total   BytesFromB                   `json:"total"`
	Month   BytesFromB                   `json:"month"`
	Week    BytesFromB                   `json:"week"`
	Day     BytesFromB                   `json:"day"`
	Servers map[string]ServerStatsServer `json:"servers"`
}

type ServerStatsServer added in v2.2.0

type ServerStatsServer struct {
	Total           BytesFromB                     `json:"total"`
	Month           BytesFromB                     `json:"month"`
	Week            BytesFromB                     `json:"week"`
	Day             BytesFromB                     `json:"day"`
	Daily           map[ServerStatsDate]BytesFromB `json:"daily"`
	ArticlesTried   map[ServerStatsDate]int        `json:"articles_tried"`
	ArticlesSuccess map[ServerStatsDate]int        `json:"articles_success"`
}

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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