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
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 5 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,10 @@ linters:
- dupl
- nlreturn

#linters-settings:
# govet:
# enable:
# - fieldalignment

run:
timeout: 35m
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module golift.io/starr

go 1.17

require golang.org/x/net v0.0.0-20220826154423-83b083e8dc8b // publicsuffix, cookiejar.
require golang.org/x/net v0.0.0-20221004154528-8021a29435af // publicsuffix, cookiejar.

// All of this is for the tests.
require (
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ golang.org/x/net v0.0.0-20220225172249-27dd8689420f h1:oA4XRj0qtSt8Yo1Zms0CUlsT3
golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
golang.org/x/net v0.0.0-20220826154423-83b083e8dc8b h1:ZmngSVLe/wycRns9MKikG9OWIEjGcGAkacif7oYQaUY=
golang.org/x/net v0.0.0-20220826154423-83b083e8dc8b/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk=
golang.org/x/net v0.0.0-20221004154528-8021a29435af h1:wv66FM3rLZGPdxpYL+ApnDe2HzHcTFta3z5nsc13wI4=
golang.org/x/net v0.0.0-20221004154528-8021a29435af/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
Expand Down
34 changes: 17 additions & 17 deletions radarr/importlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,23 @@ const bpImportList = APIver + "/importlist"

// ImportList represents the api/v3/importlist endpoint.
type ImportList struct {
ID int64 `json:"id"`
Name string `json:"name"`
Enabled bool `json:"enabled"`
EnableAuto bool `json:"enableAuto"`
ShouldMonitor bool `json:"shouldMonitor"`
SearchOnAdd bool `json:"searchOnAdd"`
RootFolderPath string `json:"rootFolderPath"`
QualityProfileID int64 `json:"qualityProfileId"`
MinimumAvailability string `json:"minimumAvailability"`
ListType string `json:"listType"`
ListOrder int64 `json:"listOrder"`
Fields []*Field `json:"fields"`
ImplementationName string `json:"implementationName"`
Implementation string `json:"implementation"`
ConfigContract string `json:"configContract"`
InfoLink string `json:"infoLink"`
Tags []int `json:"tags"`
ID int64 `json:"id"`
Name string `json:"name"`
Enabled bool `json:"enabled"`
EnableAuto bool `json:"enableAuto"`
ShouldMonitor bool `json:"shouldMonitor"`
SearchOnAdd bool `json:"searchOnAdd"`
RootFolderPath string `json:"rootFolderPath"`
QualityProfileID int64 `json:"qualityProfileId"`
MinimumAvailability Availability `json:"minimumAvailability"`
ListType string `json:"listType"`
ListOrder int64 `json:"listOrder"`
Fields []*Field `json:"fields"`
ImplementationName string `json:"implementationName"`
Implementation string `json:"implementation"`
ConfigContract string `json:"configContract"`
InfoLink string `json:"infoLink"`
Tags []int `json:"tags"`
}

// Field is currently only part of ImportList.
Expand Down
6 changes: 3 additions & 3 deletions radarr/movie.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type Movie struct {
ID int64 `json:"id"`
Title string `json:"title,omitempty"`
Path string `json:"path,omitempty"`
MinimumAvailability string `json:"minimumAvailability,omitempty"`
MinimumAvailability Availability `json:"minimumAvailability,omitempty"`
QualityProfileID int64 `json:"qualityProfileId,omitempty"`
TmdbID int64 `json:"tmdbId,omitempty"`
OriginalTitle string `json:"originalTitle,omitempty"`
Expand Down Expand Up @@ -101,7 +101,7 @@ type MediaInfo struct {
type AddMovieInput struct {
Title string `json:"title,omitempty"`
TitleSlug string `json:"titleSlug,omitempty"`
MinimumAvailability string `json:"minimumAvailability,omitempty"`
MinimumAvailability Availability `json:"minimumAvailability,omitempty"`
RootFolderPath string `json:"rootFolderPath"`
TmdbID int64 `json:"tmdbId"`
QualityProfileID int64 `json:"qualityProfileId"`
Expand Down Expand Up @@ -138,7 +138,7 @@ type AddMovieOutput struct {
Studio string `json:"studio"`
Path string `json:"path"`
QualityProfileID int64 `json:"qualityProfileId"`
MinimumAvailability string `json:"minimumAvailability"`
MinimumAvailability Availability `json:"minimumAvailability"`
FolderName string `json:"folderName"`
Runtime int `json:"runtime"`
CleanTitle string `json:"cleanTitle"`
Expand Down
39 changes: 29 additions & 10 deletions radarr/movieeditor.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,36 @@ 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.
// Use Availability.Ptr() to add a value to minimum availability, and starr.ApplyTags.Ptr() for apply tags.
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
MovieIDs []int64 `json:"movieIds"`
Monitored *bool `json:"monitored,omitempty"`
QualityProfileID *int64 `json:"qualityProfileId,omitempty"`
MinimumAvailability *Availability `json:"minimumAvailability,omitempty"` // tba
RootFolderPath *string `json:"rootFolderPath,omitempty"` // path
Tags []int `json:"tags,omitempty"` // [0]
ApplyTags *starr.ApplyTags `json:"applyTags,omitempty"` // add
MoveFiles *bool `json:"moveFiles,omitempty"`
DeleteFiles *bool `json:"deleteFiles,omitempty"` // delete only
AddImportExclusion *bool `json:"addImportExclusion,omitempty"` // delete only
}

// 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"
)
Comment on lines +30 to +41
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. :)


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


// EditMovies allows bulk diting many movies at once.
Expand Down
24 changes: 22 additions & 2 deletions radarr/movieeditor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,26 @@ func TestEditMovies(t *testing.T) {
ExpectedMethod: http.MethodPut,
WithResponse: []*radarr.Movie{{ID: 7, Monitored: true}, {ID: 3, Monitored: true}},
},
{
Name: "200",
ExpectedPath: path.Join("/", starr.API, radarr.APIver, "movie", "editor"),
ResponseStatus: http.StatusOK,
ResponseBody: `[{"id":17,"minimumAvailability":"tba","tags":[44,55,66]},` +
`{"id":13,"minimumAvailability":"tba","tags":[44,55,66]}]`,
WithError: nil,
WithRequest: &radarr.BulkEdit{
MovieIDs: []int64{17, 13},
Tags: []int{44, 55, 66},
ApplyTags: starr.TagsAdd.Ptr(),
MinimumAvailability: radarr.AvailabilityToBeAnnounced.Ptr(),
},
ExpectedRequest: `{"movieIds":[17,13],"minimumAvailability":"tba","tags":[44,55,66],"applyTags":"add"}` + "\n",
ExpectedMethod: http.MethodPut,
WithResponse: []*radarr.Movie{
{ID: 17, MinimumAvailability: radarr.AvailabilityToBeAnnounced, Tags: []int{44, 55, 66}},
{ID: 13, MinimumAvailability: radarr.AvailabilityToBeAnnounced, Tags: []int{44, 55, 66}},
},
},
}

for _, test := range tests {
Expand All @@ -38,8 +58,8 @@ func TestEditMovies(t *testing.T) {
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")
assert.ErrorIs(t, err, test.WithError, "the wrong error was returned")
assert.EqualValues(t, test.WithResponse, output, "make sure ResponseBody and WithResponse are a match")
})
}
}
16 changes: 16 additions & 0 deletions shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,3 +224,19 @@ func (d *PlayTime) MarshalJSON() ([]byte, error) {
}

var _ json.Unmarshaler = (*PlayTime)(nil)

// ApplyTags is an enum used as an input for Bulk editors, and perhaps other places.
type ApplyTags string

// ApplyTags enum constants. Use these as inputs for "ApplyTags" member values.
// Schema doc'd here: https://radarr.video/docs/api/#/MovieEditor/put_api_v3_movie_editor
const (
TagsAdd ApplyTags = "add"
TagsRemove ApplyTags = "remove"
TagsReplace ApplyTags = "replace"
)

// Ptr returns a pointer to an apply tags value. Useful for a BulkEdit struct.
func (a ApplyTags) Ptr() *ApplyTags {
return &a
}