Skip to content

Commit

Permalink
Merge pull request #4 from golift/dn2_new_endpoints
Browse files Browse the repository at this point in the history
New methods for quality profiles and Sonarr release profiles.
  • Loading branch information
davidnewhall authored May 18, 2021
2 parents a5e5dc3 + db987e4 commit 4d6c2d4
Show file tree
Hide file tree
Showing 9 changed files with 229 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ language: go
go:
- 1.16.x
install:
- curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(go env GOPATH)/bin latest
- curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(go env GOPATH)/bin v1.38.0
script:
- make test
9 changes: 5 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ test: lint nopollution
GOOS=freebsd GOARCH=386 go build .

lint:
GOOS=linux golangci-lint run --enable-all
GOOS=darwin golangci-lint run --enable-all
GOOS=windows golangci-lint run --enable-all
GOOS=freebsd golangci-lint run --enable-all
# Test lint on four platforms.
GOOS=linux golangci-lint run --enable-all -D maligned,scopelint,interfacer
GOOS=darwin golangci-lint run --enable-all -D maligned,scopelint,interfacer
GOOS=windows golangci-lint run --enable-all -D maligned,scopelint,interfacer
GOOS=freebsd golangci-lint run --enable-all -D maligned,scopelint,interfacer

nopollution:
# Avoid cross pollution.
Expand Down
32 changes: 32 additions & 0 deletions lidarr/lidarr.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,38 @@ func (l *Lidarr) GetQualityProfiles() ([]*QualityProfile, error) {
return profiles, nil
}

// AddQualityProfile updates a quality profile in place.
func (l *Lidarr) AddQualityProfile(profile *QualityProfile) (int64, error) {
post, err := json.Marshal(profile)
if err != nil {
return 0, fmt.Errorf("json.Marshal(profile): %w", err)
}

var output QualityProfile

err = l.PostInto("v1/qualityProfile", nil, post, &output)
if err != nil {
return 0, fmt.Errorf("api.Post(qualityProfile): %w", err)
}

return output.ID, nil
}

// UpdateQualityProfile updates a quality profile in place.
func (l *Lidarr) UpdateQualityProfile(profile *QualityProfile) error {
put, err := json.Marshal(profile)
if err != nil {
return fmt.Errorf("json.Marshal(profile): %w", err)
}

_, err = l.Put("v1/qualityProfile/"+strconv.FormatInt(profile.ID, 10), nil, put)
if err != nil {
return fmt.Errorf("api.Put(qualityProfile): %w", err)
}

return nil
}

