Monitor MPD FIFO output status for audio sources

This commit is contained in:
maze committed 2026-10-29 17:38:07 +01:00
1 parent 1b2285fc91
commit f2c9aeb3a8
9 files changed
+159 -1

No files matched your search

+61
View File
@@ -0,0 +1,61 @@
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")
}
}