feat(playout): use liquidsoap interactive variables

This commit is contained in:
jo 2023-02-20 22:01:24 +01:00 committed by Jonas L
parent 394cf68b61
commit 654259824c
5 changed files with 58 additions and 58 deletions

View File

@ -27,17 +27,17 @@ end
# A function applied to each metadata chunk # A function applied to each metadata chunk
def append_title(m) = def append_title(m) =
log("Using stream_format #{!stream_metadata_type}") log("Using message format #{message_format()}")
if list.mem_assoc("mapped", m) then if list.mem_assoc("mapped", m) then
#protection against applying this function twice. It shouldn't be happening #protection against applying this function twice. It shouldn't be happening
#and bug file with Liquidsoap. #and bug file with Liquidsoap.
m m
else else
if !stream_metadata_type == 1 then if message_format() == "1" then
[("title", "#{!show_name} - #{m['artist']} - #{m['title']}"), ("mapped", "true")] [("title", "#{show_name()} - #{m['artist']} - #{m['title']}"), ("mapped", "true")]
elsif !stream_metadata_type == 2 then elsif message_format() == "2" then
[("title", "#{!station_name} - #{!show_name}"), ("mapped", "true")] [("title", "#{station_name()} - #{show_name()}"), ("mapped", "true")]
else else
if "#{m['artist']}" == "" then if "#{m['artist']}" == "" then
[("title", "#{m['title']}"), ("mapped", "true")] [("title", "#{m['title']}"), ("mapped", "true")]
@ -50,10 +50,16 @@ end
def transition(a,b) = def transition(a,b) =
log("transition called...") log("transition called...")
add(normalize=false, add(
[ sequence([ blank(duration=0.01), normalize=false,
fade.initial(duration=!default_dj_fade, b) ]), [
fade.final(duration=!default_dj_fade, a) ]) sequence([
blank(duration=0.01),
fade.initial(duration=input_fade_transition(), b)
]),
fade.final(duration=input_fade_transition(), a)
]
)
end end
# we need this function for special transition case(from default to queue) # we need this function for special transition case(from default to queue)
@ -63,10 +69,16 @@ def transition_default(a,b) =
log("transition called...") log("transition called...")
if !just_switched then if !just_switched then
just_switched := false just_switched := false
add(normalize=false, add(
[ sequence([ blank(duration=0.01), normalize=false,
fade.initial(duration=!default_dj_fade, b) ]), [
fade.final(duration=!default_dj_fade, a) ]) sequence([
blank(duration=0.01),
fade.initial(duration=input_fade_transition(), b)
]),
fade.final(duration=input_fade_transition(), a)
]
)
else else
just_switched := false just_switched := false
b b
@ -90,12 +102,12 @@ def output_to(output_type, type, bitrate, host, port, pass, mount_point, url, de
source = ref s source = ref s
def on_error(msg) def on_error(msg)
connected := "false" connected := "false"
gateway("stream '#{stream}' '#{!time}' --error='#{msg}'") gateway("stream '#{stream}' '#{boot_timestamp()}' --error='#{msg}'")
5. 5.
end end
def on_connect() def on_connect()
connected := "true" connected := "true"
gateway("stream '#{stream}' '#{!time}'") gateway("stream '#{stream}' '#{boot_timestamp()}'")
end end
stereo = (channels == "stereo") stereo = (channels == "stereo")

View File

@ -1,4 +1,4 @@
time = ref string_of(gettimeofday()) boot_timestamp = interactive.string("boot_timestamp", string_of(gettimeofday()))
#Dynamic source list #Dynamic source list
#dyn_sources = ref [] #dyn_sources = ref []
@ -6,7 +6,7 @@ webstream_enabled = ref false
current_dyn_id = ref '-1' current_dyn_id = ref '-1'
show_name = ref '' show_name = interactive.string("show_name", "")
dynamic_metadata_callback = ref fun (~new_track=false, s) -> begin () end dynamic_metadata_callback = ref fun (~new_track=false, s) -> begin () end
@ -76,27 +76,9 @@ stream_queue = map_metadata(update=false, append_title, stream_queue)
ignore(output.dummy(stream_queue, fallible=true)) ignore(output.dummy(stream_queue, fallible=true))
server.register(namespace="vars",
"stream_metadata_type",
fun (s) -> begin log("vars.stream_metadata_type") stream_metadata_type := int_of_string(s) s end)
server.register(namespace="vars",
"show_name",
fun (s) -> begin log("vars.show_name") show_name := s s end)
server.register(namespace="vars",
"station_name",
fun (s) -> begin log("vars.station_name") station_name := s s end)
server.register(namespace="vars",
"off_air_meta",
fun (s) -> begin log("vars.off_air_meta") off_air_meta := s s end)
server.register(namespace="vars",
"bootup_time",
fun (s) -> begin log("vars.bootup_time") time := s s end)
server.register(namespace="streams", server.register(namespace="streams",
"connection_status", "connection_status",
fun (s) -> begin log("streams.connection_status") "1:#{!s1_connected},2:#{!s2_connected},3:#{!s3_connected},4:#{!s4_connected}" end) fun (s) -> begin log("streams.connection_status") "1:#{!s1_connected},2:#{!s2_connected},3:#{!s3_connected},4:#{!s4_connected}" end)
server.register(namespace="vars",
"default_dj_fade",
fun (s) -> begin log("vars.default_dj_fade") default_dj_fade := float_of_string(s) s end)
server.register(namespace="dynamic_source", server.register(namespace="dynamic_source",
description="Enable webstream output", description="Enable webstream output",
@ -141,13 +123,12 @@ server.register(namespace="dynamic_source",
# fun (s) -> begin log("dynamic_source.read_stop") destroy_dynamic_source_all() end) # fun (s) -> begin log("dynamic_source.read_stop") destroy_dynamic_source_all() end)
default = amplify(id="silence_src", 0.00001, noise()) default = amplify(id="silence_src", 0.00001, noise())
if !off_air_meta == "" then
off_air_meta := "LibreTime - offline" def map_message_offline(m) =
[("title", message_offline())]
end end
def map_off_air_meta(m) =
[("title", !off_air_meta)] default = map_metadata(map_message_offline, default)
end
default = map_metadata(map_off_air_meta, default)
ignore(output.dummy(default, fallible=true)) ignore(output.dummy(default, fallible=true))
master_dj_enabled = ref false master_dj_enabled = ref false

View File

@ -5,6 +5,8 @@ from typing import Any, Literal, Optional, Tuple
from loguru import logger from loguru import logger
from ..models import MessageFormatKind
from ..utils import quote
from ..version import parse_liquidsoap_version from ..version import parse_liquidsoap_version
from ._connection import LiquidsoapConnection from ._connection import LiquidsoapConnection
@ -36,9 +38,14 @@ class LiquidsoapClient:
timeout=timeout, timeout=timeout,
) )
def _quote(self, value: Any):
return quote(value, double=True)
def _set_var(self, name: str, value: Any): def _set_var(self, name: str, value: Any):
self.conn.write(f"vars.{name} {value}") self.conn.write(f"var.set {name} = {value}")
self.conn.read() result = self.conn.read()
if f"Variable {name} set" not in result:
logger.error(result)
def version(self) -> Tuple[int, int, int]: def version(self) -> Tuple[int, int, int]:
with self.conn: with self.conn:
@ -71,7 +78,7 @@ class LiquidsoapClient:
def queue_push(self, queue_id: int, entry: str, show_name: str) -> None: def queue_push(self, queue_id: int, entry: str, show_name: str) -> None:
with self.conn: with self.conn:
self.conn.write(f"{queue_id}.push {entry}") self.conn.write(f"{queue_id}.push {entry}")
self._set_var("show_name", show_name) self._set_var("show_name", self._quote(show_name))
def web_stream_get_id(self) -> str: def web_stream_get_id(self) -> str:
with self.conn: with self.conn:
@ -118,23 +125,23 @@ class LiquidsoapClient:
self, self,
*, *,
station_name: Optional[str] = None, station_name: Optional[str] = None,
message_format: Optional[int] = None, message_format: Optional[MessageFormatKind] = None,
message_offline: Optional[str] = None, message_offline: Optional[str] = None,
input_fade_transition: Optional[float] = None, input_fade_transition: Optional[float] = None,
): ):
with self.conn: with self.conn:
if station_name is not None: if station_name is not None:
self._set_var("station_name", station_name) self._set_var("station_name", self._quote(station_name))
if message_format is not None: if message_format is not None:
self._set_var("stream_metadata_type", message_format) self._set_var("message_format", self._quote(message_format.value))
if message_offline is not None: if message_offline is not None:
self._set_var("off_air_meta", message_offline) self._set_var("message_offline", self._quote(message_offline))
if input_fade_transition is not None: if input_fade_transition is not None:
self._set_var("default_dj_fade", input_fade_transition) self._set_var("input_fade_transition", input_fade_transition)
def boot_timestamp_update(self, timestamp: float): def boot_timestamp_update(self, timestamp: float):
with self.conn: with self.conn:
self._set_var("bootup_time", str(timestamp)) self._set_var("boot_timestamp", self._quote(timestamp))
def restart(self): def restart(self):
logger.warning("restarting Liquidsoap") logger.warning("restarting Liquidsoap")

