From ff6386658c89469087fff794abe3d1819aec2965 Mon Sep 17 00:00:00 2001 From: Alexander Gil Date: Sun, 14 Jan 2024 21:49:03 +0100 Subject: [PATCH] radarr: Add message for added or failed movies --- radarr/main.go | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/radarr/main.go b/radarr/main.go index 30e3736..fb776e9 100644 --- a/radarr/main.go +++ b/radarr/main.go @@ -50,6 +50,48 @@ func HumanReadableSize(size int64) string { return fmt.Sprintf("%.2f %cB", float64(size)/float64(div), "KMGTPE"[exp]) } +type ScheduledItem struct { + SourcePath string `json:"sourcePath"` + DestinationPath string `json:"destinationPath"` + ID string `json:"id"` + Events interface{} `json:"events"` +} + +type FailedItem struct { + SourcePath string `json:"sourcePath"` + DestinationPath string `json:"destinationPath"` + ForceCompleted bool `json:"forceCompleted"` + ForceFailed bool `json:"forceFailed"` + ForceExecuting bool `json:"forceExecuting"` + ForceAdded bool `json:"forceAdded"` + Priority int `json:"priority"` + Error string `json:"error"` +} + +type Response struct { + Scheduled []ScheduledItem `json:"scheduled"` + Failed []FailedItem `json:"failed"` + Skipped interface{} `json:"skipped"` +} + +func PrintTranscoderResponse(jsonStr []byte) error { + var response Response + if err := json.Unmarshal(jsonStr, &response); err != nil { + return err + } + + switch { + case len(response.Failed) > 0: + fmt.Println("Movie was not added.") + case len(response.Scheduled) > 0: + fmt.Println("Movie successfully added.") + default: + return errors.New("Movie was neither failed nor added.") + } + + return nil +} + func AddMovieToTranscoderQueue(path string, url string) error { payload := map[string]string{ "SourcePath": path, @@ -83,11 +125,17 @@ func AddMovieToTranscoderQueue(path string, url string) error { return err } + err = PrintTranscoderResponse(body) + if err != nil { + fmt.Printf("Error decoding transcoder response: %s", err) + } + if resp.StatusCode != http.StatusOK { // Return an error with a detailed message return errors.New(fmt.Sprintf("Request failed with status %s. Response Body: %s", resp.Status, body)) } + fmt.Println() return nil }