migration of Sounds; Liquidsoap 2.4 compatibility
This commit is contained in:
@ -77,9 +77,12 @@ class Metadata:
|
||||
air_time = tz.datetime.strptime(air_time, "%Y/%m/%d %H:%M:%S")
|
||||
return local_tz.localize(air_time)
|
||||
|
||||
def validate(self, data):
|
||||
def validate(self, data, as_dict=False):
|
||||
"""Validate provided data and set as attribute (must already be
|
||||
declared)"""
|
||||
if as_dict and isinstance(data, list):
|
||||
data = {v[0]: v[1] for v in data}
|
||||
|
||||
for key, value in data.items():
|
||||
if hasattr(self, key) and not callable(getattr(self, key)):
|
||||
setattr(self, key, value)
|
||||
|
@ -43,9 +43,9 @@ class Source(Metadata):
|
||||
except ValueError:
|
||||
self.remaining = None
|
||||
|
||||
data = self.controller.send(self.id, ".get", parse=True)
|
||||
data = self.controller.send(f"var.get {self.id}_meta", parse_json=True)
|
||||
if data:
|
||||
self.validate(data if data and isinstance(data, dict) else {})
|
||||
self.validate(data if data and isinstance(data, (dict, list)) else {}, as_dict=True)
|
||||
|
||||
def skip(self):
|
||||
"""Skip the current source sound."""
|
||||
|
@ -8,8 +8,7 @@ import subprocess
|
||||
import psutil
|
||||
from django.template.loader import render_to_string
|
||||
|
||||
from aircox.conf import settings
|
||||
|
||||
from ..conf import settings
|
||||
from ..connector import Connector
|
||||
from .sources import PlaylistSource, QueueSource
|
||||
|
||||
@ -46,8 +45,8 @@ class Streamer:
|
||||
self.outputs = self.station.port_set.active().output()
|
||||
|
||||
self.id = self.station.slug.replace("-", "_")
|
||||
self.path = os.path.join(station.path, "station.liq")
|
||||
self.connector = connector or Connector(os.path.join(station.path, "station.sock"))
|
||||
self.path = settings.get_dir(station, "station.liq")
|
||||
self.connector = connector or Connector(settings.get_dir(station, "station.sock"))
|
||||
self.init_sources()
|
||||
|
||||
@property
|
||||
@ -98,7 +97,6 @@ class Streamer:
|
||||
{
|
||||
"station": self.station,
|
||||
"streamer": self,
|
||||
"settings": settings,
|
||||
},
|
||||
)
|
||||
data = re.sub("[\t ]+\n", "\n", data)
|
||||
|
@ -19,7 +19,7 @@ from aircox_streamer.controllers import Monitor, Streamer
|
||||
|
||||
|
||||
# force using UTC
|
||||
tz.activate(timezone.UTC)
|
||||
tz.activate(timezone.utc)
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
|
@ -10,9 +10,9 @@ Base liquidsoap station configuration.
|
||||
|
||||
{% block functions %}
|
||||
{# Seek function #}
|
||||
def seek(source, t) =
|
||||
def seek(s, t) =
|
||||
t = float_of_string(default=0.,t)
|
||||
ret = source.seek(source,t)
|
||||
ret = source.seek(s,t)
|
||||
log("seek #{ret} seconds.")
|
||||
"#{ret}"
|
||||
end
|
||||
@ -30,6 +30,17 @@ def to_stream(live, stream)
|
||||
add(normalize=false, [live,stream])
|
||||
end
|
||||
|
||||
{# Skip command #}
|
||||
def add_skip_command(s) =
|
||||
def skip(_) =
|
||||
source.skip(s)
|
||||
"Done!"
|
||||
end
|
||||
server.register(namespace="#{source.id(s)}",
|
||||
usage="skip",
|
||||
description="Skip the current song.",
|
||||
"skip",skip)
|
||||
end
|
||||
|
||||
{% comment %}
|
||||
An interactive source is a source that:
|
||||
@ -45,10 +56,14 @@ def interactive (id, s) =
|
||||
server.register(namespace=id,
|
||||
description="Get source's track remaining time",
|
||||
usage="remaining",
|
||||
"remaining", fun (_) -> begin json_of(source.remaining(s)) end)
|
||||
"remaining", fun (_) -> begin json.stringify(source.remaining(s)) end)
|
||||
|
||||
s = store_metadata(id=id, size=1, s)
|
||||
add_skip_command(s)
|
||||
|
||||
{# metadata: create an interactive variable as "{id}_meta" #}
|
||||
s_meta = interactive.string("#{id}_meta", "")
|
||||
s = source.on_metadata(s, fun(meta) -> s_meta.set(json.stringify(meta)))
|
||||
|
||||
s
|
||||
end
|
||||
|
||||
@ -66,9 +81,6 @@ end
|
||||
set("server.socket", true)
|
||||
set("server.socket.path", "{{ streamer.socket_path }}")
|
||||
set("log.file.path", "{{ station.path }}/liquidsoap.log")
|
||||
{% for key, value in settings.AIRCOX_LIQUIDSOAP_SET.items %}
|
||||
set("{{ key|safe }}", {{ value|safe }})
|
||||
{% endfor %}
|
||||
{% endblock %}
|
||||
|
||||
{% block config_extras %}
|
||||
|
Reference in New Issue
Block a user