Skip to content

Commit 4f8b389

Browse files
committed
Add naming for lidarr
1 parent fdc7303 commit 4f8b389

File tree

2 files changed

+94
-1
lines changed

2 files changed

+94
-1
lines changed

lidarr/naming.go

+13-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,18 @@ import (
1212
// Define Base Path for Naming calls.
1313
const bpNaming = APIver + "/config/naming"
1414

15+
// CRF is ColonReplacementFormat, for naming config.
16+
type CRF int
17+
18+
// These are all of the possible Colon Replacement Formats (for naming config) in Lidarr.
19+
const (
20+
ColonDelete CRF = iota
21+
ColonReplaceWithDash
22+
ColonReplaceWithSpaceDash
23+
ColonReplaceWithSpaceDashSpace
24+
ColonSmartReplace
25+
)
26+
1527
// Naming represents the config/naming endpoint in Lidarr.
1628
type Naming struct {
1729
RenameTracks bool `json:"renameTracks"`
@@ -20,7 +32,7 @@ type Naming struct {
2032
IncludeAlbumTitle bool `json:"includeAlbumTitle"`
2133
IncludeQuality bool `json:"includeQuality"`
2234
ReplaceSpaces bool `json:"replaceSpaces"`
23-
ColonReplacementFormat int `json:"colonReplacementFormat"`
35+
ColonReplacementFormat CRF `json:"colonReplacementFormat"`
2436
ID int64 `json:"id"`
2537
StandardTrackFormat string `json:"standardTrackFormat"`
2638
MultiDiscTrackFormat string `json:"multiDiscTrackFormat"`

readarr/naming.go

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
package readarr
2+
3+
import (
4+
"bytes"
5+
"context"
6+
"encoding/json"
7+
"fmt"
8+
9+
"golift.io/starr"
10+
)
11+
12+
// Define Base Path for Naming calls.
13+
const bpNaming = APIver + "/config/naming"
14+
15+
// Naming represents the config/naming endpoint in Radarr.
16+
type Naming struct {
17+
RenameBooks bool `json:"renameBooks"`
18+
ReplaceIllegalCharacters bool `json:"replaceIllegalCharacters"`
19+
IncludeAuthorName bool `json:"includeAuthorName"`
20+
IncludeBookTitle bool `json:"includeBookTitle"`
21+
IncludeQuality bool `json:"includeQuality"`
22+
ReplaceSpaces bool `json:"replaceSpaces"`
23+
ColonReplacementFormat CRF `json:"colonReplacementFormat"`
24+
ID int64 `json:"id"`
25+
StandardBookFormat string `json:"standardBookFormat"`
26+
AuthorFolderFormat string `json:"authorFolderFormat"`
27+
}
28+
29+
// CRF is ColonReplacementFormat, for naming config.
30+
type CRF int
31+
32+
// These are all of the possible Colon Replacement Formats (for naming config) in Readarr.
33+
const (
34+
ColonDelete CRF = iota
35+
ColonReplaceWithDash
36+
ColonReplaceWithSpaceDash
37+
ColonReplaceWithSpaceDashSpace
38+
ColonSmartReplace
39+
)
40+
41+
// GetNaming returns the file naming rules.
42+
func (r *Readarr) GetNaming() (*Naming, error) {
43+
return r.GetNamingContext(context.Background())
44+
}
45+
46+
// GetNamingContext returns the file naming rules.
47+
func (r *Readarr) GetNamingContext(ctx context.Context) (*Naming, error) {
48+
var output Naming
49+
50+
req := starr.Request{URI: bpNaming}
51+
if err := r.GetInto(ctx, req, &output); err != nil {
52+
return nil, fmt.Errorf("api.Get(%s): %w", &req, err)
53+
}
54+
55+
return &output, nil
56+
}
57+
58+
// UpdateNaming updates the file naming rules.
59+
func (r *Readarr) UpdateNaming(naming *Naming) (*Naming, error) {
60+
return r.UpdateNamingContext(context.Background(), naming)
61+
}
62+
63+
// UpdateNamingContext updates the file naming rules.
64+
func (r *Readarr) UpdateNamingContext(ctx context.Context, naming *Naming) (*Naming, error) {
65+
var (
66+
output Naming
67+
body bytes.Buffer
68+
)
69+
70+
naming.ID = 1
71+
if err := json.NewEncoder(&body).Encode(naming); err != nil {
72+
return nil, fmt.Errorf("json.Marshal(%s): %w", bpNaming, err)
73+
}
74+
75+
req := starr.Request{URI: bpNaming, Body: &body}
76+
if err := r.PutInto(ctx, req, &output); err != nil {
77+
return nil, fmt.Errorf("api.Put(%s): %w", &req, err)
78+
}
79+
80+
return &output, nil
81+
}

0 commit comments

Comments
 (0)