fix config, add controler
This commit is contained in:
parent
c5c566d485
commit
ecde02725e
|
@ -90,30 +90,27 @@ class Command (BaseCommand):
|
||||||
file.write(data)
|
file.write(data)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def __render_stream_in_radio (stream):
|
def liquid_stream (stream):
|
||||||
if stream.time_start and stream.time_end:
|
def to_seconds (time):
|
||||||
data = '({{{}-{}}}, {})'.format(
|
return 3600 * time.hour + 60 * time.minute + time.second
|
||||||
stream.time_start.strftime('%Hh%M'),
|
|
||||||
stream.time_end.strftime('%Hh%M'),
|
|
||||||
stream.program.get_slug_name()
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
data = stream.program.get_slug_name()
|
|
||||||
|
|
||||||
if stream.delay:
|
return {
|
||||||
data = 'delay({}., {})'.format(
|
'name': stream.program.get_slug_name(),
|
||||||
3600*stream.delay.hour+60*stream.delay.minute+stream.delay.second,
|
'begin': stream.begin.strftime('%Hh%M') if stream.begin else None,
|
||||||
data
|
'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,
|
||||||
)
|
)
|
||||||
return data
|
}
|
||||||
|
|
||||||
def get_config (self, output = None):
|
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 = {
|
context = {
|
||||||
'streams': streams,
|
'streams': [
|
||||||
|
self.liquid_stream(stream)
|
||||||
|
for stream in models.Stream.objects.filter(program__active = True)
|
||||||
|
],
|
||||||
'settings': settings,
|
'settings': settings,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,11 +5,11 @@ def ensure (key, default):
|
||||||
globals()[key] = getattr(settings, 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)
|
# dict of values to set (do not forget to escape chars)
|
||||||
ensure('AIRCOX_LIQUIDSOAP_SET', {
|
ensure('AIRCOX_LIQUIDSOAP_SET', {
|
||||||
'log.file.path': '"/tmp/liquidsoap.log"',
|
'log.file.path': '"/tmp/liquidsoap.log"',
|
||||||
'server.socket': 'true',
|
|
||||||
'server.socket.path': '"/tmp/liquidsoap.sock"'
|
|
||||||
})
|
})
|
||||||
|
|
||||||
# security source: used when no source are available
|
# security source: used when no source are available
|
||||||
|
|
34
aircox_liquidsoap/utils.py
Normal file
34
aircox_liquidsoap/utils.py
Normal 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'))
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@ class ScheduleInline (admin.TabularInline):
|
||||||
extra = 1
|
extra = 1
|
||||||
|
|
||||||
class StreamInline (admin.TabularInline):
|
class StreamInline (admin.TabularInline):
|
||||||
fields = ['delay', 'time_start', 'time_end']
|
fields = ['delay', 'begin', 'end']
|
||||||
model = Stream
|
model = Stream
|
||||||
extra = 1
|
extra = 1
|
||||||
|
|
||||||
|
@ -64,7 +64,7 @@ class SoundAdmin (NameableAdmin):
|
||||||
|
|
||||||
@admin.register(Stream)
|
@admin.register(Stream)
|
||||||
class StreamAdmin (admin.ModelAdmin):
|
class StreamAdmin (admin.ModelAdmin):
|
||||||
list_display = ('id', 'program', 'delay', 'time_start', 'time_end')
|
list_display = ('id', 'program', 'delay', 'begin', 'end')
|
||||||
|
|
||||||
|
|
||||||
@admin.register(Program)
|
@admin.register(Program)
|
||||||
|
|
|
@ -201,13 +201,13 @@ class Stream (models.Model):
|
||||||
blank = True, null = True,
|
blank = True, null = True,
|
||||||
help_text = _('plays this playlist at least every delay')
|
help_text = _('plays this playlist at least every delay')
|
||||||
)
|
)
|
||||||
time_start = models.TimeField(
|
begin = models.TimeField(
|
||||||
_('start'),
|
_('begin'),
|
||||||
blank = True, null = True,
|
blank = True, null = True,
|
||||||
help_text = _('used to define a time range this stream is'
|
help_text = _('used to define a time range this stream is'
|
||||||
'played')
|
'played')
|
||||||
)
|
)
|
||||||
time_end = models.TimeField(
|
end = models.TimeField(
|
||||||
_('end'),
|
_('end'),
|
||||||
blank = True, null = True,
|
blank = True, null = True,
|
||||||
help_text = _('used to define a time range this stream is'
|
help_text = _('used to define a time range this stream is'
|
||||||
|
|
Loading…
Reference in New Issue
Block a user