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.
58 lines
1.3 KiB
Go
58 lines
1.3 KiB
Go
package arr
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"bellhop/internal/config"
|
|
)
|
|
|
|
// Lidarr drives a Lidarr v1 instance.
|
|
type Lidarr struct {
|
|
h *httpClient
|
|
qualityProfileID int
|
|
metadataProfileID int
|
|
rootFolder string
|
|
}
|
|
|
|
func NewLidarr(cfg *config.ArrConfig) *Lidarr {
|
|
return &Lidarr{
|
|
h: newHTTP(cfg.URL, cfg.APIKey),
|
|
qualityProfileID: cfg.QualityProfileID,
|
|
metadataProfileID: cfg.MetadataProfileID,
|
|
rootFolder: cfg.RootFolder,
|
|
}
|
|
}
|
|
|
|
func (l *Lidarr) Search(ctx context.Context, term string) ([]Result, error) {
|
|
body, err := l.h.get(ctx, "/api/v1/artist/lookup", map[string]string{"term": term})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
// Lidarr's lookup uses "artistName" instead of "title".
|
|
return parseLookup(body, "artistName")
|
|
}
|
|
|
|
func (l *Lidarr) Add(ctx context.Context, res Result) error {
|
|
if len(res.raw) == 0 {
|
|
return fmt.Errorf("lidarr: empty result")
|
|
}
|
|
body, err := buildAddBody(res.raw, map[string]any{
|
|
"qualityProfileId": l.qualityProfileID,
|
|
"metadataProfileId": l.metadataProfileID,
|
|
"rootFolderPath": l.rootFolder,
|
|
"monitored": true,
|
|
"addOptions": map[string]any{
|
|
"monitor": "all",
|
|
"searchForMissingAlbums": true,
|
|
},
|
|
})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
_, err = l.h.post(ctx, "/api/v1/artist", body)
|
|
return err
|
|
}
|
|
|
|
var _ Client = (*Lidarr)(nil)
|