package mpd import ( "fmt" "strings" ) type output struct { name, plugin string enabled bool } func parseOutputs(lines []string) []output { var outputs []output for _, line := range lines { key, value, ok := strings.Cut(line, ": ") if !ok { continue } if key == "outputid" { outputs = append(outputs, output{}) } if len(outputs) == 0 { continue } o := &outputs[len(outputs)-1] switch key { case "outputname": o.name = value case "plugin": o.plugin = value case "outputenabled": o.enabled = value == "1" } } return outputs } func fifoOutputState(outputs []output, name string) error { var matches []output for _, o := range outputs { if name != "" { if o.name == name && (o.plugin == "fifo" || o.plugin == "") { matches = append(matches, o) } } else if o.plugin == "fifo" { matches = append(matches, o) } } switch len(matches) { case 0: return fmt.Errorf("no matching MPD FIFO output; check MPD configuration and audio.output") case 1: if !matches[0].enabled { return fmt.Errorf("MPD FIFO output %q is disabled", matches[0].name) } return nil default: return fmt.Errorf("multiple matching MPD FIFO outputs; set audio.output to the output name") } }