Skip to content
Open
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
35 changes: 22 additions & 13 deletions sonarr/series.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,10 @@ type AlternateTitle struct {

// Season is part of AddSeriesInput and Queue and used in a few places.
type Season struct {
Monitored bool `json:"monitored"`
SeasonNumber int `json:"seasonNumber"`
Statistics *Statistics `json:"statistics,omitempty"`
Monitored bool `json:"monitored"`
SeasonNumber int `json:"seasonNumber"`
Statistics *Statistics `json:"statistics,omitempty"`
Images []*starr.Image `json:"images,omitempty"`
}

// Statistics is part of AddSeriesInput and Queue.
Expand All @@ -137,30 +138,34 @@ type Statistics struct {

// GetAllSeries returns all configured series.
// This may not deal well with pagination atm, let us know?
func (s *Sonarr) GetAllSeries() ([]*Series, error) {
return s.GetAllSeriesContext(context.Background())
func (s *Sonarr) GetAllSeries(includeSeasonImages bool) ([]*Series, error) {
return s.GetAllSeriesContext(context.Background(), includeSeasonImages)
}

// GetAllSeriesContext returns all configured series.
// This may not deal well with pagination atm, let us know?
func (s *Sonarr) GetAllSeriesContext(ctx context.Context) ([]*Series, error) {
return s.GetSeriesContext(ctx, 0)
func (s *Sonarr) GetAllSeriesContext(ctx context.Context, includeSeasonImages bool) ([]*Series, error) {
return s.GetSeriesContext(ctx, 0, includeSeasonImages)
}

// GetSeries locates and returns a series by tvdbID. If tvdbID is 0, returns all series.
func (s *Sonarr) GetSeries(tvdbID int64) ([]*Series, error) {
return s.GetSeriesContext(context.Background(), tvdbID)
func (s *Sonarr) GetSeries(tvdbID int64, includeSeasonImages bool) ([]*Series, error) {
return s.GetSeriesContext(context.Background(), tvdbID, includeSeasonImages)
}

// GetSeriesContext locates and returns a series by tvdbID. If tvdbID is 0, returns all series.
func (s *Sonarr) GetSeriesContext(ctx context.Context, tvdbID int64) ([]*Series, error) {
func (s *Sonarr) GetSeriesContext(ctx context.Context, tvdbID int64, includeSeasonImages bool) ([]*Series, error) {
var output []*Series

req := starr.Request{URI: bpSeries, Query: make(url.Values)}
if tvdbID != 0 {
req.Query.Add("tvdbId", starr.Str(tvdbID))
}

if includeSeasonImages {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the value of making this optional? Can it always be true?

req.Query.Add("includeSeasonImages", "true")
}

if err := s.GetInto(ctx, req, &output); err != nil {
return nil, fmt.Errorf("api.Get(%s): %w", &req, err)
}
Expand Down Expand Up @@ -220,14 +225,18 @@ func (s *Sonarr) AddSeriesContext(ctx context.Context, series *AddSeriesInput) (

// GetSeriesByID locates and returns a series by DB [series] ID.
func (s *Sonarr) GetSeriesByID(seriesID int64) (*Series, error) {
return s.GetSeriesByIDContext(context.Background(), seriesID)
return s.GetSeriesByIDContext(context.Background(), seriesID, false)
}

// GetSeriesByIDContext locates and returns a series by DB [series] ID.
func (s *Sonarr) GetSeriesByIDContext(ctx context.Context, seriesID int64) (*Series, error) {
func (s *Sonarr) GetSeriesByIDContext(ctx context.Context, seriesID int64, includeSeasonImages bool) (*Series, error) {
var output Series

req := starr.Request{URI: path.Join(bpSeries, starr.Str(seriesID))}
req := starr.Request{URI: path.Join(bpSeries, starr.Str(seriesID)), Query: make(url.Values)}
if includeSeasonImages {
req.Query.Add("includeSeasonImages", "true")
}

if err := s.GetInto(ctx, req, &output); err != nil {
return nil, fmt.Errorf("api.Get(%s): %w", &req, err)
}
Expand Down
4 changes: 2 additions & 2 deletions sonarr/series_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ func TestGetAllSeries(t *testing.T) {
t.Parallel()
mockServer := test.GetMockServer(t)
client := sonarr.New(starr.New("mockAPIkey", mockServer.URL, 0))
output, err := client.GetAllSeries()
output, err := client.GetAllSeries(false)
require.ErrorIs(t, err, test.WithError, "error is not the same as expected")
assert.EqualValues(t, output, test.WithResponse, "response is not the same as expected")
})
Expand Down Expand Up @@ -671,7 +671,7 @@ func TestGetSeries(t *testing.T) {
t.Parallel()
mockServer := test.GetMockServer(t)
client := sonarr.New(starr.New("mockAPIkey", mockServer.URL, 0))
output, err := client.GetSeries(int64(test.WithRequest.(int)))
output, err := client.GetSeries(int64(test.WithRequest.(int)), false)
require.ErrorIs(t, err, test.WithError, "error is not the same as expected")
assert.EqualValues(t, output, test.WithResponse, "response is not the same as expected")
})
Expand Down
Loading