Skip to content

Commit

Permalink
radarr: Add message for added or failed movies
Browse files Browse the repository at this point in the history
  • Loading branch information
pando85 committed Jan 14, 2024
1 parent 28a4d5d commit ff63866
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions radarr/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit ff63866

Please sign in to comment.