Skip to content
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

Merged
merged 6 commits into from
Oct 7, 2022
Merged

Add movie editor endpoints #69

merged 6 commits into from
Oct 7, 2022

Conversation

davidnewhall
Copy link
Contributor

@davidnewhall davidnewhall commented Oct 5, 2022

Adds movie editor endpoint.
Adds movie delete and bulk delete endpoints.
Closes #68. @NCRoxas, can you test this?

edit := &radarr.BulkEdit{
    MovieIDs:    []int64{7, 3},
    Monitored:   starr.True(),
    DeleteFiles: starr.False(),
}
movies, err := r.EditMovies(edit)

@davidnewhall davidnewhall requested a review from Fuochi October 5, 2022 20:13
@@ -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)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was backward.

@@ -0,0 +1,23 @@
package starr
Copy link
Contributor Author

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.

@d34dscene
Copy link

Looks great! Unmonitoring works, but DeleteFiles and AddImportExclusion doesn't work on my end.

@davidnewhall
Copy link
Contributor Author

davidnewhall commented Oct 5, 2022

Did you mean DeleteMovie or DeleteMovies?

We'll have to address AddImportExclusion in another conversation. edit: oh, derp, you mean AddImportExclusion as part of the input. I see it now. Can you share your code?

@davidnewhall
Copy link
Contributor Author

AddImportExclusion is documented here: https://radarr.video/docs/api/#/MovieEditor/delete_api_v3_movie_editor
...but I don't see any way to trigger it in the UI, so it may not actual work? Can you get an example payload where this works?

@d34dscene
Copy link

d34dscene commented Oct 5, 2022

I meant DeleteFiles in this code block

edit := &radarr.EditMovies{
  MovieIDs:    []int64{1, 2, 3},
  Monitored:   starr.True(),
  DeleteFiles: starr.True(),
}

So it bulk deletes all movies and their files.

For the AddImportExclusion I created a simple request:

request, _ := json.Marshal(map[string]any{
  "movieIds": []int64{1, 2, 3},
  "monitored": false,
  "deleteFiles": true,
  "addImportExclusion": true,
})

and sent it via:

req, err := http.NewRequest("DELETE", url, bytes.NewBuffer(request))
// error handling
req.Header.Set("Content-Type", "application/json")
client := &http.Client{}
_, err := client.Do(req);
// error handling

url is xxx/api/v3/movie/editor?apikey=xxx

@davidnewhall
Copy link
Contributor Author

I suspect those things do not actually work in radarr. Do you know how to do these actions in the UI? So I can reproduce and see what the difference is.

@d34dscene
Copy link

You can bulk delete movies in the UI by going to "Movies" > clicking on the "Movie Editor" button > selecting multiple movies and clicking on Delete on the bottom right.
image
But I don't think you can add movies to the exclusion list via the UI. That's only possible with an api call. The request I sent in the previous message actually works and it deletes all the movie files in the movieID list and puts the movies under "Settings" > "Lists" > "List Exclusions" in the UI.

@davidnewhall
Copy link
Contributor Author

oh, I see what the problem is.

@davidnewhall
Copy link
Contributor Author

Okay, I gave delete the same inputs as edit, so you can pass in those fields. Good to know how it works, thanks! I also renamed the struct to BulkEdit. Try this:

r.DeleteMovies(&radarr.BulkEdit{
  MovieIDs:           []int64{1, 2, 3},
  DeleteFiles:        starr.True(),
  Monitored:          starr.False(),
  AddImportExclusion: starr.True(),
})

@d34dscene
Copy link

Awesome it works now :D

Copy link
Contributor

@Fuochi Fuochi left a comment

Choose a reason for hiding this comment

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

just a thought about the usage of pointers

@@ -0,0 +1,45 @@
package radarr_test
Copy link
Contributor

Choose a reason for hiding this comment

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

@davidnewhall this really rock! thanks 🚀

