CC-1665: Scheduled stream rebroadcasting and recording

-initial prototype
This commit is contained in:
Martin Konecny 2012-07-17 16:00:13 -04:00
parent ed54e882a3
commit 2ad7e78e10
3 changed files with 104 additions and 13 deletions

View file

@ -8,18 +8,19 @@ def generate_liquidsoap_config(ss):
fh.write("################################################\n")
fh.write("# THIS FILE IS AUTO GENERATED. DO NOT CHANGE!! #\n")
fh.write("################################################\n")
for d in data:
for d in data:
key = d['keyname']
str_buffer = d[u'keyname'] + " = "
if(d[u'type'] == 'string'):
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'))
fh.write('log_file = "/var/log/airtime/pypo-liquidsoap/<script>.log"\n')
fh.close()

View file

@ -227,3 +227,80 @@ def add_skip_command(s)
description="Skip the current song.",
"skip",skip)
end
dyn_out = output.icecast(%wav,
host="localhost",
port=8999,
password="hackme",
mount="test-harbor",
fallible=true)
# Function to create a playlist source and output it.
def create_dynamic_source(uri) =
# The playlist source
s = input.http(uri)
# The output
active_dyn_out = dyn_out(s)
# We register both source and output
# in the list of sources
dyn_sources :=
list.append( [(uri,s),(uri,active_dyn_out)],
!dyn_sources )
"Done!"
end
# A function to destroy a dynamic source
def destroy_dynamic_source(uri) =
# We need to find the source in the list,
# remove it and destroy it. Currently, the language
# lacks some nice operators for that so we do it
# the functional way
# This function is executed on every item in the list
# of dynamic sources
def parse_list(ret, current_element) =
# ret is of the form: (matching_sources, remaining_sources)
# We extract those two:
matching_sources = fst(ret)
remaining_sources = snd(ret)
# current_element is of the form: ("uri", source) so
# we check the first element
current_uri = fst(current_element)
if current_uri == uri then
# In this case, we add the source to the list of
# matched sources
(list.append( [snd(current_element)],
matching_sources),
remaining_sources)
else
# In this case, we put the element in the list of remaining
# sources
(matching_sources,
list.append([current_element],
remaining_sources))
end
end
# Now we execute the function:
result = list.fold(parse_list, ([], []), !dyn_sources)
matching_sources = fst(result)
remaining_sources = snd(result)
# We store the remaining sources in dyn_sources
dyn_sources := remaining_sources
# If no source matched, we return an error
if list.length(matching_sources) == 0 then
"Error: no matching sources!"
else
# We stop all sources
list.iter(source.shutdown, matching_sources)
# And return
"Done!"
end
end

View file

@ -6,12 +6,22 @@ set("log.stdout", true)
set("server.telnet", true)
set("server.telnet.port", 1234)
#Dynamic source list
dyn_sources = ref []
time = ref string_of(gettimeofday())
queue = audio_to_stereo(id="queue_src", request.equeue(id="queue", length=0.5))
queue = cue_cut(queue)
queue = amplify(1., override="replay_gain", queue)
#fallback between queue and input.harbor (for restreaming other web-streams)
#live stream setup
set("harbor.bind_addr", "0.0.0.0")
#TODO: Need to create a randomized password for every instance
web_stream = input.harbor("test-harbor",port=8999,password="hackme")
pypo_data = ref '0'
web_stream_enabled = ref false
stream_metadata_type = ref 0
@ -35,6 +45,8 @@ queue = map_metadata(append_title, queue)
queue = crossfade(queue)
ignore(output.dummy(queue, fallible=true))
queue = fallback([web_stream, queue])
server.register(namespace="vars", "pypo_data", fun (s) -> begin pypo_data := s "Done" end)
server.register(namespace="vars", "web_stream_enabled", fun (s) -> begin web_stream_enabled := (s == "true") string_of(!web_stream_enabled) end)
server.register(namespace="vars", "stream_metadata_type", fun (s) -> begin stream_metadata_type := int_of_string(s) s end)
@ -43,7 +55,16 @@ server.register(namespace="vars", "station_name", fun (s) -> begin station_name
server.register(namespace="vars", "bootup_time", fun (s) -> begin time := s s end)
server.register(namespace="streams", "connection_status", fun (s) -> begin "1:#{!s1_connected},2:#{!s2_connected},3:#{!s3_connected}" end)
server.register(namespace="vars", "default_dj_fade", fun (s) -> begin default_dj_fade := float_of_string(s) s end)
server.register(namespace="dynamic_source",
description="Start a new dynamic source.",
usage="start <uri>",
"start",
create_dynamic_source)
server.register(namespace="dynamic_source",
description="Stop a dynamic source.",
usage="stop <uri>",
"stop",
destroy_dynamic_source)
default = amplify(id="silence_src", 0.00001, noise())
default = rewrite_metadata([("artist","Airtime"), ("title", "offline")],default)
@ -78,9 +99,6 @@ def make_scheduled_play_unavailable()
scheduled_play_enabled := false
end
#live stream setup
set("harbor.bind_addr", "0.0.0.0")
def update_source_status(sourcename, status) =
system("/usr/lib/airtime/pypo/bin/liquidsoap_scripts/notify.sh --source-name=#{sourcename} --source-status=#{status} &")
log("/usr/lib/airtime/pypo/bin/liquidsoap_scripts/notify.sh --source-name=#{sourcename} --source-status=#{status} &")
@ -120,13 +138,8 @@ def check_dj_client(user,password) =
#get the output of the php script
ret = get_process_lines("python /usr/lib/airtime/pypo/bin/liquidsoap_scripts/liquidsoap_auth.py --dj #{user} #{password}")
#ret has now the value of the live client (dj1,dj2, or djx), or "ERROR"/"unknown" ...
ret = list.hd(ret)
#return true to let the client transmit data, or false to tell harbor to decline
if (ret == "True") then
true
else
false
end
hd = list.hd(ret)
hd == "True"
end
def append_dj_inputs(master_harbor_input_port, master_harbor_input_mount_point, dj_harbor_input_port, dj_harbor_input_mount_point, s) =