-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add movie editor endpoints #69
Changes from 4 commits
0ab5fd5
9735b7c
dedd989
574338e
e14d1f8
cc0cd9a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package starr | ||
|
||
// String returns a pointer to a string. | ||
func String(s string) *string { | ||
return &s | ||
} | ||
|
||
// True returns a pointer to a true boolean. | ||
func True() *bool { | ||
s := true | ||
return &s | ||
} | ||
|
||
// False returns a pointer to a false boolean. | ||
func False() *bool { | ||
s := false | ||
return &s | ||
} | ||
|
||
// Int64 returns a pointer to the provided integer. | ||
func Int64(s int64) *int64 { | ||
return &s | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package radarr | ||
|
||
import ( | ||
"bytes" | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
|
||
"golift.io/starr" | ||
) | ||
|
||
const bpMovieEditor = bpMovie + "/editor" | ||
|
||
// BulkEdit is the input for the bulk movie editor endpoint. | ||
// You may use starr.True(), starr.False(), starr.Int64(), and starr.String() to add data to the struct members. | ||
type BulkEdit struct { | ||
MovieIDs []int64 `json:"movieIds"` | ||
Monitored *bool `json:"monitored,omitempty"` | ||
QualityProfileID *int64 `json:"qualityProfileId,omitempty"` | ||
MinimumAvailability *string `json:"minimumAvailability,omitempty"` // tba | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. tba, announced, inCinemas, released, deleted ref https://radarr.video/docs/api/#/MovieEditor/put_api_v3_movie_editor |
||
RootFolderPath *string `json:"rootFolderPath,omitempty"` // path | ||
Tags []int `json:"tags,omitempty"` // [0] | ||
ApplyTags *string `json:"applyTags,omitempty"` // add | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add, remove, replace ref https://radarr.video/docs/api/#/MovieEditor/put_api_v3_movie_editor |
||
MoveFiles *bool `json:"moveFiles,omitempty"` | ||
DeleteFiles *bool `json:"deleteFiles,omitempty"` // delete only | ||
AddImportExclusion *bool `json:"addImportExclusion,omitempty"` // delete only | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. are they pointer to let them leverage the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These members are purposely pointers, because the default value is different than the "missing" value. This is a bulk-change endpoint. When you pick There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. got it, thanks for the example |
||
} | ||
|
||
// EditMovies allows bulk diting many movies at once. | ||
func (r *Radarr) EditMovies(editMovies *BulkEdit) ([]*Movie, error) { | ||
return r.EditMoviesContext(context.Background(), editMovies) | ||
} | ||
|
||
// EditMoviesContext allows bulk diting many movies at once. | ||
func (r *Radarr) EditMoviesContext(ctx context.Context, editMovies *BulkEdit) ([]*Movie, error) { | ||
var body bytes.Buffer | ||
if err := json.NewEncoder(&body).Encode(editMovies); err != nil { | ||
return nil, fmt.Errorf("json.Marshal(%s): %w", bpMovieEditor, err) | ||
} | ||
|
||
var output []*Movie | ||
|
||
req := starr.Request{URI: bpMovieEditor, Body: &body} | ||
if err := r.PutInto(ctx, req, &output); err != nil { | ||
return nil, fmt.Errorf("api.Put(%s): %w", &req, err) | ||
} | ||
|
||
return output, nil | ||
} | ||
|
||
// DeleteMovies bulk deletes movies. Can also mark them as excluded, and delete their files. | ||
func (r *Radarr) DeleteMovies(deleteMovies *BulkEdit) error { | ||
return r.DeleteMoviesContext(context.Background(), deleteMovies) | ||
} | ||
|
||
// DeleteDeleteMoviesContextMovies bulk deletes movies. Can also mark them as excluded, and delete their files. | ||
func (r *Radarr) DeleteMoviesContext(ctx context.Context, deleteMovies *BulkEdit) error { | ||
var body bytes.Buffer | ||
if err := json.NewEncoder(&body).Encode(deleteMovies); err != nil { | ||
return fmt.Errorf("json.Marshal(%s): %w", bpMovieEditor, err) | ||
} | ||
|
||
req := starr.Request{URI: bpMovieEditor, Body: &body} | ||
if err := r.DeleteAny(ctx, req); err != nil { | ||
return fmt.Errorf("api.Delete(%s): %w", &req, err) | ||
} | ||
|
||
return nil | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package radarr_test | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @davidnewhall this really rock! thanks 🚀 |
||
|
||
import ( | ||
"net/http" | ||
"path" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"golift.io/starr" | ||
"golift.io/starr/radarr" | ||
) | ||
|
||
func TestEditMovies(t *testing.T) { | ||
t.Parallel() | ||
|
||
tests := []*starr.TestMockData{ | ||
{ | ||
Name: "200", | ||
ExpectedPath: path.Join("/", starr.API, radarr.APIver, "movie", "editor"), | ||
ResponseStatus: http.StatusOK, | ||
ResponseBody: `[{"id": 7, "monitored": true},{"id": 3, "monitored": true}]`, | ||
WithError: nil, | ||
WithRequest: &radarr.BulkEdit{ | ||
MovieIDs: []int64{7, 3}, | ||
Monitored: starr.True(), | ||
DeleteFiles: starr.False(), | ||
}, | ||
ExpectedRequest: `{"movieIds":[7,3],"monitored":true,"deleteFiles":false}` + "\n", | ||
ExpectedMethod: http.MethodPut, | ||
WithResponse: []*radarr.Movie{{ID: 7, Monitored: true}, {ID: 3, Monitored: true}}, | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
test := test | ||
t.Run(test.Name, func(t *testing.T) { | ||
t.Parallel() | ||
mockServer := test.GetMockServer(t) | ||
client := radarr.New(starr.New("mockAPIkey", mockServer.URL, 0)) | ||
output, err := client.EditMovies(test.WithRequest.(*radarr.BulkEdit)) | ||
assert.ErrorIs(t, err, test.WithError, "error is not the same as expected") | ||
assert.EqualValues(t, test.WithResponse, output, "response is not the same as expected") | ||
}) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,7 +40,7 @@ func (test *TestMockData) GetMockServer(t *testing.T) *httptest.Server { | |
assert.EqualValues(t, test.ExpectedPath, req.URL.String()) | ||
writer.WriteHeader(test.ResponseStatus) | ||
|
||
assert.EqualValues(t, req.Method, test.ExpectedMethod) | ||
assert.EqualValues(t, test.ExpectedMethod, req.Method) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was backward. |
||
|
||
body, err := io.ReadAll(req.Body) | ||
assert.NoError(t, err) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These may be useful down the road too.