Comment on lines 16 to 26
type BulkEdit struct {
MovieIDs []int64 `json:"movieIds"`
Monitored *bool `json:"monitored,omitempty"`
QualityProfileID *int64 `json:"qualityProfileId,omitempty"`
MinimumAvailability *string `json:"minimumAvailability,omitempty"` // tba
RootFolderPath *string `json:"rootFolderPath,omitempty"` // path
Tags []int `json:"tags,omitempty"` // [0]
ApplyTags *string `json:"applyTags,omitempty"` // add
MoveFiles *bool `json:"moveFiles,omitempty"`
DeleteFiles *bool `json:"deleteFiles,omitempty"` // delete only
AddImportExclusion *bool `json:"addImportExclusion,omitempty"` // delete only
Copy link
Contributor

Choose a reason for hiding this comment

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

are they pointer to let them leverage the omitempty tag and use the default 0 value as well?
when they are not present which is the default behaviour? if it is the same as the 0 value you can use values instead of pointers and remove the omitempty tag.
I haven't tried this, so they're just some thoughts

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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 monitored, for instance, there are three choices. monitored, not monitored and no change. We achieve "no change" by omitting the key entirely. If we set it to true, then all movie IDs provided are monitored. If we set it to false then they are all unmonitored. If we do not want to change the monitored status, but rather, change something else, then we have to omit monitored.

Copy link
Contributor

Choose a reason for hiding this comment

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

got it, thanks for the example

MinimumAvailability *string `json:"minimumAvailability,omitempty"` // tba
RootFolderPath *string `json:"rootFolderPath,omitempty"` // path
Tags []int `json:"tags,omitempty"` // [0]
ApplyTags *string `json:"applyTags,omitempty"` // add
Copy link
Contributor Author

Choose a reason for hiding this comment

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

ApplyTags could probably be enum constants, but I do not know all the values.

Choose a reason for hiding this comment

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

MovieIDs []int64 `json:"movieIds"`
Monitored *bool `json:"monitored,omitempty"`
QualityProfileID *int64 `json:"qualityProfileId,omitempty"`
MinimumAvailability *string `json:"minimumAvailability,omitempty"` // tba
Copy link
Contributor Author

Choose a reason for hiding this comment

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

MinimumAvailability could probably be enum constants, but I do not know all the values.

Choose a reason for hiding this comment

The 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

@bakerboy448
Copy link

AddImportExclusion is documented here: https://radarr.video/docs/api/#/MovieEditor/delete_api_v3_movie_editor
...but I don't see any way to trigger it in the UI, so it may not actual work? Can you get an example payload where this works?

This is a modal prompt when you delete movies. Same prompt when deleting movie (not via editor)

delete files
add To exclusion list

@bakerboy448
Copy link

But I don't think you can add movies to the exclusion list via the UI. That's only possible with an api call.

discover tab has this option to select and exclude

Otherwise when deleting a movie or movies the exclusion list is a modal confirmation checkbox

@davidnewhall
Copy link
Contributor Author

I think I'm gonna turn those inputs into enums. We can probably re-use them in a few places.

@davidnewhall
Copy link
Contributor Author

How's that look @Fuochi ?

Copy link
Contributor

@Fuochi Fuochi left a comment

Choose a reason for hiding this comment

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

I don't fully get the Ptr() functions added... but I'm sure I'm missing a use case

Comment on lines 43 to 46
// Ptr returns a pointer to a minimum availability. Useful for a BulkEdit struct.
func (a Availability) Ptr() *Availability {
return &a
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't get the use case of this, can't you just use the & operator? why is a method needed?

Copy link
Contributor Author

@davidnewhall davidnewhall Oct 7, 2022

Choose a reason for hiding this comment

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

You cannot make pointers to constants, so the user would have to do:

  avail := radarr.AvailabilityInCinemas

Then pass in &avail. Having the Ptr method allows passing a value in 1 line, as shown in the test.

Comment on lines +30 to +41
// Availability is an enum used as MinimumAvailability in a few places throughout Radarr.
type Availability string

// Availability / MinimumAvailability constants.
// https://radarr.video/docs/api/#/MovieEditor/put_api_v3_movie_editor
const (
AvailabilityToBeAnnounced Availability = "tba"
AvailabilityAnnounced Availability = "announced"
AvailabilityInCinemas Availability = "inCinemas"
AvailabilityReleased Availability = "released"
AvailabilityDeleted Availability = "deleted"
)
Copy link
Contributor

Choose a reason for hiding this comment

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

this is nice for a user perspective since it provides users with valid values. However, users can still use any string they want... so I'd say it doesn't make much difference for me, if you like this approach you can continue to use it!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's all about users. This, if nothing else, gives them an easy way to see what values are appropriate.

Copy link
Collaborator

Choose a reason for hiding this comment

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

There is a difference in status and availability. tba and deleted will not work as a minimum availability in radarr. "announced", "released" & "inCinemas"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

:(

Screen Shot 2022-10-07 at 11 18 15 AM

Choose a reason for hiding this comment

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

Practical use would be the 3 nit mentioned

  • deleted is a status from tmdb
  • tba is legacy carryover

neither really has any practical use

Copy link
Contributor Author

Choose a reason for hiding this comment

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

All good. I just made them constants. Users don't have to use them. :)

@davidnewhall davidnewhall merged commit 843eaad into master Oct 7, 2022
@davidnewhall davidnewhall deleted the dn2_movie_editor branch October 7, 2022 08:49
@austinwbest
Copy link
Collaborator

But I don't think you can add movies to the exclusion list via the UI. That's only possible with an api call. The request I sent in the previous message actually works and it deletes all the movie files in the movieID list and puts the movies under "Settings" > "Lists" > "List Exclusions" in the UI.

You can add movies to the exclusion list on the List Exclusions page @NCRoxas ... There is a + at the bottom of the list.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add MovieEditor endpoint to Radarr
5 participants