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)