Skip to content

Commit

Permalink
Add queue grab methods
Browse files Browse the repository at this point in the history
  • Loading branch information
davidnewhall committed Aug 15, 2023
1 parent 748fa85 commit 903edcf
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 0 deletions.
30 changes: 30 additions & 0 deletions lidarr/queue.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package lidarr

import (
"bytes"
"context"
"encoding/json"
"fmt"
"path"
"time"
Expand Down Expand Up @@ -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
}
30 changes: 30 additions & 0 deletions radarr/queue.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package radarr

import (
"bytes"
"context"
"encoding/json"
"fmt"
"path"
"time"
Expand Down Expand Up @@ -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
}
30 changes: 30 additions & 0 deletions readarr/queue.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package readarr

import (
"bytes"
"context"
"encoding/json"
"fmt"
"path"
"time"
Expand Down Expand Up @@ -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
}
30 changes: 30 additions & 0 deletions sonarr/queue.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package sonarr

import (
"bytes"
"context"
"encoding/json"
"fmt"
"path"
"time"
Expand Down Expand Up @@ -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
}

0 comments on commit 903edcf

Please sign in to comment.