@@ -23,24 +23,46 @@ type CommandRequest struct {
2323 ArtistID int64 `json:"artistId,omitempty"`
2424}
2525
26+ // ManualImportFile is one file in a ManualImport command request.
27+ type ManualImportFile struct {
28+ Path string `json:"path"`
29+ ArtistID int64 `json:"artistId"`
30+ AlbumID int64 `json:"albumId"`
31+ AlbumReleaseID int64 `json:"albumReleaseId"`
32+ TrackIDs []int64 `json:"trackIds"`
33+ Quality * starr.Quality `json:"quality"`
34+ IndexerFlags int `json:"indexerFlags"`
35+ DownloadID string `json:"downloadId"`
36+ DisableReleaseSwitching bool `json:"disableReleaseSwitching"`
37+ }
38+
39+ // ManualImportCommandRequest is the body for the ManualImport command (POST /api/v1/command).
40+ // It triggers Lidarr to import the listed files.
41+ type ManualImportCommandRequest struct {
42+ Name string `json:"name"` // "ManualImport"
43+ Files []* ManualImportFile `json:"files"`
44+ ImportMode string `json:"importMode"` // "auto"
45+ ReplaceExistingFiles bool `json:"replaceExistingFiles"`
46+ }
47+
2648// CommandResponse comes from the /api/v1/command endpoint.
2749type CommandResponse struct {
28- ID int64 `json:"id"`
29- Name string `json:"name"`
30- CommandName string `json:"commandName"`
31- Message string `json:"message,omitempty"`
32- Priority string `json:"priority"`
33- Status string `json:"status"`
34- Queued time.Time `json:"queued"`
35- Started time.Time `json:"started,omitempty"`
36- Ended time.Time `json:"ended,omitempty"`
37- StateChangeTime time.Time `json:"stateChangeTime,omitempty"`
38- LastExecutionTime time.Time `json:"lastExecutionTime,omitempty"`
39- Duration string `json:"duration,omitempty"`
40- Trigger string `json:"trigger"`
41- SendUpdatesToClient bool `json:"sendUpdatesToClient"`
42- UpdateScheduledTask bool `json:"updateScheduledTask"`
43- Body map [string ]interface {} `json:"body"`
50+ ID int64 `json:"id"`
51+ Name string `json:"name"`
52+ CommandName string `json:"commandName"`
53+ Message string `json:"message,omitempty"`
54+ Priority string `json:"priority"`
55+ Status string `json:"status"`
56+ Queued time.Time `json:"queued"`
57+ Started time.Time `json:"started,omitempty"`
58+ Ended time.Time `json:"ended,omitempty"`
59+ StateChangeTime time.Time `json:"stateChangeTime,omitempty"`
60+ LastExecutionTime time.Time `json:"lastExecutionTime,omitempty"`
61+ Duration string `json:"duration,omitempty"`
62+ Trigger string `json:"trigger"`
63+ SendUpdatesToClient bool `json:"sendUpdatesToClient"`
64+ UpdateScheduledTask bool `json:"updateScheduledTask"`
65+ Body map [string ]any `json:"body"`
4466}
4567
4668// GetCommands returns all available Lidarr commands.
@@ -106,3 +128,39 @@ func (l *Lidarr) GetCommandStatusContext(ctx context.Context, commandID int64) (
106128
107129 return & output , nil
108130}
131+
132+ // SendManualImportCommand sends the ManualImport command to import the given files (e.g. after FLAC+CUE split).
133+ func (l * Lidarr ) SendManualImportCommand (cmd * ManualImportCommandRequest ) (* CommandResponse , error ) {
134+ return l .SendManualImportCommandContext (context .Background (), cmd )
135+ }
136+
137+ // SendManualImportCommandContext sends the ManualImport command to import the given files.
138+ func (l * Lidarr ) SendManualImportCommandContext (
139+ ctx context.Context , cmd * ManualImportCommandRequest ,
140+ ) (* CommandResponse , error ) {
141+ var output CommandResponse
142+
143+ if cmd == nil || len (cmd .Files ) == 0 {
144+ return & output , nil
145+ }
146+
147+ if cmd .Name == "" {
148+ cmd .Name = "ManualImport"
149+ }
150+
151+ if cmd .ImportMode == "" {
152+ cmd .ImportMode = "auto"
153+ }
154+
155+ var buf bytes.Buffer
156+ if err := json .NewEncoder (& buf ).Encode (cmd ); err != nil {
157+ return nil , fmt .Errorf ("json.Marshal(%s): %w" , bpCommand , err )
158+ }
159+
160+ req := starr.Request {URI : bpCommand , Body : & buf }
161+ if err := l .PostInto (ctx , req , & output ); err != nil {
162+ return nil , fmt .Errorf ("api.Post(%s): %w" , & req , err )
163+ }
164+
165+ return & output , nil
166+ }
0 commit comments