work on liquidsoap script (fix & fade) + fix errors in monitor

This commit is contained in:
bkfox 2016-08-02 19:46:31 +02:00
parent d62a47ffe5
commit f5dbc93f7f
9 changed files with 126 additions and 65 deletions

View File

@ -530,9 +530,10 @@ class SectionItemMeta(models.base.ModelBase):
cl = super().__new__(cls, name, bases, attrs) cl = super().__new__(cls, name, bases, attrs)
if not 'template' in attrs: if not 'template' in attrs:
cl.snake_name = camelcase_to_underscore(name)
cl.template = '{}/sections/{}.html'.format( cl.template = '{}/sections/{}.html'.format(
cl._meta.app_label, cl._meta.app_label,
camelcase_to_underscore(name), cl.snake_name,
) )
if name != 'SectionItem': if name != 'SectionItem':
try: try:

View File

@ -76,6 +76,11 @@ nav.menu {
display: inline-block; display: inline-block;
} }
.menu.top a {
display: inline-block;
margin: 0.2em 1em;
}
.page_left > section, .page_left > section,
.page_right > section { .page_right > section {
margin-bottom: 1em; margin-bottom: 1em;
@ -328,4 +333,3 @@ main .body ~ section:not(.comments) {
} }

View File

@ -87,7 +87,8 @@ main {
} }
main .content img.cover { main .content img.cover {
width: 100%; width: calc(100% + 2em);
margin-left: -1em;
} }

View File

@ -1,4 +1,4 @@
<section class="section_item {{ self.css_class }}"> <section class="section_item {{ self.css_class }} {{ self.snake_name }}">
{% block title %} {% block title %}
{% if self.show_title %}<h2>{{ self.title }}</h2>{% endif %} {% if self.show_title %}<h2>{{ self.title }}</h2>{% endif %}
{% endblock %} {% endblock %}

View File

