word on liquidsoap interface

This commit is contained in:
bkfox
2015-11-17 11:28:21 +01:00
parent 4fbd30a460
commit 64c59f22ab
8 changed files with 562 additions and 113 deletions

View File

@ -0,0 +1,14 @@
{% with metadata=source.metadata %}
<div class="source {% if metadata.initial_uri == controller.master.metadata.initial_uri %}on_air{% endif %}">
<h2>{{ source.name }}</h2>
<time>{{ metadata.on_air }}</time>
<span class="path">{{ metadata.initial_uri }}</span>
<span class="status" status="{{ metadata.status }}">{{ metadata.status }}</span>
<button onclick="liquid_action('{{controller.id}}','{{source.id}}','skip');">
skip
</button>
</div>
{% endwith %}

View File

@ -0,0 +1,31 @@
{# Utilities #}
def interactive_source (id, s, ) = \
def apply_metadata(m) = \
m = json_of(compact=true, m) \
ignore(interactive.string('#{id}_meta', m)) \
end \
\
s = on_metadata(id = id, apply_metadata, s) \
add_skip_command(s) \
s \
end \
\
def stream (id, file) = \
s = playlist(id = '#{id}_playlist', mode = "random", file) \
interactive_source(id, s) \
end \
\
{# Config #}
set("server.socket", true) \
set("server.socket.path", "{{ settings.AIRCOX_LIQUIDSOAP_SOCKET }}") \
{% for key, value in settings.AIRCOX_LIQUIDSOAP_SET.items %}
set("{{ key|safe }}", {{ value|safe }}) \
{% endfor %}
\
\
{% for controller in monitor.controllers.values %}
{% include 'aircox_liquidsoap/station.liq' %} \
{{ controller.id }} = make_station_{{ controller.id }}() \
output.alsa({{ controller.id }}) \
{% endfor %}

View File

@ -1,11 +1,129 @@
{% if not embed %}
<html>
<head>
<style>
.station {
margin: 2em;
border: 1px grey solid;
}
{% for station in stations %}
{% for name, source in station.sources.items %}
<div class="source">
{{ name }}:
{{ source.initial_uri }}
<time style="font-size: 0.9em; color: grey">{{ source.on_air }}</time>
</div>
{% endfor %}
{% endfor %}
.sources {
padding: 0.5em;
box-shadow: inset 0.1em 0.1em 0.5em rgba(0, 0, 0, 0.5);
}
.station h1 {
font-size: 1.2em;
margin: 0.2em;
}
.source {
border-left: 0.5em solid grey;
font-size: 0.9em;
}
.on_air {
display: block;
border-left: 0.5em solid #f00;
}
.source h2 {
display: inline-block;
min-width: 10em;
font-size: 1em;
margin: 0.2em;
}
.source time {
display: inline-block;
margin-right: 2em;
}
.source span {
font-size: 1em;
}
.error {
padding: 0.2em;
color: red;
font-weight: bold;
}
</style>
<script>
function get_token() {
return document.cookie.replace(/.*csrftoken=([^;]+)(;.*|$)/, '$1');
}
function liquid_action (controller, source, action) {
params = 'controller=' + controller + '&&source=' + source +
'&&action=' + action;
req = new XMLHttpRequest()
req.open('POST', '{% url 'liquid-controller' %}', false);
req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
req.setRequestHeader("Content-length", params.length);
req.setRequestHeader("Connection", "close");
req.setRequestHeader("X-CSRFToken", get_token());
req.send(params);
liquid_update()
}
function liquid_update (update) {
req = new XMLHttpRequest()
req.open('GET', '{% url 'liquid-controller' %}?embed', true);
req.onreadystatechange = function() {
if(req.readyState != 4 || (req.status != 200 && req.status != 0))
return;
document.getElementById('liquid-stations').innerHTML =
req.responseText;
if(update)
window.setTimeout(function() { liquid_update(update);}, 5000);
};
req.send();
}
liquid_update(true);
</script>
</head>
<body>
<main id="liquid-stations">
{% endif %}
{% for c_id, controller in monitor.controllers.items %}
{% with on_air=controller.on_air %}
<div id="{{ c_id }}" class="station">
<header>
{% if not controller.connector.available %}
<span class="error" style="float:right;">disconnected</span>
{% endif %}
<h1>
{{ controller.station.name }}
</h1>
</header>
<div class="sources">
{% with source=controller.master %}
{% include 'aircox_liquidsoap/base_source.html' %}
{% endwith %}
{% with source=controller.dealer %}
{% include 'aircox_liquidsoap/base_source.html' %}
{% endwith %}
{% for source in controller.streams.values %}
{% include 'aircox_liquidsoap/base_source.html' %}
{% endfor %}
</div>
</div>
{% endwith %}
{% endfor %}
{% if not embed %}
</main>
</body>
</html>
{% endif %}

View File

@ -5,54 +5,50 @@ A station has multiple sources:
- streams: a rotate source with all playlists
- single: security song
{% endcomment %}
{% with name=station.name streams=station.streams %}
def make_station_{{ name }} () = \
def make_station_{{ controller.id }} () = \
{# dealer #}
dealer = interactive_source('{{ name }}_dealer', playlist.once( \
{% with source=controller.dealer %}
{% if source %}
dealer = interactive_source('{{ source.id }}', playlist.once( \
reload_mode='watch', \
'/tmp/dealer.m3u', \
"{{ source.path }}", \
)) \
\
dealer_on = interactive.bool("{{ name }}_dealer_on", false) \
dealer_on = interactive.bool("{{ source.id }}_on", false) \
{% endif %}
{% endwith %}
\
{# streams #}
streams = interactive_source("streams", rotate([ \
{% for stream in streams %}
{% if stream.delay %}
delay({{ stream.delay }}., stream("{{ name }}_{{ stream.name }}", "{{ stream.file }}")), \
{% for source in controller.streams.values %}
{% with info=source.stream_info %}
{% if info.delay %}
delay({{ info.delay }}., stream("{{ source.id }}", "{{ source.path }}")), \
{% elif info.begin and info.end %}
at({ {{info.begin}}-{{info.end}} }, stream("{{ source.id }}", "{{ source.path }}")), \
{% endif %}
{% endwith %}
{% endfor %}
switch([ \
{% for stream in streams %}
{% if stream.begin and stream.end %}
({ stream.begin, stream.end }, stream("{{ name }}_{{ stream.name }}", "{{ stream.file }}")), \
{% endif %}
{% endfor %}
]), \
{% for stream in streams %}
{% if not stream.delay %}
{% if not stream.begin or not stream.end %}
stream("{{ name }}_{{ stream.name }}", "{{ stream.file }}"), \
{% endif %}
{% for source in controller.streams.values %}
{% if not source.stream_info %}
stream("{{ source.id }}", "{{ source.path }}"), \
{% endif %}
{% endfor %}
])) \
\
{# station #}
interactive_source ( \
"{{ name }}", \
"{{ controller.id }}", \
fallback(track_sensitive = false, [ \
at(dealer_on, dealer), \
{% if station.fallback %}
streams, \
single("{{ station.fallback }}") \
{% if controller.station.fallback %}
single("{{ controller.station.fallback }}"), \
{% else %}
mksafe(streams) \
blank(), \
{% endif %}
]) \
) \
end \
{% endwith %}