Session 3: Radarr/Sonarr/Lidarr clients with add-on-search
Adds internal/arr with a shared HTTP layer and per-service clients that look up candidates and POST the chosen one back with monitored=true and search-on-add enabled. Lidarr requires metadata_profile_id, now part of ArrConfig and validated when lidarr is set.
This commit is contained in:
55
internal/arr/sonarr.go
Normal file
55
internal/arr/sonarr.go
Normal file
@@ -0,0 +1,55 @@
|
||||
package arr
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"bellhop/internal/config"
|
||||
)
|
||||
|
||||
// Sonarr drives a Sonarr v3/v4 instance.
|
||||
type Sonarr struct {
|
||||
h *httpClient
|
||||
qualityProfileID int
|
||||
rootFolder string
|
||||
}
|
||||
|
||||
func NewSonarr(cfg *config.ArrConfig) *Sonarr {
|
||||
return &Sonarr{
|
||||
h: newHTTP(cfg.URL, cfg.APIKey),
|
||||
qualityProfileID: cfg.QualityProfileID,
|
||||
rootFolder: cfg.RootFolder,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Sonarr) Search(ctx context.Context, term string) ([]Result, error) {
|
||||
body, err := s.h.get(ctx, "/api/v3/series/lookup", map[string]string{"term": term})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return parseLookup(body, "title")
|
||||
}
|
||||
|
||||
func (s *Sonarr) Add(ctx context.Context, res Result) error {
|
||||
if len(res.raw) == 0 {
|
||||
return fmt.Errorf("sonarr: empty result")
|
||||
}
|
||||
body, err := buildAddBody(res.raw, map[string]any{
|
||||
"qualityProfileId": s.qualityProfileID,
|
||||
"rootFolderPath": s.rootFolder,
|
||||
"monitored": true,
|
||||
"seasonFolder": true,
|
||||
"addOptions": map[string]any{
|
||||
"monitor": "all",
|
||||
"searchForMissingEpisodes": true,
|
||||
"searchForCutoffUnmetEpisodes": false,
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = s.h.post(ctx, "/api/v3/series", body)
|
||||
return err
|
||||
}
|
||||
|
||||
var _ Client = (*Sonarr)(nil)
|
||||
Reference in New Issue
Block a user