Skip to content

Commit

Permalink
add new sonarr custom naming format (#168)
Browse files Browse the repository at this point in the history
* add new sonarr custom naming format

* fix naming test
  • Loading branch information
davidnewhall authored Aug 8, 2024
1 parent 441249a commit 9ab5f90
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 19 deletions.
24 changes: 13 additions & 11 deletions sonarr/naming.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,23 @@ const (
ColonReplaceWithSpaceDash
ColonReplaceWithSpaceDashSpace
ColonSmartReplace
Custom
)

// Naming represents the config/naming endpoint in Sonarr.
type Naming struct {
RenameEpisodes bool `json:"renameEpisodes,omitempty"`
ReplaceIllegalCharacters bool `json:"replaceIllegalCharacters,omitempty"`
ColonReplacementFormat CRF `json:"colonReplacementFormat,omitempty"`
ID int64 `json:"id,omitempty"`
MultiEpisodeStyle int64 `json:"multiEpisodeStyle,omitempty"`
DailyEpisodeFormat string `json:"dailyEpisodeFormat,omitempty"`
AnimeEpisodeFormat string `json:"animeEpisodeFormat,omitempty"`
SeriesFolderFormat string `json:"seriesFolderFormat,omitempty"`
SeasonFolderFormat string `json:"seasonFolderFormat,omitempty"`
SpecialsFolderFormat string `json:"specialsFolderFormat,omitempty"`
StandardEpisodeFormat string `json:"standardEpisodeFormat,omitempty"`
RenameEpisodes bool `json:"renameEpisodes"`
ReplaceIllegalCharacters bool `json:"replaceIllegalCharacters"`
ColonReplacementFormat CRF `json:"colonReplacementFormat"`
ID int64 `json:"id"`
MultiEpisodeStyle int64 `json:"multiEpisodeStyle"`
DailyEpisodeFormat string `json:"dailyEpisodeFormat"`
AnimeEpisodeFormat string `json:"animeEpisodeFormat"`
SeriesFolderFormat string `json:"seriesFolderFormat"`
SeasonFolderFormat string `json:"seasonFolderFormat"`
SpecialsFolderFormat string `json:"specialsFolderFormat"`
StandardEpisodeFormat string `json:"standardEpisodeFormat"`
CustomColonReplacementFormat string `json:"customColonReplacementFormat"`
}

// GetNaming returns the naming.
Expand Down
33 changes: 25 additions & 8 deletions sonarr/naming_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const namingBody = `{
"seriesFolderFormat": "{Series Title}",
"seasonFolderFormat": "Season {season}",
"specialsFolderFormat": "Specials",
"customcolonReplacementFormat": "",
"id": 1
}`

Expand Down Expand Up @@ -85,10 +86,23 @@ func TestUpdateNaming(t *testing.T) {
ExpectedMethod: "PUT",
ResponseStatus: 202,
WithRequest: &sonarr.Naming{
ReplaceIllegalCharacters: true,
RenameEpisodes: true,
ReplaceIllegalCharacters: true,
ColonReplacementFormat: 5,
ID: 4,
MultiEpisodeStyle: 2,
DailyEpisodeFormat: "a",
AnimeEpisodeFormat: "b",
SeriesFolderFormat: "c",
SeasonFolderFormat: "d",
SpecialsFolderFormat: "e",
StandardEpisodeFormat: "f",
CustomColonReplacementFormat: "g",
},
ExpectedRequest: `{"replaceIllegalCharacters":true,"id":1}` + "\n",
ResponseBody: namingBody,
ExpectedRequest: `{"renameEpisodes":true,"replaceIllegalCharacters":true,"colonReplacementFormat":5,` +
`"id":1,"multiEpisodeStyle":2,"dailyEpisodeFormat":"a","animeEpisodeFormat":"b","seriesFolderFormat":"c",` +
`"seasonFolderFormat":"d","specialsFolderFormat":"e","standardEpisodeFormat":"f","customColonReplacementFormat":"g"}` + "\n",
ResponseBody: namingBody,
WithResponse: &sonarr.Naming{
ID: 1,
RenameEpisodes: false,
Expand All @@ -103,18 +117,21 @@ func TestUpdateNaming(t *testing.T) {
},
WithError: nil,
},

{
Name: "404",
ExpectedPath: path.Join("/", starr.API, sonarr.APIver, "config", "naming"),
ExpectedMethod: "PUT",
WithRequest: &sonarr.Naming{
ReplaceIllegalCharacters: true,
},
ExpectedRequest: `{"replaceIllegalCharacters":true,"id":1}` + "\n",
ResponseStatus: 404,
ResponseBody: `{"message": "NotFound"}`,
WithError: &starr.ReqError{Code: http.StatusNotFound},
WithResponse: (*sonarr.Naming)(nil),
ExpectedRequest: `{"renameEpisodes":false,"replaceIllegalCharacters":true,"colonReplacementFormat":0,` +
`"id":1,"multiEpisodeStyle":0,"dailyEpisodeFormat":"","animeEpisodeFormat":"","seriesFolderFormat":"",` +
`"seasonFolderFormat":"","specialsFolderFormat":"","standardEpisodeFormat":"","customColonReplacementFormat":""}` + "\n",
ResponseStatus: 404,
ResponseBody: `{"message": "NotFound"}`,
WithError: &starr.ReqError{Code: http.StatusNotFound},
WithResponse: (*sonarr.Naming)(nil),
},
}

Expand Down

0 comments on commit 9ab5f90

Please sign in to comment.