View File

@ -49,10 +49,10 @@ set("server.telnet.port", {{ config.liquidsoap.server_listen_port }})
set("harbor.bind_addrs", ["{{ config.liquidsoap.harbor_listen_address | join('", "') }}"]) set("harbor.bind_addrs", ["{{ config.liquidsoap.harbor_listen_address | join('", "') }}"])
station_name = ref {{ info.station_name | quote }} station_name = interactive.string("station_name", {{ info.station_name | quote }})
off_air_meta = ref {{ preferences.message_offline | quote }} message_offline = interactive.string("message_offline", {{ preferences.message_offline | quote }})
stream_metadata_type = ref {{ preferences.message_format.value }} message_format = interactive.string("message_format", {{ preferences.message_format.value | quote }})
default_dj_fade = ref {{ preferences.input_fade_transition }} input_fade_transition = interactive.float("input_fade_transition", {{ preferences.input_fade_transition }})
%include "{{ paths.lib_filepath }}" %include "{{ paths.lib_filepath }}"

View File

@ -100,11 +100,11 @@
set("harbor.bind_addrs", ["0.0.0.0"]) set("harbor.bind_addrs", ["0.0.0.0"])
station_name = ref "LibreTime" station_name = interactive.string("station_name", "LibreTime")
off_air_meta = ref "LibreTime - offline" message_offline = interactive.string("message_offline", "LibreTime - offline")
stream_metadata_type = ref 0 message_format = interactive.string("message_format", "0")
default_dj_fade = ref 0.0 input_fade_transition = interactive.float("input_fade_transition", 0.0)
%include "/fake/1.4/ls_script.liq" %include "/fake/1.4/ls_script.liq"