Merge remote-tracking branch 'stash/saas-four-streams' into saas-embed-player
This commit is contained in:
commit
e2ca218ac2
12 changed files with 190 additions and 225 deletions
|
@ -10,18 +10,23 @@ def generate_liquidsoap_config(ss):
|
|||
fh.write("################################################\n")
|
||||
fh.write("# THIS FILE IS AUTO GENERATED. DO NOT CHANGE!! #\n")
|
||||
fh.write("################################################\n")
|
||||
fh.write("# The ignore() lines are to squash unused variable warnings\n")
|
||||
|
||||
for d in data:
|
||||
key = d['keyname']
|
||||
for key, value in data.iteritems():
|
||||
try:
|
||||
str_buffer = "%s = %s\n" % (key, int(value))
|
||||
except ValueError:
|
||||
try: # Is it a boolean?
|
||||
if "true" in value or "false" in value:
|
||||
str_buffer = "%s = %s\n" % (key, value.lower())
|
||||
else:
|
||||
raise ValueError() # Just drop into the except below
|
||||
except: #Everything else is a string
|
||||
str_buffer = "%s = \"%s\"\n" % (key, value)
|
||||
|
||||
str_buffer = d[u'keyname'] + " = "
|
||||
if d[u'type'] == 'string':
|
||||
val = '"%s"' % d['value']
|
||||
else:
|
||||
val = d[u'value']
|
||||
val = val if len(val) > 0 else "0"
|
||||
str_buffer = "%s = %s\n" % (key, val)
|
||||
fh.write(str_buffer.encode('utf-8'))
|
||||
# ignore squashes unused variable errors from Liquidsoap
|
||||
fh.write(("ignore(%s)\n" % key).encode('utf-8'))
|
||||
|
||||
fh.write('log_file = "/var/log/airtime/pypo-liquidsoap/<script>.log"\n')
|
||||
fh.close()
|
||||
|
|
|
@ -10,18 +10,22 @@ output_sound_device_type = "ALSA"
|
|||
s1_output = "icecast"
|
||||
s2_output = "icecast"
|
||||
s3_output = "icecast"
|
||||
s4_output = "icecast"
|
||||
|
||||
s1_enable = true
|
||||
s2_enable = false
|
||||
s3_enable = false
|
||||
s4_enable = false
|
||||
|
||||
s1_type = "ogg"
|
||||
s2_type = "ogg"
|
||||
s3_type = "mp3"
|
||||
s4_type = "mp3"
|
||||
|
||||
s1_bitrate = 128
|
||||
s2_bitrate = 128
|
||||
s3_bitrate = 160
|
||||
s4_bitrate = 160
|
||||
|
||||
###########################################
|
||||
# Logging settings #
|
||||
|
@ -35,31 +39,39 @@ log_file = "/var/log/airtime/pypo-liquidsoap/<script>.log"
|
|||
s1_host = "127.0.0.1"
|
||||
s2_host = "127.0.0.1"
|
||||
s3_host = "127.0.0.1"
|
||||
s4_host = "127.0.0.1"
|
||||
s1_port = 8000
|
||||
s2_port = 8000
|
||||
s3_port = 8000
|
||||
s4_port = 8000
|
||||
s1_user = ""
|
||||
s2_user = ""
|
||||
s3_user = ""
|
||||
s4_user = ""
|
||||
s1_pass = "hackme"
|
||||
s2_pass = "hackme"
|
||||
s3_pass = "hackme"
|
||||
s4_pass = "hackme"
|
||||
|
||||
# Icecast mountpoint names
|
||||
s1_mount = "airtime_128.ogg"
|
||||
s2_mount = "airtime_128.ogg"
|
||||
s3_mount = "airtime_160.mp3"
|
||||
s4_mount = "airtime_160.mp3"
|
||||
|
||||
# Webstream metadata settings
|
||||
s1_url = "http://airtime.sourcefabric.org"
|
||||
s2_url = "http://airtime.sourcefabric.org"
|
||||
s3_url = "http://airtime.sourcefabric.org"
|
||||
s1_description = "Airtime Radio! stream1"
|
||||
s2_description = "Airtime Radio! stream2"
|
||||
s3_description = "Airtime Radio! stream3"
|
||||
s4_url = "http://airtime.sourcefabric.org"
|
||||
s1_description = "Airtime Radio! Stream 1"
|
||||
s2_description = "Airtime Radio! Stream 2"
|
||||
s3_description = "Airtime Radio! Stream 3"
|
||||
s4_description = "Airtime Radio! Stream 4"
|
||||
s1_genre = "genre"
|
||||
s2_genre = "genre"
|
||||
s3_genre = "genre"
|
||||
s4_genre = "genre"
|
||||
|
||||
# Audio stream metadata for vorbis/ogg is disabled by default
|
||||
# due to a number of client media players that disconnect
|
||||
|
|
|
@ -29,6 +29,7 @@ dynamic_metadata_callback = ref fun (s) -> begin () end
|
|||
s1_connected = ref ''
|
||||
s2_connected = ref ''
|
||||
s3_connected = ref ''
|
||||
s4_connected = ref ''
|
||||
s1_namespace = ref ''
|
||||
s2_namespace = ref ''
|
||||
s3_namespace = ref ''
|
||||
|
@ -103,7 +104,7 @@ server.register(namespace="vars",
|
|||
fun (s) -> begin log("vars.bootup_time") time := s s end)
|
||||
server.register(namespace="streams",
|
||||
"connection_status",
|
||||
fun (s) -> begin log("streams.connection_status") "1:#{!s1_connected},2:#{!s2_connected},3:#{!s3_connected}" end)
|
||||
fun (s) -> begin log("streams.connection_status") "1:#{!s1_connected},2:#{!s2_connected},3:#{!s3_connected},4:#{!s4_connected}" end)
|
||||
server.register(namespace="vars",
|
||||
"default_dj_fade",
|
||||
fun (s) -> begin log("vars.default_dj_fade") default_dj_fade := float_of_string(s) s end)
|
||||
|
@ -399,6 +400,21 @@ if s3_enable == true then
|
|||
s3_connected, s3_description, s3_channels)
|
||||
end
|
||||
|
||||
s4_namespace = ref ''
|
||||
if s4_enable == true then
|
||||
log("Stream 4 Enabled")
|
||||
if s4_output == 'shoutcast' then
|
||||
s4_namespace := "shoutcast_stream_4"
|
||||
else
|
||||
s4_namespace := s4_mount
|
||||
end
|
||||
server.register(namespace=!s4_namespace, "connected", fun (s) -> begin log("#{!s4_namespace}.connected") !s4_connected end)
|
||||
output_to(s4_output, s4_type, s4_bitrate, s4_host, s4_port, s4_pass,
|
||||
s4_mount, s4_url, s4_name, s4_genre, s4_user, s, "4",
|
||||
s4_connected, s4_description, s4_channels)
|
||||
end
|
||||
|
||||
|
||||
command = "/usr/lib/airtime/pypo/bin/liquidsoap_scripts/notify.sh --liquidsoap-started &"
|
||||
log(command)
|
||||
system(command)
|
||||
|
|
|
@ -118,10 +118,10 @@ class ListenerStat(Thread):
|
|||
else:
|
||||
stats.append(self.get_shoutcast_stats(v))
|
||||
self.update_listener_stat_error(v["mount"], 'OK')
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
try:
|
||||
self.update_listener_stat_error(v["mount"], str(e))
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
self.logger.error('Exception: %s', e)
|
||||
|
||||
return stats
|
||||
|
|
|
@ -216,98 +216,9 @@ class PypoFetch(Thread):
|
|||
TODO: This function needs to be way shorter, and refactored :/ - MK
|
||||
"""
|
||||
def regenerate_liquidsoap_conf(self, setting):
|
||||
existing = {}
|
||||
self.restart_liquidsoap()
|
||||
self.update_liquidsoap_connection_status()
|
||||
|
||||
setting = sorted(setting.items())
|
||||
try:
|
||||
fh = open('/etc/airtime/liquidsoap.cfg', 'r')
|
||||
except IOError, e:
|
||||
#file does not exist
|
||||
self.restart_liquidsoap()
|
||||
return
|
||||
|
||||
self.logger.info("Reading existing config...")
|
||||
# read existing conf file and build dict
|
||||
while True:
|
||||
line = fh.readline()
|
||||
|
||||
# empty line means EOF
|
||||
if not line:
|
||||
break
|
||||
|
||||
line = line.strip()
|
||||
|
||||
if not len(line) or line[0] == "#":
|
||||
continue
|
||||
|
||||
try:
|
||||
key, value = line.split('=', 1)
|
||||
except ValueError:
|
||||
continue
|
||||
key = key.strip()
|
||||
value = value.strip()
|
||||
value = value.replace('"', '')
|
||||
if value == '' or value == "0":
|
||||
value = ''
|
||||
existing[key] = value
|
||||
fh.close()
|
||||
|
||||
# dict flag for any change in config
|
||||
change = {}
|
||||
# this flag is to detect disable -> disable change
|
||||
# in that case, we don't want to restart even if there are changes.
|
||||
state_change_restart = {}
|
||||
#restart flag
|
||||
restart = False
|
||||
|
||||
self.logger.info("Looking for changes...")
|
||||
# look for changes
|
||||
for k, s in setting:
|
||||
if "output_sound_device" in s[u'keyname'] or "icecast_vorbis_metadata" in s[u'keyname']:
|
||||
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']] != str(s[u'value'])):
|
||||
self.logger.info("'Need-to-restart' state detected for %s...", s[u'keyname'])
|
||||
restart = True;
|
||||
elif "master_live_stream_port" in s[u'keyname'] or "master_live_stream_mp" in s[u'keyname'] or "dj_live_stream_port" in s[u'keyname'] or "dj_live_stream_mp" in s[u'keyname'] or "off_air_meta" in s[u'keyname']:
|
||||
if (existing[s[u'keyname']] != s[u'value']):
|
||||
self.logger.info("'Need-to-restart' state detected for %s...", s[u'keyname'])
|
||||
restart = True;
|
||||
else:
|
||||
stream, dump = s[u'keyname'].split('_', 1)
|
||||
if "_output" in s[u'keyname']:
|
||||
if (existing[s[u'keyname']] != s[u'value']):
|
||||
self.logger.info("'Need-to-restart' state detected for %s...", s[u'keyname'])
|
||||
restart = True;
|
||||
state_change_restart[stream] = True
|
||||
elif (s[u'value'] != 'disabled'):
|
||||
state_change_restart[stream] = True
|
||||
else:
|
||||
state_change_restart[stream] = False
|
||||
else:
|
||||
# setting inital value
|
||||
if stream not in change:
|
||||
change[stream] = False
|
||||
if not (s[u'value'] == existing[s[u'keyname']]):
|
||||
self.logger.info("Keyname: %s, Current 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
|
||||
self.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]:
|
||||
self.logger.info("'Need-to-restart' state detected for %s...", k)
|
||||
restart = True
|
||||
# rewrite
|
||||
if restart:
|
||||
self.restart_liquidsoap()
|
||||
else:
|
||||
self.logger.info("No change detected in setting...")
|
||||
self.update_liquidsoap_connection_status()
|
||||
|
||||
@ls_timeout
|
||||
def update_liquidsoap_connection_status(self):
|
||||
|
|
|
@ -15,6 +15,7 @@ class PypoLiquidsoap():
|
|||
"s1": None,
|
||||
"s2": None,
|
||||
"s3": None,
|
||||
"s4": None,
|
||||
}
|
||||
|
||||
self.telnet_liquidsoap = TelnetLiquidsoap(telnet_lock, \
|
||||
|
|
|
@ -83,12 +83,12 @@ class Notify:
|
|||
|
||||
# @pram time: time that LS started
|
||||
def notify_liquidsoap_status(self, msg, stream_id, time):
|
||||
logger.debug('#################################################')
|
||||
logger.debug('# Calling server to update liquidsoap status #')
|
||||
logger.debug('#################################################')
|
||||
logger.debug('msg = ' + str(msg))
|
||||
logger.info('#################################################')
|
||||
logger.info('# Calling server to update liquidsoap status #')
|
||||
logger.info('#################################################')
|
||||
logger.info('msg = ' + str(msg))
|
||||
response = self.api_client.notify_liquidsoap_status(msg, stream_id, time)
|
||||
logger.debug("Response: " + json.dumps(response))
|
||||
logger.info("Response: " + json.dumps(response))
|
||||
|
||||
def notify_source_status(self, source_name, status):
|
||||
logger.debug('#################################################')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue