Fix Sonarr TV request policy and bump gateway to 0.1.40
This commit is contained in:
@@ -84,7 +84,31 @@ type RootFolder struct {
|
||||
}
|
||||
|
||||
type QualityProfile struct {
|
||||
ID int `json:"id"`
|
||||
ID int `json:"id"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
// RequestOptions are Memby's deliberate request policy. They must be supplied by the
|
||||
// gateway: letting Sonarr choose a profile or search flag reintroduces unsafe defaults.
|
||||
type RequestOptions struct {
|
||||
QualityProfileID int
|
||||
SearchImmediately bool
|
||||
}
|
||||
|
||||
func (c *Client) RootFolders(ctx context.Context) ([]RootFolder, error) {
|
||||
var roots []RootFolder
|
||||
if err := c.get(ctx, "/api/v3/rootfolder", &roots); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return roots, nil
|
||||
}
|
||||
|
||||
func (c *Client) QualityProfiles(ctx context.Context) ([]QualityProfile, error) {
|
||||
var profiles []QualityProfile
|
||||
if err := c.get(ctx, "/api/v3/qualityprofile", &profiles); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return profiles, nil
|
||||
}
|
||||
|
||||
type EpisodeFile struct {
|
||||
@@ -168,23 +192,18 @@ func (c *Client) Lookup(ctx context.Context, term string) ([]Series, error) {
|
||||
return series, nil
|
||||
}
|
||||
|
||||
// AddRequested adds a series, monitors its seasons and asks Sonarr to search for missing
|
||||
// episodes immediately. An unmonitored catalogue row does not fulfil a media request.
|
||||
func (c *Client) AddRequested(ctx context.Context, series Series) (Series, error) {
|
||||
var roots []RootFolder
|
||||
if err := c.get(ctx, "/api/v3/rootfolder", &roots); err != nil {
|
||||
return Series{}, err
|
||||
// AddRequested adds a monitored series using the supplied request policy. It never reads
|
||||
// Sonarr's first quality profile, because that is commonly "Any".
|
||||
func (c *Client) AddRequested(ctx context.Context, series Series, rootFolder string, options RequestOptions) (Series, error) {
|
||||
if strings.TrimSpace(rootFolder) == "" {
|
||||
return Series{}, fmt.Errorf("sonarr: request root folder is required")
|
||||
}
|
||||
var profiles []QualityProfile
|
||||
if err := c.get(ctx, "/api/v3/qualityprofile", &profiles); err != nil {
|
||||
return Series{}, err
|
||||
}
|
||||
if len(roots) == 0 || len(profiles) == 0 {
|
||||
return Series{}, fmt.Errorf("sonarr: no root folder or quality profile configured")
|
||||
if options.QualityProfileID <= 0 {
|
||||
return Series{}, fmt.Errorf("sonarr: request quality profile is required")
|
||||
}
|
||||
series.ID = 0
|
||||
series.RootFolderPath = roots[0].Path
|
||||
series.QualityProfileID = profiles[0].ID
|
||||
series.RootFolderPath = rootFolder
|
||||
series.QualityProfileID = options.QualityProfileID
|
||||
series.Monitored = true
|
||||
series.SeasonFolder = true
|
||||
for i := range series.Seasons {
|
||||
@@ -193,7 +212,7 @@ func (c *Client) AddRequested(ctx context.Context, series Series) (Series, error
|
||||
body := struct {
|
||||
Series
|
||||
AddOptions map[string]bool `json:"addOptions"`
|
||||
}{Series: series, AddOptions: map[string]bool{"searchForMissingEpisodes": true}}
|
||||
}{Series: series, AddOptions: map[string]bool{"searchForMissingEpisodes": options.SearchImmediately}}
|
||||
var added Series
|
||||
if err := c.post(ctx, "/api/v3/series", body, &added); err != nil {
|
||||
return Series{}, err
|
||||
|
||||
Reference in New Issue
Block a user