// GetRootFolders returns all configured root folders.
func (l *Lidarr) GetRootFolders() ([]*RootFolder, error) {
var folders []*RootFolder
Expand Down
32 changes: 32 additions & 0 deletions radarr/radarr.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,38 @@ func (r *Radarr) GetQualityProfiles() ([]*QualityProfile, error) {
return profiles, nil
}

// AddQualityProfile updates a quality profile in place.
func (r *Radarr) AddQualityProfile(profile *QualityProfile) (int64, error) {
post, err := json.Marshal(profile)
if err != nil {
return 0, fmt.Errorf("json.Marshal(profile): %w", err)
}

var output QualityProfile

err = r.PostInto("v3/qualityProfile", nil, post, &output)
if err != nil {
return 0, fmt.Errorf("api.Post(qualityProfile): %w", err)
}

return output.ID, nil
}

// UpdateQualityProfile updates a quality profile in place.
func (r *Radarr) UpdateQualityProfile(profile *QualityProfile) error {
put, err := json.Marshal(profile)
if err != nil {
return fmt.Errorf("json.Marshal(profile): %w", err)
}

_, err = r.Put("v3/qualityProfile/"+strconv.FormatInt(profile.ID, 10), nil, put)
if err != nil {
return fmt.Errorf("api.Put(qualityProfile): %w", err)
}

return nil
}

// GetRootFolders returns all configured root folders.
func (r *Radarr) GetRootFolders() ([]*RootFolder, error) {
var folders []*RootFolder
Expand Down
9 changes: 8 additions & 1 deletion radarr/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,10 +360,17 @@ type QualityProfile struct {
Qualities []*starr.Quality `json:"items"`
MinFormatScore int64 `json:"minFormatScore"`
CutoffFormatScore int64 `json:"cutoffFormatScore"`
FormatItems []interface{} `json:"formatItems"`
FormatItems []*FormatItem `json:"formatItems,omitempty"`
Language *starr.Value `json:"language"`
}

// FormatItem is part of a QualityProfile.
type FormatItem struct {
Format int `json:"format"`
Name string `json:"name"`
Score int `json:"score"`
}

type Exclusion struct {
TMDBID int64 `json:"tmdbId"`
Title string `json:"movieTitle"`
Expand Down
32 changes: 32 additions & 0 deletions readarr/readarr.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,38 @@ func (r *Readarr) GetQualityProfiles() ([]*QualityProfile, error) {
return profiles, nil
}

// AddQualityProfile updates a quality profile in place.
func (r *Readarr) AddQualityProfile(profile *QualityProfile) (int64, error) {
post, err := json.Marshal(profile)
if err != nil {
return 0, fmt.Errorf("json.Marshal(profile): %w", err)
}

var output QualityProfile

err = r.PostInto("v1/qualityProfile", nil, post, &output)
if err != nil {
return 0, fmt.Errorf("api.Post(qualityProfile): %w", err)
}

return output.ID, nil
}

// UpdateQualityProfile updates a quality profile in place.
func (r *Readarr) UpdateQualityProfile(profile *QualityProfile) error {
put, err := json.Marshal(profile)
if err != nil {
return fmt.Errorf("json.Marshal(profile): %w", err)
}

_, err = r.Put("v1/qualityProfile/"+strconv.FormatInt(profile.ID, 10), nil, put)
if err != nil {
return fmt.Errorf("api.Put(qualityProfile): %w", err)
}

return nil
}

// GetAuthorByID returns an author.
func (r *Readarr) GetAuthorByID(authorID int64) (*Author, error) {
var author Author
Expand Down
44 changes: 31 additions & 13 deletions shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,32 @@ type StatusMessage struct {
Messages []string `json:"messages"`
}

// Quality is a download quality attached to a movie, book, track or series.
// BaseQuality is a base quality profile.
type BaseQuality struct {
ID int64 `json:"id"`
Name string `json:"name"`
Source string `json:"source,omitempty"`
Resolution int `json:"resolution,omitempty"`
Modifier string `json:"modifier,omitempty"`
}

// Quality is a download quality profile attached to a movie, book, track or series.
// It may contain 1 or more profiles.
// Readarr does not use Name or ID in this struct.
type Quality struct {
Quality struct {
ID int64 `json:"id"`
Name string `json:"name"`
Source string `json:"source,omitempty"`
Resolution int `json:"resolution,omitempty"`
Modifier string `json:"modifier,omitempty"`
} `json:"quality"`
Revision struct {
Version int64 `json:"version"`
Real int64 `json:"real"`
IsRepack bool `json:"isRepack,omitempty"`
} `json:"revision,omitempty"`
Name string `json:"name,omitempty"`
ID int `json:"id,omitempty"`
Quality *BaseQuality `json:"quality,omitempty"`
Items []*Quality `json:"items"`
Allowed bool `json:"allowed"`
Revision *QualityRevision `json:"revision,omitempty"` // Not sure which app had this....
}

// QualityRevision is probably used in Sonarr.
type QualityRevision struct {
Version int64 `json:"version"`
Real int64 `json:"real"`
IsRepack bool `json:"isRepack,omitempty"`
}

// Ratings belong to a few types.
Expand Down Expand Up @@ -67,3 +79,9 @@ type Value struct {
ID int64 `json:"id"`
Name string `json:"name"`
}

// KeyValue is yet another reusable generic type.
type KeyValue struct {
Key string `json:"key"`
Value int `json:"value"`
}
76 changes: 76 additions & 0 deletions sonarr/sonarr.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,82 @@ func (s *Sonarr) GetQualityProfiles() ([]*QualityProfile, error) {
return profiles, nil
}

// AddQualityProfile updates a quality profile in place.
func (s *Sonarr) AddQualityProfile(profile *QualityProfile) (int64, error) {
post, err := json.Marshal(profile)
if err != nil {
return 0, fmt.Errorf("json.Marshal(profile): %w", err)
}

var output QualityProfile

err = s.PostInto("v3/qualityProfile", nil, post, &output)
if err != nil {
return 0, fmt.Errorf("api.Post(qualityProfile): %w", err)
}

return output.ID, nil
}

// UpdateQualityProfile updates a quality profile in place.
func (s *Sonarr) UpdateQualityProfile(profile *QualityProfile) error {
put, err := json.Marshal(profile)
if err != nil {
return fmt.Errorf("json.Marshal(profile): %w", err)
}

_, err = s.Put("v3/qualityProfile/"+strconv.FormatInt(profile.ID, 10), nil, put)
if err != nil {
return fmt.Errorf("api.Put(qualityProfile): %w", err)
}

return nil
}

// GetReleaseProfiles returns all configured release profiles.
func (s *Sonarr) GetReleaseProfiles() ([]*ReleaseProfile, error) {
var profiles []*ReleaseProfile

err := s.GetInto("v3/releaseProfile", nil, &profiles)
if err != nil {
return nil, fmt.Errorf("api.Get(releaseProfile): %w", err)
}

return profiles, nil
}

// AddReleaseProfile updates a release profile in place.
func (s *Sonarr) AddReleaseProfile(profile *ReleaseProfile) (int64, error) {
post, err := json.Marshal(profile)
if err != nil {
return 0, fmt.Errorf("json.Marshal(profile): %w", err)
}

var output ReleaseProfile

err = s.PostInto("v3/releaseProfile", nil, post, &output)
if err != nil {
return 0, fmt.Errorf("api.Post(releaseProfile): %w", err)
}

return output.ID, nil
}

// UpdateReleaseProfile updates a release profile in place.
func (s *Sonarr) UpdateReleaseProfile(profile *ReleaseProfile) error {
put, err := json.Marshal(profile)
if err != nil {
return fmt.Errorf("json.Marshal(profile): %w", err)
}

_, err = s.Put("v3/releaseProfile/"+strconv.FormatInt(profile.ID, 10), nil, put)
if err != nil {
return fmt.Errorf("api.Put(releaseProfile): %w", err)
}

return nil
}

// GetRootFolders returns all configured root folders.
func (s *Sonarr) GetRootFolders() ([]*RootFolder, error) {
var folders []*RootFolder
Expand Down
12 changes: 12 additions & 0 deletions sonarr/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,18 @@ type QualityProfile struct {
UpgradeAllowed bool `json:"upgradeAllowed"`
}

type ReleaseProfile struct {
Name string `json:"name"`
Required string `json:"required"`
Ignored string `json:"ignored"`
Preferred []*starr.KeyValue `json:"preferred"`
IncPrefOnRename bool `json:"includePreferredWhenRenaming"`
IndexerID int64 `json:"indexerId"`
Tags []*starr.Tag `json:"tags"`
ID int64 `json:"id"`
Enabled bool `json:"enabled"`
}

// SystemStatus is the /api/v3/system/status endpoint.
type SystemStatus struct {
Version string `json:"version"`
Expand Down

0 comments on commit 4d6c2d4

Please sign in to comment.