Skip to content

Commit

Permalink
update naming for radarr and sonarr
Browse files Browse the repository at this point in the history
  • Loading branch information
davidnewhall committed Jun 11, 2024
1 parent 55af00b commit f10d3bf
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 40 deletions.
2 changes: 2 additions & 0 deletions radarr/mediamanagement.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const bpMediaManagement = APIver + "/config/mediaManagement"

// MediaManagement represents the /config/mediaManagement endpoint.
type MediaManagement struct {
UseScriptImport bool `json:"useScriptImport,omitempty"`
AutoRenameFolders bool `json:"autoRenameFolders,omitempty"`
AutoUnmonitorPreviouslyDownloadedMovies bool `json:"autoUnmonitorPreviouslyDownloadedMovies,omitempty"`
CopyUsingHardlinks bool `json:"copyUsingHardlinks,omitempty"`
Expand All @@ -27,6 +28,7 @@ type MediaManagement struct {
ID int64 `json:"id"`
MinimumFreeSpaceWhenImporting int64 `json:"minimumFreeSpaceWhenImporting"` // 0 or empty not allowed
RecycleBinCleanupDays int64 `json:"recycleBinCleanupDays,omitempty"`
ScriptImportPath string `json:"scriptImportPath,omitempty"`
ChmodFolder string `json:"chmodFolder,omitempty"`
ChownGroup string `json:"chownGroup"` // empty string is valid
DownloadPropersAndRepacks string `json:"downloadPropersAndRepacks,omitempty"`
Expand Down
24 changes: 17 additions & 7 deletions radarr/naming.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,23 @@ const bpNaming = APIver + "/config/naming"
type Naming struct {
RenameMovies bool `json:"renameMovies,omitempty"`
ReplaceIllegalCharacters bool `json:"replaceIllegalCharacters,omitempty"`
IncludeQuality bool `json:"includeQuality,omitempty"`
ReplaceSpaces bool `json:"replaceSpaces,omitempty"`
ID int64 `json:"id"` // ID must always be 1 (Oct 10, 2022)
ColonReplacementFormat string `json:"colonReplacementFormat,omitempty"`
ColonReplacementFormat CRF `json:"colonReplacementFormat,omitempty"`
StandardMovieFormat string `json:"standardMovieFormat"` // required
MovieFolderFormat string `json:"movieFolderFormat"` // required
Separator string `json:"separatort,omitempty"`
NumberStyle string `json:"numberStylet,omitempty"`
}

// CRF is ColonReplacementFormat, for naming config.
type CRF string

// These are all of the possible Colon Replacement Formats (for naming config) in Radarr.
const (
ColonDelete CRF = "delete"
ColonReplaceWithDash CRF = "dash"
ColonReplaceWithSpaceDash CRF = "spaceDash"
ColonReplaceWithSpaceDashSpace CRF = "spaceDashSpace"
)

// GetNaming returns the file naming rules.
func (r *Radarr) GetNaming() (*Naming, error) {
return r.GetNamingContext(context.Background())
Expand All @@ -50,9 +57,12 @@ func (r *Radarr) UpdateNaming(naming *Naming) (*Naming, error) {

// UpdateNamingContext updates the file naming rules.
func (r *Radarr) UpdateNamingContext(ctx context.Context, naming *Naming) (*Naming, error) {
var output Naming
var (
output Naming
body bytes.Buffer
)

var body bytes.Buffer
naming.ID = 1
if err := json.NewEncoder(&body).Encode(naming); err != nil {
return nil, fmt.Errorf("json.Marshal(%s): %w", bpNaming, err)
}
Expand Down
8 changes: 1 addition & 7 deletions radarr/naming_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ const namingBody = `{
"colonReplacementFormat": "delete",
"standardMovieFormat": "{Movie.Title}.{Release.Year}.{Quality.Title}",
"movieFolderFormat": "{Movie Title} ({Release Year})",
"includeQuality": true,
"replaceSpaces": true,
"id": 1
}`

Expand All @@ -35,10 +33,8 @@ func TestGetNaming(t *testing.T) {
WithResponse: &radarr.Naming{
ID: 1,
ReplaceIllegalCharacters: true,
IncludeQuality: true,
ReplaceSpaces: true,
RenameMovies: true,
ColonReplacementFormat: "delete",
ColonReplacementFormat: radarr.ColonDelete,
StandardMovieFormat: "{Movie.Title}.{Release.Year}.{Quality.Title}",
MovieFolderFormat: "{Movie Title} ({Release Year})",
},
Expand Down Expand Up @@ -87,8 +83,6 @@ func TestUpdateNaming(t *testing.T) {
WithResponse: &radarr.Naming{
ID: 1,
ReplaceIllegalCharacters: true,
IncludeQuality: true,
ReplaceSpaces: true,
RenameMovies: true,
ColonReplacementFormat: "delete",
StandardMovieFormat: "{Movie.Title}.{Release.Year}.{Quality.Title}",
Expand Down
2 changes: 2 additions & 0 deletions sonarr/mediamanagement.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const bpMediaManagement = APIver + "/config/mediaManagement"

// MediaManagement represents the /config/mediamanagement endpoint.
type MediaManagement struct {
UseScriptImport bool `json:"useScriptImport,omitempty"`
AutoUnmonitorPreviouslyDownloadedEpisodes bool `json:"autoUnmonitorPreviouslyDownloadedEpisodes,omitempty"`
CopyUsingHardlinks bool `json:"copyUsingHardlinks,omitempty"`
CreateEmptySeriesFolders bool `json:"createEmptySeriesFolders,omitempty"`
Expand All @@ -25,6 +26,7 @@ type MediaManagement struct {
ID int64 `json:"id"`
MinimumFreeSpaceWhenImporting int64 `json:"minimumFreeSpaceWhenImporting"` // 0 or empty not allowed
RecycleBinCleanupDays int64 `json:"recycleBinCleanupDays,omitempty"`
ScriptImportPath string `json:"scriptImportPath,omitempty"`
ChmodFolder string `json:"chmodFolder,omitempty"`
ChownGroup string `json:"chownGroup"` // empty string is valid
DownloadPropersAndRepacks string `json:"downloadPropersAndRepacks,omitempty"`
Expand Down
26 changes: 18 additions & 8 deletions sonarr/naming.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,25 @@ import (
// Define Base Path for Naming calls.
const bpNaming = APIver + "/config/naming"

// CRF is ColonReplacementFormat, for naming config.
type CRF int

// These are all of the possible Colon Replacement Formats (for naming config) in Sonarr.
const (
ColonDelete CRF = iota
ColonReplaceWithDash
ColonReplaceWithSpaceDash
ColonReplaceWithSpaceDashSpace
ColonSmartReplace
)

// Naming represents the config/naming endpoint in Sonarr.
type Naming struct {
RenameEpisodes bool `json:"renameEpisodes,omitempty"`
ReplaceIllegalCharacters bool `json:"replaceIllegalCharacters,omitempty"`
IncludeQuality bool `json:"includeQuality,omitempty"`
IncludeSeriesTitle bool `json:"includeSeriesTitle,omitempty"`
IncludeEpisodeTitle bool `json:"includeEpisodeTitle,omitempty"`
ReplaceSpaces bool `json:"replaceSpaces,omitempty"`
ColonReplacementFormat CRF `json:"colonReplacementFormat,omitempty"`
ID int64 `json:"id,omitempty"`
MultiEpisodeStyle int64 `json:"multiEpisodeStyle,omitempty"`
Separator string `json:"separator,omitempty"`
NumberStyle string `json:"numberStyle,omitempty"`
DailyEpisodeFormat string `json:"dailyEpisodeFormat,omitempty"`
AnimeEpisodeFormat string `json:"animeEpisodeFormat,omitempty"`
SeriesFolderFormat string `json:"seriesFolderFormat,omitempty"`
Expand Down Expand Up @@ -56,9 +63,12 @@ func (s *Sonarr) UpdateNaming(naming *Naming) (*Naming, error) {

// UpdateNamingContext updates the naming.
func (s *Sonarr) UpdateNamingContext(ctx context.Context, naming *Naming) (*Naming, error) {
var output Naming
var (
output Naming
body bytes.Buffer
)

var body bytes.Buffer
naming.ID = 1
if err := json.NewEncoder(&body).Encode(naming); err != nil {
return nil, fmt.Errorf("json.Marshal(%s): %w", bpNaming, err)
}
Expand Down
20 changes: 2 additions & 18 deletions sonarr/naming_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
)

const namingBody = `{
"colonReplacementFormat": 0,
"renameEpisodes": false,
"replaceIllegalCharacters": true,
"multiEpisodeStyle": 0,
Expand All @@ -21,12 +22,6 @@ const namingBody = `{
"seriesFolderFormat": "{Series Title}",
"seasonFolderFormat": "Season {season}",
"specialsFolderFormat": "Specials",
"includeSeriesTitle": true,
"includeEpisodeTitle": false,
"includeQuality": false,
"replaceSpaces": true,
"separator": " - ",
"numberStyle": "S{season:00}E{episode:00}",
"id": 1
}`

Expand All @@ -51,12 +46,7 @@ func TestGetNaming(t *testing.T) {
SeriesFolderFormat: "{Series Title}",
SeasonFolderFormat: "Season {season}",
SpecialsFolderFormat: "Specials",
IncludeSeriesTitle: true,
IncludeEpisodeTitle: false,
IncludeQuality: false,
ReplaceSpaces: true,
Separator: " - ",
NumberStyle: "S{season:00}E{episode:00}",
ColonReplacementFormat: sonarr.ColonDelete,
},
WithError: nil,
},
Expand Down Expand Up @@ -109,12 +99,6 @@ func TestUpdateNaming(t *testing.T) {
SeriesFolderFormat: "{Series Title}",
SeasonFolderFormat: "Season {season}",
SpecialsFolderFormat: "Specials",
IncludeSeriesTitle: true,
IncludeEpisodeTitle: false,
IncludeQuality: false,
ReplaceSpaces: true,
Separator: " - ",
NumberStyle: "S{season:00}E{episode:00}",
},
WithError: nil,
},
Expand Down

0 comments on commit f10d3bf

Please sign in to comment.