Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add new sonarr custom naming format #168

Merged
merged 2 commits into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading