CC-2607: Ability to adjust stream bitrate, type, etc from UI
- removed debug code from NowPlayingController - New Form for streamsetting - Action created in PreferenceController
This commit is contained in:
parent
4f2b2dba6d
commit
cf55e92aa3
17 changed files with 701 additions and 103 deletions
|
@ -19,13 +19,24 @@ PIDFILE0=/var/run/airtime-playout.pid
|
|||
DAEMON1=/usr/lib/airtime/pypo/bin/airtime-liquidsoap
|
||||
PIDFILE1=/var/run/airtime-liquidsoap.pid
|
||||
|
||||
liquidsoap_start () {
|
||||
monit monitor airtime-liquidsoap >/dev/null 2>&1
|
||||
start-stop-daemon --start --background --quiet --chuid $USERID:$GROUPID \
|
||||
--nicelevel -15 --make-pidfile --pidfile $PIDFILE1 --startas $DAEMON1
|
||||
}
|
||||
|
||||
liquidsoap_stop () {
|
||||
# Send TERM after 5 seconds, wait at most 30 seconds.
|
||||
monit unmonitor airtime-liquidsoap >/dev/null 2>&1
|
||||
start-stop-daemon --stop --oknodo --retry TERM/5/0/30 --quiet --pidfile $PIDFILE1
|
||||
rm -f $PIDFILE1
|
||||
}
|
||||
|
||||
start () {
|
||||
monit monitor airtime-playout >/dev/null 2>&1
|
||||
start-stop-daemon --start --background --quiet --chuid $USERID:$GROUPID --make-pidfile --pidfile $PIDFILE0 --startas $DAEMON0
|
||||
|
||||
monit monitor airtime-liquidsoap >/dev/null 2>&1
|
||||
start-stop-daemon --start --background --quiet --chuid $USERID:$GROUPID \
|
||||
--nicelevel -15 --make-pidfile --pidfile $PIDFILE1 --startas $DAEMON1
|
||||
liquidsoap_start
|
||||
}
|
||||
|
||||
stop () {
|
||||
|
@ -35,12 +46,9 @@ stop () {
|
|||
start-stop-daemon --stop --oknodo --retry TERM/5/0/30 --quiet --pidfile $PIDFILE0
|
||||
rm -f $PIDFILE0
|
||||
|
||||
monit unmonitor airtime-liquidsoap >/dev/null 2>&1
|
||||
start-stop-daemon --stop --oknodo --retry TERM/5/0/30 --quiet --pidfile $PIDFILE1
|
||||
rm -f $PIDFILE1
|
||||
liquidsoap_stop
|
||||
}
|
||||
|
||||
|
||||
case "${1:-''}" in
|
||||
'start')
|
||||
# start commands here
|
||||
|
@ -65,6 +73,13 @@ case "${1:-''}" in
|
|||
# status commands here
|
||||
/usr/bin/airtime-check-system
|
||||
;;
|
||||
'restart-liquidsoap')
|
||||
# restart commands here
|
||||
echo -n "Restarting Liquidsoap: "
|
||||
liquidsoap_stop
|
||||
liquidsoap_start
|
||||
echo "Done."
|
||||
;;
|
||||
*) # no parameter specified
|
||||
echo "Usage: $SELF start|stop|restart|status"
|
||||
exit 1
|
||||
|
|
|
@ -114,26 +114,28 @@ try:
|
|||
p = Popen("update-rc.d airtime-playout defaults >/dev/null 2>&1", shell=True)
|
||||
sts = os.waitpid(p.pid, 0)[1]
|
||||
|
||||
#we should access the DB and generate liquidsoap.cfg under etc/airtime/
|
||||
# we should access the DB and generate liquidsoap.cfg under etc/airtime/
|
||||
api_client = api_client.api_client_factory(config)
|
||||
ss = api_client.get_stream_setting()
|
||||
data = ss['msg']
|
||||
fh = open('/etc/airtime/liquidsoap.cfg', 'w')
|
||||
for d in data:
|
||||
buffer = d[u'keyname'] + " = "
|
||||
if(d[u'type'] == 'string'):
|
||||
temp = d[u'value']
|
||||
if(temp == ""):
|
||||
temp = "dummy_string"
|
||||
buffer += "\"" + temp + "\""
|
||||
else:
|
||||
temp = d[u'value']
|
||||
if(temp == ""):
|
||||
temp = "0"
|
||||
buffer += temp
|
||||
buffer += "\n"
|
||||
fh.write(buffer)
|
||||
fh.close()
|
||||
# if api_client is somehow not working, just use original cfg file
|
||||
if(ss is not None):
|
||||
data = ss['msg']
|
||||
fh = open('/etc/airtime/liquidsoap.cfg', 'w')
|
||||
for d in data:
|
||||
buffer = d[u'keyname'] + " = "
|
||||
if(d[u'type'] == 'string'):
|
||||
temp = d[u'value']
|
||||
if(temp == ""):
|
||||
temp = ""
|
||||
buffer += "\"" + temp + "\""
|
||||
else:
|
||||
temp = d[u'value']
|
||||
if(temp == ""):
|
||||
temp = "0"
|
||||
buffer += temp
|
||||
buffer += "\n"
|
||||
fh.write(buffer)
|
||||
fh.close()
|
||||
|
||||
print "Waiting for processes to start..."
|
||||
p = Popen("/etc/init.d/airtime-playout start", shell=True)
|
||||
|
|
|
@ -50,8 +50,12 @@ def output_to(output_type, type, bitrate, host, port, pass, mount_point, url, de
|
|||
description = description,
|
||||
genre = genre)
|
||||
if type == "mp3" then
|
||||
if bitrate == 32 then
|
||||
if bitrate == 24 then
|
||||
ignore(output.icecast(%mp3(bitrate = 24),s))
|
||||
elsif bitrate == 32 then
|
||||
ignore(output.icecast(%mp3(bitrate = 32),s))
|
||||
elsif bitrate == 48 then
|
||||
ignore(output.icecast(%mp3(bitrate = 48),s))
|
||||
elsif bitrate == 64 then
|
||||
ignore(output.icecast(%mp3(bitrate = 64),s))
|
||||
elsif bitrate == 96 then
|
||||
|
@ -60,14 +64,26 @@ def output_to(output_type, type, bitrate, host, port, pass, mount_point, url, de
|
|||
ignore(output.icecast(%mp3(bitrate = 128),s))
|
||||
elsif bitrate == 160 then
|
||||
ignore(output.icecast(%mp3(bitrate = 160),s))
|
||||
elsif bitrate == 192 then
|
||||
ignore(output.icecast(%mp3(bitrate = 192),s))
|
||||
elsif bitrate == 224 then
|
||||
ignore(output.icecast(%mp3(bitrate = 224),s))
|
||||
elsif bitrate == 256 then
|
||||
ignore(output.icecast(%mp3(bitrate = 256),s))
|
||||
elsif bitrate == 320 then
|
||||
ignore(output.icecast(%mp3(bitrate = 320),s))
|
||||
end
|
||||
else
|
||||
source = ref s
|
||||
if not output_icecast_vorbis_metadata then
|
||||
source := add(normalize=false, [amplify(0.00001, noise()),s])
|
||||
end
|
||||
if bitrate == 32 then
|
||||
if bitrate == 24 then
|
||||
ignore(output.icecast(%vorbis.cbr(bitrate = 24),!source))
|
||||
elsif bitrate == 32 then
|
||||
ignore(output.icecast(%vorbis.cbr(bitrate = 32),!source))
|
||||
elsif bitrate == 48 then
|
||||
ignore(output.icecast(%vorbis.cbr(bitrate = 48),!source))
|
||||
elsif bitrate == 64 then
|
||||
ignore(output.icecast(%vorbis.cbr(bitrate = 64),!source))
|
||||
elsif bitrate == 96 then
|
||||
|
@ -76,6 +92,14 @@ def output_to(output_type, type, bitrate, host, port, pass, mount_point, url, de
|
|||
ignore(output.icecast(%vorbis.cbr(bitrate = 128),!source))
|
||||
elsif bitrate == 160 then
|
||||
ignore(output.icecast(%vorbis.cbr(bitrate = 160),!source))
|
||||
elsif bitrate == 192 then
|
||||
ignore(output.icecast(%vorbis.cbr(bitrate = 192),!source))
|
||||
elsif bitrate == 224 then
|
||||
ignore(output.icecast(%vorbis.cbr(bitrate = 224),!source))
|
||||
elsif bitrate == 256 then
|
||||
ignore(output.icecast(%vorbis.cbr(bitrate = 256),!source))
|
||||
elsif bitrate == 320 then
|
||||
ignore(output.icecast(%vorbis.cbr(bitrate = 320),!source))
|
||||
end
|
||||
end
|
||||
else
|
||||
|
@ -87,17 +111,29 @@ def output_to(output_type, type, bitrate, host, port, pass, mount_point, url, de
|
|||
restart_delay = 5,
|
||||
url = url,
|
||||
genre = genre)
|
||||
if bitrate == 32 then
|
||||
ignore(output.shoutcast(%mp3(bitrate = 32),s))
|
||||
elsif bitrate == 64 then
|
||||
ignore(output.shoutcast(%mp3(bitrate = 64),s))
|
||||
elsif bitrate == 96 then
|
||||
ignore(output.shoutcast(%mp3(bitrate = 96),s))
|
||||
elsif bitrate == 128 then
|
||||
ignore(output.shoutcast(%mp3(bitrate = 128),s))
|
||||
elsif bitrate == 160 then
|
||||
ignore(output.shoutcast(%mp3(bitrate = 160),s))
|
||||
end
|
||||
if bitrate == 24 then
|
||||
ignore(output.shoutcast(%mp3(bitrate = 24),s))
|
||||
elsif bitrate == 32 then
|
||||
ignore(output.shoutcast(%mp3(bitrate = 32),s))
|
||||
elsif bitrate == 48 then
|
||||
ignore(output.shoutcast(%mp3(bitrate = 48),s))
|
||||
elsif bitrate == 64 then
|
||||
ignore(output.shoutcast(%mp3(bitrate = 64),s))
|
||||
elsif bitrate == 96 then
|
||||
ignore(output.shoutcast(%mp3(bitrate = 96),s))
|
||||
elsif bitrate == 128 then
|
||||
ignore(output.shoutcast(%mp3(bitrate = 128),s))
|
||||
elsif bitrate == 160 then
|
||||
ignore(output.shoutcast(%mp3(bitrate = 160),s))
|
||||
elsif bitrate == 192 then
|
||||
ignore(output.shoutcast(%mp3(bitrate = 192),s))
|
||||
elsif bitrate == 224 then
|
||||
ignore(output.shoutcast(%mp3(bitrate = 224),s))
|
||||
elsif bitrate == 256 then
|
||||
ignore(output.shoutcast(%mp3(bitrate = 256),s))
|
||||
elsif bitrate == 320 then
|
||||
ignore(output.shoutcast(%mp3(bitrate = 320),s))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -109,7 +109,7 @@ class PypoFetch(Thread):
|
|||
os.environ['TZ'] = m['timezone']
|
||||
time.tzset()
|
||||
elif (command == 'update_stream_setting'):
|
||||
logger.info("Updating stream setting: %s", m['setting'])
|
||||
logger.info("Updating stream setting...")
|
||||
self.regenerateLiquidsoapConf(m['setting'])
|
||||
# ACK the message to take it off the queue
|
||||
message.ack()
|
||||
|
@ -128,20 +128,58 @@ class PypoFetch(Thread):
|
|||
key = key.strip()
|
||||
value = value.strip()
|
||||
value = value.replace('"', '')
|
||||
if value == "dummy_string" or value == "0":
|
||||
if value == "" or value == "0":
|
||||
value = ''
|
||||
existing[key] = value
|
||||
fh.close()
|
||||
# flag for any change in cofig
|
||||
change = False
|
||||
|
||||
# dict flag for any change in cofig
|
||||
change = {}
|
||||
# this flag is to detect diable -> disable change
|
||||
# in that case, we don't want to restart even if there are chnges.
|
||||
state_change_restart = {}
|
||||
#restart flag
|
||||
restart = False
|
||||
|
||||
# look for changes
|
||||
for s in setting:
|
||||
if not s[u'value'] == existing[s[u'keyname']]:
|
||||
logger.info("Keyname: %s, Curent value: %s, New Value: %s", s[u'keyname'], s[u'value'], existing[s[u'keyname']])
|
||||
change = True
|
||||
if "output_" in s[u'keyname'] and s[u'keyname'] != "output_icecast_vorbis_metadata" and s[u'keyname'] != "output_sound_device":
|
||||
dump, stream = s[u'keyname'].split('_', 1)
|
||||
state_change_restart[stream] = False
|
||||
# This is the case where restart is required no matter what
|
||||
if (existing[s[u'keyname']] != s[u'value']):
|
||||
logger.info("'Need-to-restart' state detected for %s...", s[u'keyname'])
|
||||
restart = True;
|
||||
# This is the case where we need further checking
|
||||
if s[u'value'] != 'disabled':
|
||||
state_change_restart[stream] = True
|
||||
else:
|
||||
if s[u'keyname'] == "output_sound_device":
|
||||
dump, stream = s[u'keyname'].split('_',1)
|
||||
state_change_restart[stream] = False
|
||||
if not (s[u'value'] == existing[s[u'keyname']]):
|
||||
logger.info("'Need-to-restart' state detected for %s...", s[u'keyname'])
|
||||
state_change_restart[stream] = True
|
||||
elif s[u'keyname'] != "output_icecast_vorbis_metadata" and s[u'keyname'] != "log_file":
|
||||
stream, dump = s[u'keyname'].split('_',1)
|
||||
# setting inital value
|
||||
if stream not in change:
|
||||
change[stream] = False
|
||||
if not (s[u'value'] == existing[s[u'keyname']]):
|
||||
logger.info("Keyname: %s, Curent value: %s, New Value: %s", s[u'keyname'], existing[s[u'keyname']], s[u'value'])
|
||||
change[stream] = True
|
||||
|
||||
# set flag change for sound_device alway True
|
||||
logger.info("Change:%s, State_Change:%s...", change, state_change_restart)
|
||||
|
||||
for k, v in state_change_restart.items():
|
||||
if k == "sound_device" and v:
|
||||
restart = True
|
||||
elif v and change[k]:
|
||||
logger.info("'Need-to-restart' state detected for %s...", k)
|
||||
restart = True
|
||||
# rewrite
|
||||
if change:
|
||||
if restart:
|
||||
fh = open('/etc/airtime/liquidsoap.cfg', 'w')
|
||||
logger.info("Rewriting liquidsoap.cfg...")
|
||||
for d in setting:
|
||||
|
@ -149,7 +187,7 @@ class PypoFetch(Thread):
|
|||
if(d[u'type'] == 'string'):
|
||||
temp = d[u'value']
|
||||
if(temp == ""):
|
||||
temp = "dummy_string"
|
||||
temp = ""
|
||||
buffer += "\"" + temp + "\""
|
||||
else:
|
||||
temp = d[u'value']
|
||||
|
@ -159,10 +197,12 @@ class PypoFetch(Thread):
|
|||
buffer += "\n"
|
||||
fh.write(buffer)
|
||||
fh.close()
|
||||
# restart playout
|
||||
logger.info("Restarting airtime-playout...")
|
||||
# restarting pypo.
|
||||
# we could just restart liquidsoap but it take more time somehow.
|
||||
logger.info("Restarting pypo...")
|
||||
p = Popen("/etc/init.d/airtime-playout restart >/dev/null 2>&1", shell=True)
|
||||
sts = os.waitpid(p.pid, 0)[1]
|
||||
self.process_schedule(self.schedule_data, "scheduler", False)
|
||||
else:
|
||||
logger.info("No change detected in setting...")
|
||||
|
||||
|
@ -244,6 +284,8 @@ class PypoFetch(Thread):
|
|||
# TODO: THIS LIQUIDSOAP STUFF NEEDS TO BE MOVED TO PYPO-PUSH!!!
|
||||
stream_metadata = schedule_data['stream_metadata']
|
||||
try:
|
||||
logger.info(LS_HOST)
|
||||
logger.info(LS_PORT)
|
||||
tn = telnetlib.Telnet(LS_HOST, LS_PORT)
|
||||
#encode in latin-1 due to telnet protocol not supporting utf-8
|
||||
tn.write(('vars.stream_metadata_type %s\n' % stream_metadata['format']).encode('latin-1'))
|
||||
|
@ -456,7 +498,7 @@ class PypoFetch(Thread):
|
|||
# most recent schedule. After that we can just wait for updates.
|
||||
status, self.schedule_data = self.api_client.get_schedule()
|
||||
if status == 1:
|
||||
self.process_schedule(self.schedule_data , "scheduler", True)
|
||||
self.process_schedule(self.schedule_data , "scheduler", True)
|
||||
logger.info("Bootstrap complete: got initial copy of the schedule")
|
||||
|
||||
loops = 1
|
||||
|
|
|
@ -141,9 +141,9 @@ class PypoPush(Thread):
|
|||
tn.read_all()
|
||||
except Exception, e:
|
||||
logger.debug(e)
|
||||
logger.debug('Could not connect to liquidsoap')
|
||||
|
||||
self.liquidsoap_state_play = False
|
||||
logger.debug('Could not connect to liquidsoap')
|
||||
|
||||
|
||||
def push_liquidsoap(self, pkey, schedule, playlists):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue