Skip to content

Commit

Permalink
update sonarr commands (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidnewhall committed Nov 6, 2021
1 parent 3837f98 commit 10b320c
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 25 deletions.
10 changes: 5 additions & 5 deletions lidarr/lidarr.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (l *Lidarr) UpdateQualityProfile(profile *QualityProfile) error {
return fmt.Errorf("json.Marshal(profile): %w", err)
}

_, err = l.Put("v1/qualityProfile/"+strconv.FormatInt(profile.ID, starr.Bits10), nil, put)
_, err = l.Put("v1/qualityProfile/"+strconv.FormatInt(profile.ID, starr.Base10), nil, put)
if err != nil {
return fmt.Errorf("api.Put(qualityProfile): %w", err)
}
Expand Down Expand Up @@ -187,7 +187,7 @@ func (l *Lidarr) GetArtist(mbID string) ([]*Artist, error) {
func (l *Lidarr) GetArtistByID(artistID int64) (*Artist, error) {
var artist Artist

err := l.GetInto("v1/artist/"+strconv.FormatInt(artistID, starr.Bits10), nil, &artist)
err := l.GetInto("v1/artist/"+strconv.FormatInt(artistID, starr.Base10), nil, &artist)
if err != nil {
return &artist, fmt.Errorf("api.Get(artist): %w", err)
}
Expand Down Expand Up @@ -227,7 +227,7 @@ func (l *Lidarr) UpdateArtist(artist *Artist) (*Artist, error) {

var output Artist

err = l.PutInto("v1/artist/"+strconv.FormatInt(artist.ID, starr.Bits10), params, body, &output)
err = l.PutInto("v1/artist/"+strconv.FormatInt(artist.ID, starr.Base10), params, body, &output)
if err != nil {
return nil, fmt.Errorf("api.Put(artist): %w", err)
}
Expand Down Expand Up @@ -258,7 +258,7 @@ func (l *Lidarr) GetAlbum(mbID string) ([]*Album, error) {
func (l *Lidarr) GetAlbumByID(albumID int64) (*Album, error) {
var album Album

err := l.GetInto("v1/album/"+strconv.FormatInt(albumID, starr.Bits10), nil, &album)
err := l.GetInto("v1/album/"+strconv.FormatInt(albumID, starr.Base10), nil, &album)
if err != nil {
return nil, fmt.Errorf("api.Get(album): %w", err)
}
Expand All @@ -278,7 +278,7 @@ func (l *Lidarr) UpdateAlbum(albumID int64, album *Album) (*Album, error) {

var output Album

err = l.PutInto("v1/album/"+strconv.FormatInt(albumID, starr.Bits10), params, put, &output)
err = l.PutInto("v1/album/"+strconv.FormatInt(albumID, starr.Base10), params, put, &output)
if err != nil {
return nil, fmt.Errorf("api.Put(album): %w", err)
}
Expand Down
14 changes: 7 additions & 7 deletions radarr/radarr.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func (r *Radarr) GetQueue(maxRecords, page int) (*Queue, error) {
func (r *Radarr) GetMovie(tmdbID int64) ([]*Movie, error) {
params := make(url.Values)
if tmdbID != 0 {
params.Set("tmdbId", strconv.FormatInt(tmdbID, starr.Bits10))
params.Set("tmdbId", strconv.FormatInt(tmdbID, starr.Base10))
}

var movie []*Movie
Expand All @@ -139,7 +139,7 @@ func (r *Radarr) GetMovie(tmdbID int64) ([]*Movie, error) {
func (r *Radarr) GetMovieByID(movieID int64) (*Movie, error) {
var movie Movie

err := r.GetInto("v3/movie/"+strconv.FormatInt(movieID, starr.Bits10), nil, &movie)
err := r.GetInto("v3/movie/"+strconv.FormatInt(movieID, starr.Base10), nil, &movie)
if err != nil {
return nil, fmt.Errorf("api.Get(movie): %w", err)
}
Expand Down Expand Up @@ -183,7 +183,7 @@ func (r *Radarr) UpdateQualityProfile(profile *QualityProfile) error {
return fmt.Errorf("json.Marshal(profile): %w", err)
}

_, err = r.Put("v3/qualityProfile/"+strconv.FormatInt(profile.ID, starr.Bits10), nil, put)
_, err = r.Put("v3/qualityProfile/"+strconv.FormatInt(profile.ID, starr.Base10), nil, put)
if err != nil {
return fmt.Errorf("api.Put(qualityProfile): %w", err)
}
Expand Down Expand Up @@ -213,7 +213,7 @@ func (r *Radarr) UpdateMovie(movieID int64, movie *Movie) error {
params := make(url.Values)
params.Add("moveFiles", "true")

_, err = r.Put("v3/movie/"+strconv.FormatInt(movieID, starr.Bits10), params, put)
_, err = r.Put("v3/movie/"+strconv.FormatInt(movieID, starr.Base10), params, put)
if err != nil {
return fmt.Errorf("api.Put(movie): %w", err)
}
Expand Down Expand Up @@ -259,7 +259,7 @@ func (r *Radarr) DeleteExclusions(ids []int64) error {
var errs string

for _, id := range ids {
_, err := r.Delete("v3/exclusions/"+strconv.FormatInt(id, starr.Bits10), nil)
_, err := r.Delete("v3/exclusions/"+strconv.FormatInt(id, starr.Base10), nil)
if err != nil {
errs += err.Error() + " "
}
Expand Down Expand Up @@ -373,7 +373,7 @@ func (r *Radarr) DeleteImportList(ids []int64) error {
var errs string

for _, id := range ids {
_, err := r.Delete("v3/importlist/"+strconv.FormatInt(id, starr.Bits10), nil)
_, err := r.Delete("v3/importlist/"+strconv.FormatInt(id, starr.Base10), nil)
if err != nil {
errs += fmt.Errorf("api.Delete(importlist): %w", err).Error() + " "
}
Expand All @@ -394,7 +394,7 @@ func (r *Radarr) UpdateImportList(il *ImportList) (*ImportList, error) {
}

var output ImportList
if err := r.PutInto("v3/importlist/"+strconv.FormatInt(il.ID, starr.Bits10), nil, body, &output); err != nil {
if err := r.PutInto("v3/importlist/"+strconv.FormatInt(il.ID, starr.Base10), nil, body, &output); err != nil {
return nil, fmt.Errorf("api.Put(importlist): %w", err)
}

Expand Down
10 changes: 5 additions & 5 deletions readarr/readarr.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func (r *Readarr) UpdateQualityProfile(profile *QualityProfile) error {
return fmt.Errorf("json.Marshal(profile): %w", err)
}

_, err = r.Put("v1/qualityProfile/"+strconv.FormatInt(profile.ID, starr.Bits10), nil, put)
_, err = r.Put("v1/qualityProfile/"+strconv.FormatInt(profile.ID, starr.Base10), nil, put)
if err != nil {
return fmt.Errorf("api.Put(qualityProfile): %w", err)
}
Expand All @@ -156,7 +156,7 @@ func (r *Readarr) UpdateQualityProfile(profile *QualityProfile) error {
func (r *Readarr) GetAuthorByID(authorID int64) (*Author, error) {
var author Author

err := r.GetInto("v1/author/"+strconv.FormatInt(authorID, starr.Bits10), nil, &author)
err := r.GetInto("v1/author/"+strconv.FormatInt(authorID, starr.Base10), nil, &author)
if err != nil {
return nil, fmt.Errorf("api.Get(author): %w", err)
}
Expand All @@ -174,7 +174,7 @@ func (r *Readarr) UpdateAuthor(authorID int64, author *Author) error {
params := make(url.Values)
params.Add("moveFiles", "true")

b, err := r.Put("v1/author/"+strconv.FormatInt(authorID, starr.Bits10), params, put)
b, err := r.Put("v1/author/"+strconv.FormatInt(authorID, starr.Base10), params, put)
if err != nil {
return fmt.Errorf("api.Put(author): %w", err)
}
Expand Down Expand Up @@ -206,7 +206,7 @@ func (r *Readarr) GetBook(gridID string) ([]*Book, error) {
func (r *Readarr) GetBookByID(bookID int64) (*Book, error) {
var book Book

err := r.GetInto("v1/book/"+strconv.FormatInt(bookID, starr.Bits10), nil, &book)
err := r.GetInto("v1/book/"+strconv.FormatInt(bookID, starr.Base10), nil, &book)
if err != nil {
return nil, fmt.Errorf("api.Get(book): %w", err)
}
Expand All @@ -224,7 +224,7 @@ func (r *Readarr) UpdateBook(bookID int64, book *Book) error {
params := make(url.Values)
params.Add("moveFiles", "true")

b, err := r.Put("v1/book/"+strconv.FormatInt(bookID, starr.Bits10), params, put)
b, err := r.Put("v1/book/"+strconv.FormatInt(bookID, starr.Base10), params, put)
if err != nil {
return fmt.Errorf("api.Put(book): %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const (

// Silly constants to not screw up integer->string conversions.
const (
Bits10 = 10
Base10 = 10
)

// String turns an App name into a string.
Expand Down
30 changes: 23 additions & 7 deletions sonarr/sonarr.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func (s *Sonarr) UpdateQualityProfile(profile *QualityProfile) error {
return fmt.Errorf("json.Marshal(profile): %w", err)
}

_, err = s.Put("v3/qualityProfile/"+strconv.FormatInt(profile.ID, starr.Bits10), nil, put)
_, err = s.Put("v3/qualityProfile/"+strconv.FormatInt(profile.ID, starr.Base10), nil, put)
if err != nil {
return fmt.Errorf("api.Put(qualityProfile): %w", err)
}
Expand Down Expand Up @@ -183,7 +183,7 @@ func (s *Sonarr) UpdateReleaseProfile(profile *ReleaseProfile) error {
return fmt.Errorf("json.Marshal(profile): %w", err)
}

_, err = s.Put("v3/releaseProfile/"+strconv.FormatInt(profile.ID, starr.Bits10), nil, put)
_, err = s.Put("v3/releaseProfile/"+strconv.FormatInt(profile.ID, starr.Base10), nil, put)
if err != nil {
return fmt.Errorf("api.Put(releaseProfile): %w", err)
}
Expand All @@ -209,7 +209,7 @@ func (s *Sonarr) GetSeriesLookup(term string, tvdbID int64) ([]*SeriesLookup, er
params := make(url.Values)

if tvdbID > 0 {
params.Add("term", "tvdbid:"+strconv.FormatInt(tvdbID, starr.Bits10))
params.Add("term", "tvdbid:"+strconv.FormatInt(tvdbID, starr.Base10))
} else {
params.Add("term", term)
}
Expand All @@ -229,7 +229,7 @@ func (s *Sonarr) GetSeries(tvdbID int64) ([]*Series, error) {
params := make(url.Values)

if tvdbID != 0 {
params.Add("tvdbId", strconv.FormatInt(tvdbID, starr.Bits10))
params.Add("tvdbId", strconv.FormatInt(tvdbID, starr.Base10))
}

var series []*Series
Expand All @@ -246,7 +246,7 @@ func (s *Sonarr) GetSeries(tvdbID int64) ([]*Series, error) {
func (s *Sonarr) GetSeriesByID(seriesID int64) (*Series, error) {
var series Series

err := s.GetInto("v3/series/"+strconv.FormatInt(seriesID, starr.Bits10), nil, &series)
err := s.GetInto("v3/series/"+strconv.FormatInt(seriesID, starr.Base10), nil, &series)
if err != nil {
return nil, fmt.Errorf("api.Get(series): %w", err)
}
Expand All @@ -270,7 +270,7 @@ func (s *Sonarr) UpdateSeries(seriesID int64, series *Series) error {
params := make(url.Values)
params.Add("moveFiles", "true")

b, err := s.Put("v3/series/"+strconv.FormatInt(seriesID, starr.Bits10), params, put)
b, err := s.Put("v3/series/"+strconv.FormatInt(seriesID, starr.Base10), params, put)
if err != nil {
return fmt.Errorf("api.Put(series): %w", err)
}
Expand Down Expand Up @@ -330,13 +330,29 @@ func (s *Sonarr) SendCommand(cmd *CommandRequest) (*CommandResponse, error) {
return &output, nil
}

// GetCommandStatus returns the status of an already started command.
func (s *Sonarr) GetCommandStatus(commandID int64) (*CommandResponse, error) {
if commandID == 0 {
return nil, nil
}

var output CommandResponse

err := s.GetInto("v3/command/"+strconv.FormatInt(commandID, starr.Base10), nil, &output)
if err != nil {
return nil, fmt.Errorf("api.Post(command): %w", err)
}

return &output, nil
}

// GetSeriesEpisodes returns all episodes for a series by series ID.
// You can get series IDs from GetAllSeries() and GetSeries().
func (s *Sonarr) GetSeriesEpisodes(seriesID int64) ([]*Episode, error) {
var output []*Episode

params := make(url.Values)
params.Add("seriesId", strconv.FormatInt(seriesID, starr.Bits10))
params.Add("seriesId", strconv.FormatInt(seriesID, starr.Base10))

err := s.GetInto("v3/episode?seriesId", params, &output)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions sonarr/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ type AlternateTitle struct {
// This was created from the search command and may not support other commands yet.
type CommandRequest struct {
Name string `json:"name"`
Files []int64 `json:"files,omitempty"` // RenameFiles only
SeriesIDs []int64 `json:"seriesIds,omitempty"`
SeriesID int64 `json:"seriesId,omitempty"`
}
Expand Down

0 comments on commit 10b320c

Please sign in to comment.