fix config, add controler

This commit is contained in:
bkfox 2015-11-09 14:38:44 +01:00
parent c5c566d485
commit ecde02725e
5 changed files with 58 additions and 27 deletions

View File

@ -90,30 +90,27 @@ class Command (BaseCommand):
file.write(data)
@staticmethod
def __render_stream_in_radio (stream):
if stream.time_start and stream.time_end:
data = '({{{}-{}}}, {})'.format(
stream.time_start.strftime('%Hh%M'),
stream.time_end.strftime('%Hh%M'),
stream.program.get_slug_name()
)
else:
data = stream.program.get_slug_name()
def liquid_stream (stream):
def to_seconds (time):
return 3600 * time.hour + 60 * time.minute + time.second
if stream.delay:
data = 'delay({}., {})'.format(
3600*stream.delay.hour+60*stream.delay.minute+stream.delay.second,
data
)
return data
return {
'name': stream.program.get_slug_name(),
'begin': stream.begin.strftime('%Hh%M') if stream.begin else None,
'end': stream.end.strftime('%Hh%M') if stream.end else None,
'delay': to_seconds(stream.delay) if stream.delay else None,
'file': '{}/stream_{}.m3u'.format(
settings.AIRCOX_LIQUIDSOAP_MEDIA,
stream.pk,
)
}
def get_config (self, output = None):
streams = models.Stream.objects.filter(program__active = True)
for stream in streams:
stream.render_in_radio = self.__render_stream_in_radio(stream)
context = {
'streams': streams,
'streams': [
self.liquid_stream(stream)
for stream in models.Stream.objects.filter(program__active = True)
],
'settings': settings,
}

View File

@ -5,11 +5,11 @@ def ensure (key, default):
globals()[key] = getattr(settings, key, default)
ensure('AIRCOX_LIQUIDSOAP_SOCKET', '/tmp/liquidsoap.sock')
# dict of values to set (do not forget to escape chars)
ensure('AIRCOX_LIQUIDSOAP_SET', {
'log.file.path': '"/tmp/liquidsoap.log"',
'server.socket': 'true',
'server.socket.path': '"/tmp/liquidsoap.sock"'
})
# security source: used when no source are available

View File

@ -0,0 +1,34 @@
import socket
import aircox_liquidsoap.settings as settings
class Controller:
socket = None
available = False
def __init__ (self):
self.socket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
def open (self):
if self.available:
return
address = settings.AIRCOX_LIQUIDSOAP_SOCKET
try:
self.socket.connect(address)
self.available = True
except:
print('can not connect to liquidsoap socket {}'.format(address))
self.available = False
return -1
def send (self, data):
if self.open():
return -1
data = bytes(data + '\n', encoding='utf-8')
self.socket.sendall(data)
return self.socket.recv(10240).decode('utf-8')
def get (self, stream = None):
print(self.send('station.get'))

View File

@ -24,7 +24,7 @@ class ScheduleInline (admin.TabularInline):
extra = 1
class StreamInline (admin.TabularInline):
fields = ['delay', 'time_start', 'time_end']
fields = ['delay', 'begin', 'end']
model = Stream
extra = 1
@ -64,7 +64,7 @@ class SoundAdmin (NameableAdmin):
@admin.register(Stream)
class StreamAdmin (admin.ModelAdmin):
list_display = ('id', 'program', 'delay', 'time_start', 'time_end')
list_display = ('id', 'program', 'delay', 'begin', 'end')
@admin.register(Program)

View File

@ -201,13 +201,13 @@ class Stream (models.Model):
blank = True, null = True,
help_text = _('plays this playlist at least every delay')
)
time_start = models.TimeField(
_('start'),
begin = models.TimeField(
_('begin'),
blank = True, null = True,
help_text = _('used to define a time range this stream is'
'played')
)
time_end = models.TimeField(
end = models.TimeField(
_('end'),
blank = True, null = True,
help_text = _('used to define a time range this stream is'