@ -27,7 +27,6 @@ class Monitor:
""" """
def __init__(self, station, **kwargs): def __init__(self, station, **kwargs):
Log.objects.all().delete()
self.station = station self.station = station
self.__dict__.update(kwargs) self.__dict__.update(kwargs)
@ -169,7 +168,7 @@ class Monitor:
) )
sounds = [ sounds = [
sound.related.path for sound in sounds sound.related.path for sound in sounds
if not sound.related.removed if sound.related.type != programs.Sound.Type.removed
] ]
return ( return (
@ -229,8 +228,6 @@ class Monitor:
if next_diff and not dealer.controller.active and \ if next_diff and not dealer.controller.active and \
next_diff.start <= now: next_diff.start <= now:
dealer.controller.active = True dealer.controller.active = True
for source in station.get_sources():
source.controller.skip()
self.log( self.log(
type = Log.Type.play, type = Log.Type.play,
source = dealer.id_, source = dealer.id_,

View File

@ -19,6 +19,8 @@ position in order to do it. Keep in mind that you might want to avoid to
put station specific configuration in the template itself. put station specific configuration in the template itself.
{% endcomment %} {% endcomment %}
{% block functions %}
{% comment %} {% comment %}
An interactive source is a source that: An interactive source is a source that:
- is skippable through the given id on external interfaces - is skippable through the given id on external interfaces
@ -36,7 +38,7 @@ def interactive_source (id, s, ~active=true, ~disable_switch=false) =
end end
{% comment %} {% comment %}
a stream is a source that: A stream is a source that:
- is a playlist on random mode (playlist object accessible at {id}_playlist - is a playlist on random mode (playlist object accessible at {id}_playlist
- is interactive - is interactive
{% endcomment %} {% endcomment %}
@ -44,44 +46,45 @@ def stream (id, file) =
s = playlist(id = '#{id}_playlist', mode = "random", file) s = playlist(id = '#{id}_playlist', mode = "random", file)
interactive_source(id, s) interactive_source(id, s)
end end
{% block post_funcs %}
{% endblock %} {% endblock %}
{# config #} {% block functions_extras %}
{% endblock %}
{% block config %}
set("server.socket", true) set("server.socket", true)
set("server.socket.path", "{{ station.controller.socket_path }}") set("server.socket.path", "{{ station.controller.socket_path }}")
set("log.file.path", "{{ station.controller.station.path }}/liquidsoap.log") set("log.file.path", "{{ station.controller.station.path }}/liquidsoap.log")
{% for key, value in settings.AIRCOX_LIQUIDSOAP_SET.items %} {% for key, value in settings.AIRCOX_LIQUIDSOAP_SET.items %}
set("{{ key|safe }}", {{ value|safe }}) set("{{ key|safe }}", {{ value|safe }})
{% endfor %} {% endfor %}
{% endblock %}
{% block post_config %} {% block config_extras %}
{% endblock %} {% endblock %}
{# station #} {% block sources %}
{{ station.id_ }} = interactive_source ( live = fallback([
"{{ station.id_ }}",
fallback(track_sensitive = false, [
{% for source in station.file_sources %} {% for source in station.file_sources %}
{% with controller=source.controller %} {% with controller=source.controller %}
interactive_source( interactive_source(
'{{ source.id_ }}', single("{{ source.url }}"), '{{ source.id_ }}', single("{{ source.url }}"), active=false
active=false
), ),
{% endwith %} {% endwith %}
{% endfor %} {% endfor %}
{% with source=station.dealer %} {% with source=station.dealer controller=station.dealer.controller %}
{% with controller=source.controller %}
interactive_source('{{ source.id_ }}', interactive_source('{{ source.id_ }}',
playlist.once(reload_mode='watch', "{{ controller.path }}"), playlist.once(reload_mode='watch', "{{ controller.path }}"),
active=false active=false
), ),
{% endwith %} {% endwith %}
{% endwith %} ])
stream = fallback([
rotate([ rotate([
{% for source in station.stream_sources %} {% for source in station.stream_sources %}
{% with controller=source.controller stream=source.controller.stream %} {% with controller=source.controller stream=source.controller.stream %}
@ -105,9 +108,42 @@ set("{{ key|safe }}", {{ value|safe }})
{% endfor %} {% endfor %}
blank(id="blank_fallback", duration=0.1), blank(id="blank_fallback", duration=0.1),
]), ])
{% endblock %}
{% block sources_extras %}
{% endblock %}
def to_live(stream,live)
stream = fade.final(duration=2., type='log', stream)
live = fade.initial(duration=2., type='log', live)
add(normalize=false, [stream,live])
end
def to_stream(live,stream)
source.skip(stream)
add(normalize=false, [live,stream])
end
{% block station %}
{{ station.id_ }} = interactive_source (
"{{ station.id_ }}",
fallback(
track_sensitive=false,
transitions=[to_live,to_stream],
[ live, stream ]
),
disable_switch=true disable_switch=true
) )
{% endblock %}
{% block station_extras %}
{% endblock %}
{% block outputs %} {% block outputs %}
{% for output in station.outputs %} {% for output in station.outputs %}
@ -120,6 +156,6 @@ output.{{ output.get_type_display }}(
{% endfor %} {% endfor %}
{% endblock %} {% endblock %}
{% block post_output %} {% block output_extras %}
{% endblock %} {% endblock %}

View File

@ -54,8 +54,11 @@ var Monitor = {
return document.cookie.replace(/.*csrftoken=([^;]+)(;.*|$)/, '$1'); return document.cookie.replace(/.*csrftoken=([^;]+)(;.*|$)/, '$1');
}, },
post: function(station, action) { post: function(station, source, action) {
var params = 'station=' + station + '&&action=' + action; var params = 'station=' + station + '&&action=' + action;
if(source)
params += '&&source=' + source;
var req = new XMLHttpRequest() var req = new XMLHttpRequest()
req.open('POST', '{% url 'controllers.monitor' %}', false); req.open('POST', '{% url 'controllers.monitor' %}', false);
req.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
@ -66,8 +69,8 @@ var Monitor = {
this.update(); this.update();
}, },
skip: function(station) { skip: function(station, source) {
this.post(station, 'skip'); this.post(station, source, 'skip');
}, },
update: function(timeout) { update: function(timeout) {
@ -110,6 +113,8 @@ Monitor.update(1000);
<div class="source{% if source == station.controller.current_source %} current{% endif %}"> <div class="source{% if source == station.controller.current_source %} current{% endif %}">
<span class="name">{{ source.name }}</span> <span class="name">{{ source.name }}</span>
<span class="file">{{ source.controller.current_sound }}</span> <span class="file">{{ source.controller.current_sound }}</span>
<button onclick="Monitor.skip('{{ station.name }}','{{ source.name }}');">
{% trans "skip" %}</button>
</div> </div>
{% endif %} {% endif %}
{% endfor %} {% endfor %}

View File

@ -94,7 +94,7 @@ class Monitor(View,TemplateResponseMixin,LoginRequiredMixin):
if not request.user.is_active: if not request.user.is_active:
return Http404() return Http404()
if not 'action' in request.POST: if not ('action' or 'station') in request.POST:
return HttpResponse('') return HttpResponse('')
POST = request.POST POST = request.POST
@ -107,7 +107,21 @@ class Monitor(View,TemplateResponseMixin,LoginRequiredMixin):
return HttpResponse('') return HttpResponse('')
station.prepare(fetch=True) station.prepare(fetch=True)
source = None
if 'source' in POST:
source = station.source_set.filter(name = POST['source']) \
.first()
if not source and POST['source'] == station.dealer.name:
source = station.dealer
if source:
source.prepare()
if station and action == 'skip': if station and action == 'skip':
if source:
print('skip ', source)
source.controller.skip()
else:
station.controller.skip() station.controller.skip()
return HttpResponse('') return HttpResponse('')

View File

@ -591,7 +591,7 @@ class Program(Nameable):
class DiffusionManager(models.Manager): class DiffusionManager(models.Manager):
def get_at(self, date = None): def get_at(self, date = None, next = False):
""" """
Return a queryset of diffusions that have the given date Return a queryset of diffusions that have the given date
in their range. in their range.
@ -606,9 +606,12 @@ class DiffusionManager(models.Manager):
models.Q(end__contains = date) models.Q(end__contains = date)
) )
if not next:
return self.filter(start__lte = date, end__gte = date) \
.order_by('start')
return self.filter( return self.filter(
models.Q(start__lte = date, end__gte = date) | models.Q(start__lte = date, end__gte = date) |
# FIXME: should not be here?
models.Q(start__gte = date), models.Q(start__gte = date),
).order_by('start') ).order_by('start')