diff --git a/lidarr/queue.go b/lidarr/queue.go index 2825b0a..621ba22 100644 --- a/lidarr/queue.go +++ b/lidarr/queue.go @@ -1,7 +1,9 @@ package lidarr import ( + "bytes" "context" + "encoding/json" "fmt" "path" "time" @@ -121,3 +123,31 @@ func (l *Lidarr) DeleteQueueContext(ctx context.Context, queueID int64, opts *st return nil } + +// QueueGrab tells the app to grab an item that's in queue. +// Most often used on items with a delay set from a delay profile. +func (l *Lidarr) QueueGrab(ids ...int64) error { + return l.QueueGrabContext(context.Background(), ids...) +} + +// QueueGrabContext tells the app to grab an item that's in queue, probably set to a delay. +// Most often used on items with a delay set from a delay profile. +func (l *Lidarr) QueueGrabContext(ctx context.Context, ids ...int64) error { + idList := struct { + IDs []int64 `json:"ids"` + }{IDs: ids} + + var body bytes.Buffer + if err := json.NewEncoder(&body).Encode(idList); err != nil { + return fmt.Errorf("json.Marshal(%s): %w", bpQueue, err) + } + + var output interface{} // any ok + + req := starr.Request{URI: path.Join(bpQueue, "grab", "bulk"), Body: &body} + if err := l.PostInto(ctx, req, &output); err != nil { + return fmt.Errorf("api.Post(%s): %w", &req, err) + } + + return nil +} diff --git a/radarr/queue.go b/radarr/queue.go index 6ebe91e..a29e879 100644 --- a/radarr/queue.go +++ b/radarr/queue.go @@ -1,7 +1,9 @@ package radarr import ( + "bytes" "context" + "encoding/json" "fmt" "path" "time" @@ -122,3 +124,31 @@ func (r *Radarr) DeleteQueueContext(ctx context.Context, queueID int64, opts *st return nil } + +// QueueGrab tells the app to grab an item that's in queue. +// Most often used on items with a delay set from a delay profile. +func (r *Radarr) QueueGrab(ids ...int64) error { + return r.QueueGrabContext(context.Background(), ids...) +} + +// QueueGrabContext tells the app to grab an item that's in queue, probably set to a delay. +// Most often used on items with a delay set from a delay profile. +func (r *Radarr) QueueGrabContext(ctx context.Context, ids ...int64) error { + idList := struct { + IDs []int64 `json:"ids"` + }{IDs: ids} + + var body bytes.Buffer + if err := json.NewEncoder(&body).Encode(idList); err != nil { + return fmt.Errorf("json.Marshal(%s): %w", bpQueue, err) + } + + var output interface{} // any ok + + req := starr.Request{URI: path.Join(bpQueue, "grab", "bulk"), Body: &body} + if err := r.PostInto(ctx, req, &output); err != nil { + return fmt.Errorf("api.Post(%s): %w", &req, err) + } + + return nil +} diff --git a/readarr/queue.go b/readarr/queue.go index 3ab5aae..637d645 100644 --- a/readarr/queue.go +++ b/readarr/queue.go @@ -1,7 +1,9 @@ package readarr import ( + "bytes" "context" + "encoding/json" "fmt" "path" "time" @@ -123,3 +125,31 @@ func (r *Readarr) DeleteQueueContext(ctx context.Context, queueID int64, opts *s return nil } + +// QueueGrab tells the app to grab an item that's in queue. +// Most often used on items with a delay set from a delay profile. +func (r *Readarr) QueueGrab(ids ...int64) error { + return r.QueueGrabContext(context.Background(), ids...) +} + +// QueueGrabContext tells the app to grab an item that's in queue, probably set to a delay. +// Most often used on items with a delay set from a delay profile. +func (r *Readarr) QueueGrabContext(ctx context.Context, ids ...int64) error { + idList := struct { + IDs []int64 `json:"ids"` + }{IDs: ids} + + var body bytes.Buffer + if err := json.NewEncoder(&body).Encode(idList); err != nil { + return fmt.Errorf("json.Marshal(%s): %w", bpQueue, err) + } + + var output interface{} // any ok + + req := starr.Request{URI: path.Join(bpQueue, "grab", "bulk"), Body: &body} + if err := r.PostInto(ctx, req, &output); err != nil { + return fmt.Errorf("api.Post(%s): %w", &req, err) + } + + return nil +} diff --git a/sonarr/queue.go b/sonarr/queue.go index f8ef9e9..be21d75 100644 --- a/sonarr/queue.go +++ b/sonarr/queue.go @@ -1,7 +1,9 @@ package sonarr import ( + "bytes" "context" + "encoding/json" "fmt" "path" "time" @@ -123,3 +125,31 @@ func (s *Sonarr) DeleteQueueContext(ctx context.Context, queueID int64, opts *st return nil } + +// QueueGrab tells the app to grab an item that's in queue. +// Most often used on items with a delay set from a delay profile. +func (s *Sonarr) QueueGrab(ids ...int64) error { + return s.QueueGrabContext(context.Background(), ids...) +} + +// QueueGrabContext tells the app to grab an item that's in queue, probably set to a delay. +// Most often used on items with a delay set from a delay profile. +func (s *Sonarr) QueueGrabContext(ctx context.Context, ids ...int64) error { + idList := struct { + IDs []int64 `json:"ids"` + }{IDs: ids} + + var body bytes.Buffer + if err := json.NewEncoder(&body).Encode(idList); err != nil { + return fmt.Errorf("json.Marshal(%s): %w", bpQueue, err) + } + + var output interface{} // any ok + + req := starr.Request{URI: path.Join(bpQueue, "grab", "bulk"), Body: &body} + if err := s.PostInto(ctx, req, &output); err != nil { + return fmt.Errorf("api.Post(%s): %w", &req, err) + } + + return nil +}