liquidsoap can understand if a stream is "up"
(provided the liq script is complex enough!)
This commit is contained in:
parent
0965847026
commit
7ce86918bc
3 changed files with 57 additions and 14 deletions
|
@ -78,21 +78,20 @@ func main() {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
changed := false
|
changed := false
|
||||||
for name, enabled := range outs {
|
for name, newstream := range outs {
|
||||||
if stream, exists := state.Streams[name]; exists {
|
if stream, exists := state.Streams[name]; exists {
|
||||||
if stream.State != enabled {
|
if newstream != stream {
|
||||||
stream.State = enabled
|
state.Streams[name] = newstream
|
||||||
changed = true
|
changed = true
|
||||||
}
|
}
|
||||||
state.Streams[name] = stream
|
|
||||||
} else {
|
} else {
|
||||||
state.Streams[name] = liquidsoap.Stream{State: enabled}
|
state.Streams[name] = newstream
|
||||||
changed = true
|
changed = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
t.Close()
|
t.Close()
|
||||||
fmt.Println(changed, "state=", state)
|
|
||||||
if changed {
|
if changed {
|
||||||
|
fmt.Println("state=", state)
|
||||||
netUI.Update()
|
netUI.Update()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,16 @@
|
||||||
set('log.file', false)
|
set('log.file', false)
|
||||||
set('log.stdout', true)
|
set('log.stdout', true)
|
||||||
|
|
||||||
|
rec_up = interactive.bool("rec_up", false)
|
||||||
|
icecast_up = interactive.bool("icecast_up", false)
|
||||||
|
def var_ok(varname) =
|
||||||
|
fun () -> ignore(server.execute("var.set #{varname} = true"))
|
||||||
|
end
|
||||||
|
def var_ko(varname) =
|
||||||
|
fun () -> ignore(server.execute("var.set #{varname} = false"))
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
audioin = in()
|
audioin = in()
|
||||||
audioin = rewrite_metadata([("artist", "Direttoforo")], audioin)
|
audioin = rewrite_metadata([("artist", "Direttoforo")], audioin)
|
||||||
audioin = server.rms(id="rms", audioin)
|
audioin = server.rms(id="rms", audioin)
|
||||||
|
@ -12,6 +22,8 @@ audioin = server.rms(id="rms", audioin)
|
||||||
f = output.file(
|
f = output.file(
|
||||||
id="rec",
|
id="rec",
|
||||||
%vorbis(quality=0.2, samplerate=44100, channels=2),
|
%vorbis(quality=0.2, samplerate=44100, channels=2),
|
||||||
|
on_start=var_ok("rec_up"),
|
||||||
|
on_stop=var_ko("rec_up"),
|
||||||
"rec/%Y/%m/rec-%Y-%m-%d_%H-%M-%S.ogg",
|
"rec/%Y/%m/rec-%Y-%m-%d_%H-%M-%S.ogg",
|
||||||
audioin
|
audioin
|
||||||
)
|
)
|
||||||
|
|
|
@ -16,7 +16,9 @@ type Client struct {
|
||||||
|
|
||||||
// Stream represents a liquidsoap stream. It contains information about the status and the nature of it
|
// Stream represents a liquidsoap stream. It contains information about the status and the nature of it
|
||||||
type Stream struct {
|
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
|
// 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.
|
// Outputs will return a map of outputs that liquidsoap is handling.
|
||||||
// An output is set to true if it is enabled
|
// An output is set to true if it is enabled
|
||||||
func (c *Client) Outputs() (outputs map[string]bool, err error) {
|
func (c *Client) Outputs() (outputs map[string]Stream, err error) {
|
||||||
outputs = make(map[string]bool)
|
outputs = make(map[string]Stream)
|
||||||
var cmdout string
|
var cmdout string
|
||||||
cmdout, err = c.Command("list")
|
cmdout, err = c.Command("list")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -71,12 +73,17 @@ func (c *Client) Outputs() (outputs map[string]bool, err error) {
|
||||||
}
|
}
|
||||||
if strings.Index(parts[1], "output.") == 0 {
|
if strings.Index(parts[1], "output.") == 0 {
|
||||||
name := strings.TrimSpace(parts[0])
|
name := strings.TrimSpace(parts[0])
|
||||||
var enabled bool
|
var stream Stream
|
||||||
enabled, err = c.GetOutput(name)
|
stream.Type = parts[1][7:]
|
||||||
if err != nil {
|
enabled, err := c.GetOutput(name)
|
||||||
return
|
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
|
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
|
// SetOutput enables or disables an output
|
||||||
func (c *Client) SetOutput(name string, enabled bool) error {
|
func (c *Client) SetOutput(name string, enabled bool) error {
|
||||||
action := "stop"
|
action := "stop"
|
||||||
|
|
Loading…
Reference in a new issue