golift.io/starr@v1.0.0/radarr/moviefile.go (about) 1 package radarr 2 3 import ( 4 "bytes" 5 "context" 6 "encoding/json" 7 "fmt" 8 "net/url" 9 "path" 10 "time" 11 12 "golift.io/starr" 13 ) 14 15 const bpMovieFile = APIver + "/moviefile" 16 17 // MovieFile is part of a Movie. 18 type MovieFile struct { 19 ID int64 `json:"id"` 20 MovieID int64 `json:"movieId"` 21 RelativePath string `json:"relativePath"` 22 Path string `json:"path"` 23 Size int64 `json:"size"` 24 DateAdded time.Time `json:"dateAdded"` 25 SceneName string `json:"sceneName"` 26 IndexerFlags int64 `json:"indexerFlags"` 27 Quality *starr.Quality `json:"quality,omitempty"` 28 CustomFormats []*CustomFormatOutput `json:"customFormats,omitempty"` 29 CustomFormatScore int `json:"customFormatScore"` 30 MediaInfo *MediaInfo `json:"mediaInfo,omitempty"` 31 OriginalFilePath string `json:"originalFilePath"` 32 QualityCutoffNotMet bool `json:"qualityCutoffNotMet"` 33 Languages []*starr.Value `json:"languages"` 34 ReleaseGroup string `json:"releaseGroup"` 35 Edition string `json:"edition"` 36 } 37 38 // MediaInfo is part of a MovieFile. 39 type MediaInfo struct { 40 ID int64 `json:"id"` 41 AudioBitrate int `json:"audioBitrate"` 42 AudioChannels float64 `json:"audioChannels"` 43 AudioCodec string `json:"audioCodec"` 44 AudioLanguages string `json:"audioLanguages"` 45 AudioStreamCount int `json:"audioStreamCount"` 46 VideoBitDepth int `json:"videoBitDepth"` 47 VideoBitrate int `json:"videoBitrate"` 48 VideoCodec string `json:"videoCodec"` 49 VideoDynamicRangeType string `json:"videoDynamicRangeType"` 50 VideoFps float64 `json:"videoFps"` 51 Resolution string `json:"resolution"` 52 RunTime string `json:"runTime"` 53 ScanType string `json:"scanType"` 54 Subtitles string `json:"subtitles"` 55 } 56 57 // GetMovieFile returns the movie file(s) for a movie. 58 func (r *Radarr) GetMovieFile(movieID int64) ([]*MovieFile, error) { 59 return r.GetMovieFileContext(context.Background(), movieID) 60 } 61 62 // GetMovieFileContext returns the movie file(s) for a movie. 63 func (r *Radarr) GetMovieFileContext(ctx context.Context, movieID int64) ([]*MovieFile, error) { 64 req := starr.Request{URI: bpMovieFile, Query: make(url.Values)} 65 req.Query.Add("movieID", fmt.Sprint(movieID)) 66 67 var output []*MovieFile 68 if err := r.GetInto(ctx, req, &output); err != nil { 69 return nil, fmt.Errorf("api.Get(%s): %w", &req, err) 70 } 71 72 return output, nil 73 } 74 75 // GetMovieFiles returns the movie file(s) requested. 76 func (r *Radarr) GetMovieFiles(movieFileIDs []int64) ([]*MovieFile, error) { 77 return r.GetMovieFilesContext(context.Background(), movieFileIDs) 78 } 79 80 // GetMovieFilesContext returns the movie file(s) requested. 81 func (r *Radarr) GetMovieFilesContext(ctx context.Context, movieFileIDs []int64) ([]*MovieFile, error) { 82 req := starr.Request{URI: bpMovieFile, Query: make(url.Values)} 83 for _, id := range movieFileIDs { 84 req.Query.Add("movieFileIds", fmt.Sprint(id)) 85 } 86 87 var output []*MovieFile 88 if err := r.GetInto(ctx, req, &output); err != nil { 89 return nil, fmt.Errorf("api.Get(%s): %w", &req, err) 90 } 91 92 return output, nil 93 } 94 95 // UpdateMovieFile updates the movie file provided. 96 func (r *Radarr) UpdateMovieFile(movieFile *MovieFile) (*MovieFile, error) { 97 return r.UpdateMovieFileContext(context.Background(), movieFile) 98 } 99 100 // UpdateMovieFileContext updates the movie file provided. 101 func (r *Radarr) UpdateMovieFileContext(ctx context.Context, movieFile *MovieFile) (*MovieFile, error) { 102 var body bytes.Buffer 103 if err := json.NewEncoder(&body).Encode(movieFile); err != nil { 104 return nil, fmt.Errorf("json.Marshal(%s): %w", bpMovieFile, err) 105 } 106 107 var output *MovieFile 108 109 req := starr.Request{URI: path.Join(bpMovieFile, fmt.Sprint(movieFile.ID)), Body: &body} 110 if err := r.PutInto(ctx, req, &output); err != nil { 111 return nil, fmt.Errorf("api.Put(%s): %w", &req, err) 112 } 113 114 return output, nil 115 } 116 117 // DeleteMovieFile deletes movie files by their IDs. 118 func (r *Radarr) DeleteMovieFiles(movieFileIDs ...int64) error { 119 return r.DeleteMovieFilesContext(context.Background(), movieFileIDs...) 120 } 121 122 // DeleteMovieFileContext deletes movie files by their IDs. 123 func (r *Radarr) DeleteMovieFilesContext(ctx context.Context, movieFileIDs ...int64) error { 124 postData := struct { 125 T []int64 `json:"movieFileIds"` 126 }{movieFileIDs} 127 128 var body bytes.Buffer 129 if err := json.NewEncoder(&body).Encode(&postData); err != nil { 130 return fmt.Errorf("json.Marshal(%s): %w", bpMovieFile, err) 131 } 132 133 req := starr.Request{URI: path.Join(bpMovieFile, "bulk"), Body: &body} 134 if err := r.DeleteAny(ctx, req); err != nil { 135 return fmt.Errorf("api.Delete(%s): %w", &req, err) 136 } 137 138 return nil 139 }