|
@@ -16,7 +16,9 @@ type Client struct {
|
|
|
|
|
|
// Stream represents a liquidsoap stream. It contains information about the status and the nature of it
|
|
|
type Stream struct {
|
|
|
- State bool
|
|
|
+ Enabled bool `json:"enabled"`
|
|
|
+ Up bool `json:"up"`
|
|
|
+ Type string `json:"type"`
|
|
|
}
|
|
|
|
|
|
// NewTelnet returns a liquidsoap.Client created using telnet on the given parameters
|
|
@@ -56,8 +58,8 @@ func (c *Client) Command(cmdline string) (string, error) {
|
|
|
|
|
|
// Outputs will return a map of outputs that liquidsoap is handling.
|
|
|
// An output is set to true if it is enabled
|
|
|
-func (c *Client) Outputs() (outputs map[string]bool, err error) {
|
|
|
- outputs = make(map[string]bool)
|
|
|
+func (c *Client) Outputs() (outputs map[string]Stream, err error) {
|
|
|
+ outputs = make(map[string]Stream)
|
|
|
var cmdout string
|
|
|
cmdout, err = c.Command("list")
|
|
|
if err != nil {
|
|
@@ -71,12 +73,17 @@ func (c *Client) Outputs() (outputs map[string]bool, err error) {
|
|
|
}
|
|
|
if strings.Index(parts[1], "output.") == 0 {
|
|
|
name := strings.TrimSpace(parts[0])
|
|
|
- var enabled bool
|
|
|
- enabled, err = c.GetOutput(name)
|
|
|
- if err != nil {
|
|
|
- return
|
|
|
+ var stream Stream
|
|
|
+ stream.Type = parts[1][7:]
|
|
|
+ enabled, err := c.GetOutput(name)
|
|
|
+ if err == nil {
|
|
|
+ stream.Enabled = enabled
|
|
|
}
|
|
|
- outputs[name] = enabled
|
|
|
+ up, err := c.GetOutputUp(name)
|
|
|
+ if err == nil {
|
|
|
+ stream.Up = up
|
|
|
+ }
|
|
|
+ outputs[name] = stream
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -92,6 +99,31 @@ func (c *Client) GetOutput(name string) (bool, error) {
|
|
|
return strings.TrimSpace(cmdout) == "on", nil
|
|
|
}
|
|
|
|
|
|
+// GetOutput checks whether an output is up
|
|
|
+//
|
|
|
+// Please note that this relies on a custom convention proposed by direttoforo, where to every stream "x"
|
|
|
+// there is an interactive boolean variable "x_up" that has its state
|
|
|
+func (c *Client) GetOutputUp(name string) (bool, error) {
|
|
|
+ return c.GetVar(name + "_up")
|
|
|
+}
|
|
|
+
|
|
|
+// GetVar reads an interactive variable
|
|
|
+func (c *Client) GetVar(name string) (bool, error) {
|
|
|
+ cmdout, err := c.Command("var.get " + name)
|
|
|
+ if err != nil {
|
|
|
+ return false, err
|
|
|
+ }
|
|
|
+ cmdout = strings.TrimSpace(cmdout)
|
|
|
+ switch cmdout {
|
|
|
+ case "true":
|
|
|
+ return true, nil
|
|
|
+ case "false":
|
|
|
+ return false, nil
|
|
|
+ default:
|
|
|
+ return false, fmt.Errorf("Variable %s not set", name)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
// SetOutput enables or disables an output
|
|
|
func (c *Client) SetOutput(name string, enabled bool) error {
|
|
|
action := "stop"
|