Skip to content
Closed
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
25 changes: 18 additions & 7 deletions sonarr/series.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,22 +144,29 @@
// 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)
return s.GetSeriesContext(ctx, 0, false)
}

// 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 {

Check failure on line 163 in sonarr/series.go

View workflow job for this annotation

GitHub Actions / golangci-lint (freebsd)

missing whitespace above this line (invalid statement above if) (wsl_v5)

Check failure on line 163 in sonarr/series.go

View workflow job for this annotation

GitHub Actions / golangci-lint (linux)

missing whitespace above this line (invalid statement above if) (wsl_v5)
req.Query.Add("includeSeasonImages", "true")
}

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 Expand Up @@ -220,14 +227,18 @@

// 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 @@ -666,12 +666,12 @@
},
}

for _, test := range tests {
for _, test := range tests {

Check failure on line 669 in sonarr/series_test.go

View workflow job for this annotation

GitHub Actions / golangci-lint (freebsd)

File is not properly formatted (gci)

Check failure on line 669 in sonarr/series_test.go

View workflow job for this annotation

GitHub Actions / golangci-lint (linux)

File is not properly formatted (gci)
t.Run(test.Name, func(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