golift.io/starr@v1.0.0/radarr/movieeditor.go (about) 1 package radarr 2 3 import ( 4 "bytes" 5 "context" 6 "encoding/json" 7 "fmt" 8 9 "golift.io/starr" 10 ) 11 12 const bpMovieEditor = bpMovie + "/editor" 13 14 // BulkEdit is the input for the bulk movie editor endpoint. 15 // You may use starr.True(), starr.False(), starr.Int64(), and starr.String() to add data to the struct members. 16 // Use Availability.Ptr() to add a value to minimum availability, and starr.ApplyTags.Ptr() for apply tags. 17 type BulkEdit struct { 18 MovieIDs []int64 `json:"movieIds"` 19 Monitored *bool `json:"monitored,omitempty"` 20 QualityProfileID *int64 `json:"qualityProfileId,omitempty"` 21 MinimumAvailability *Availability `json:"minimumAvailability,omitempty"` // tba 22 RootFolderPath *string `json:"rootFolderPath,omitempty"` // path 23 Tags []int `json:"tags,omitempty"` // [0] 24 ApplyTags *starr.ApplyTags `json:"applyTags,omitempty"` // add 25 MoveFiles *bool `json:"moveFiles,omitempty"` 26 DeleteFiles *bool `json:"deleteFiles,omitempty"` // delete only 27 AddImportExclusion *bool `json:"addImportExclusion,omitempty"` // delete only 28 } 29 30 // Availability is an enum used as MinimumAvailability in a few places throughout Radarr. 31 type Availability string 32 33 // Availability / MinimumAvailability constants. 34 // https://radarr.video/docs/api/#/MovieEditor/put_api_v3_movie_editor 35 const ( 36 AvailabilityToBeAnnounced Availability = "tba" 37 AvailabilityAnnounced Availability = "announced" 38 AvailabilityInCinemas Availability = "inCinemas" 39 AvailabilityReleased Availability = "released" 40 AvailabilityDeleted Availability = "deleted" 41 ) 42 43 // Ptr returns a pointer to a minimum availability. Useful for a BulkEdit struct. 44 func (a Availability) Ptr() *Availability { 45 return &a 46 } 47 48 // EditMovies allows bulk diting many movies at once. 49 func (r *Radarr) EditMovies(editMovies *BulkEdit) ([]*Movie, error) { 50 return r.EditMoviesContext(context.Background(), editMovies) 51 } 52 53 // EditMoviesContext allows bulk diting many movies at once. 54 func (r *Radarr) EditMoviesContext(ctx context.Context, editMovies *BulkEdit) ([]*Movie, error) { 55 var body bytes.Buffer 56 if err := json.NewEncoder(&body).Encode(editMovies); err != nil { 57 return nil, fmt.Errorf("json.Marshal(%s): %w", bpMovieEditor, err) 58 } 59 60 var output []*Movie 61 62 req := starr.Request{URI: bpMovieEditor, Body: &body} 63 if err := r.PutInto(ctx, req, &output); err != nil { 64 return nil, fmt.Errorf("api.Put(%s): %w", &req, err) 65 } 66 67 return output, nil 68 } 69 70 // DeleteMovies bulk deletes movies. Can also mark them as excluded, and delete their files. 71 func (r *Radarr) DeleteMovies(deleteMovies *BulkEdit) error { 72 return r.DeleteMoviesContext(context.Background(), deleteMovies) 73 } 74 75 // DeleteMoviesContext bulk deletes movies. Can also mark them as excluded, and delete their files. 76 func (r *Radarr) DeleteMoviesContext(ctx context.Context, deleteMovies *BulkEdit) error { 77 var body bytes.Buffer 78 if err := json.NewEncoder(&body).Encode(deleteMovies); err != nil { 79 return fmt.Errorf("json.Marshal(%s): %w", bpMovieEditor, err) 80 } 81 82 req := starr.Request{URI: bpMovieEditor, Body: &body} 83 if err := r.DeleteAny(ctx, req); err != nil { 84 return fmt.Errorf("api.Delete(%s): %w", &req, err) 85 } 86 87 return nil 88 }