golift.io/starr@v1.0.0/sonarr/naming.go (about) 1 package sonarr 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 Sonarr. 16 type Naming struct { 17 RenameEpisodes bool `json:"renameEpisodes,omitempty"` 18 ReplaceIllegalCharacters bool `json:"replaceIllegalCharacters,omitempty"` 19 IncludeQuality bool `json:"includeQuality,omitempty"` 20 IncludeSeriesTitle bool `json:"includeSeriesTitle,omitempty"` 21 IncludeEpisodeTitle bool `json:"includeEpisodeTitle,omitempty"` 22 ReplaceSpaces bool `json:"replaceSpaces,omitempty"` 23 ID int64 `json:"id,omitempty"` 24 MultiEpisodeStyle int64 `json:"multiEpisodeStyle,omitempty"` 25 Separator string `json:"separator,omitempty"` 26 NumberStyle string `json:"numberStyle,omitempty"` 27 DailyEpisodeFormat string `json:"dailyEpisodeFormat,omitempty"` 28 AnimeEpisodeFormat string `json:"animeEpisodeFormat,omitempty"` 29 SeriesFolderFormat string `json:"seriesFolderFormat,omitempty"` 30 SeasonFolderFormat string `json:"seasonFolderFormat,omitempty"` 31 SpecialsFolderFormat string `json:"specialsFolderFormat,omitempty"` 32 StandardEpisodeFormat string `json:"standardEpisodeFormat,omitempty"` 33 } 34 35 // GetNaming returns the naming. 36 func (s *Sonarr) GetNaming() (*Naming, error) { 37 return s.GetNamingContext(context.Background()) 38 } 39 40 // GetNamingContext returns the naming. 41 func (s *Sonarr) GetNamingContext(ctx context.Context) (*Naming, error) { 42 var output Naming 43 44 req := starr.Request{URI: bpNaming} 45 if err := s.GetInto(ctx, req, &output); err != nil { 46 return nil, fmt.Errorf("api.Get(%s): %w", &req, err) 47 } 48 49 return &output, nil 50 } 51 52 // UpdateNaming updates the naming. 53 func (s *Sonarr) UpdateNaming(naming *Naming) (*Naming, error) { 54 return s.UpdateNamingContext(context.Background(), naming) 55 } 56 57 // UpdateNamingContext updates the naming. 58 func (s *Sonarr) UpdateNamingContext(ctx context.Context, naming *Naming) (*Naming, error) { 59 var output Naming 60 61 var body bytes.Buffer 62 if err := json.NewEncoder(&body).Encode(naming); err != nil { 63 return nil, fmt.Errorf("json.Marshal(%s): %w", bpNaming, err) 64 } 65 66 req := starr.Request{URI: bpNaming, Body: &body} 67 if err := s.PutInto(ctx, req, &output); err != nil { 68 return nil, fmt.Errorf("api.Put(%s): %w", &req, err) 69 } 70 71 return &output, nil 72 }