CC-1665: Scheduled stream rebroadcasting and recording

-webstreams now start and stop at the correct time.
This commit is contained in:
Martin Konecny 2012-07-25 16:56:33 -04:00
parent c90495d2d3
commit fbc5b72f14
4 changed files with 114 additions and 57 deletions

View file

@ -23,7 +23,6 @@ set("harbor.bind_addr", "0.0.0.0")
web_stream = input.harbor("test-harbor",port=8999,password="hackme")
pypo_data = ref '0'
web_stream_enabled = ref false
stream_metadata_type = ref 0
default_dj_fade = ref 0.
station_name = ref ''
@ -43,12 +42,11 @@ queue = on_metadata(notify, queue)
queue = map_metadata(append_title, queue)
# the crossfade function controls fade in/out
queue = crossfade(queue)
ignore(output.dummy(queue, fallible=true))
queue = fallback([web_stream, queue])
ignore(output.dummy(queue, fallible=true))
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)
server.register(namespace="vars", "show_name", fun (s) -> begin show_name := s s end)
server.register(namespace="vars", "station_name", fun (s) -> begin station_name := s s end)
@ -179,20 +177,6 @@ s = append_dj_inputs(master_live_stream_port, master_live_stream_mp, dj_live_str
# Attach a skip command to the source s:
#web_stream_source = input.http(id="web_stream", autostart = false, buffer=0.5, max=20., "")
#once the stream is started, give it a sink so that liquidsoap doesn't
#create buffer overflow warnings in the log file.
#output.dummy(fallible=true, web_stream_source)
#s = switch(track_sensitive = false,
# transitions=[to_live,to_live],
# [
# ({ !web_stream_enabled }, web_stream_source),
# ({ true }, s)
# ]
#)
add_skip_command(s)
server.register(namespace="streams",

View file

@ -425,6 +425,11 @@ class PypoFetch(Thread):
for key in media:
media_item = media[key]
"""
{u'end': u'2012-07-26-04-05-00', u'fade_out': 500, u'show_name': u'Untitled Show', u'uri': u'http://',
u'cue_in': 0, u'start': u'2012-07-26-04-00-00', u'replay_gain': u'0', u'row_id': 16, u'cue_out': 300, u'type':
u'stream', u'id': 1, u'fade_in': 500}
"""
if(media_item['type'] == 'file'):
fileExt = os.path.splitext(media_item['uri'])[1]
dst = os.path.join(download_dir, media_item['id'] + fileExt)
@ -455,15 +460,19 @@ class PypoFetch(Thread):
for mkey in media:
media_item = media[mkey]
fileExt = os.path.splitext(media_item['uri'])[1]
scheduled_file_set.add(media_item["id"] + fileExt)
if media_item['type'] == 'file':
fileExt = os.path.splitext(media_item['uri'])[1]
scheduled_file_set.add(media_item["id"] + fileExt)
unneeded_files = cached_file_set - scheduled_file_set
expired_files = cached_file_set - scheduled_file_set
self.logger.debug("Files to remove " + str(unneeded_files))
for f in unneeded_files:
self.logger.debug("Removing %s" % os.path.join(self.cache_dir, f))
os.remove(os.path.join(self.cache_dir, f))
self.logger.debug("Files to remove " + str(expired_files))
for f in expired_files:
try:
self.logger.debug("Removing %s" % os.path.join(self.cache_dir, f))
os.remove(os.path.join(self.cache_dir, f))
except Exception, e:
self.logger.error(e)
def main(self):
# Bootstrap: since we are just starting up, we need to grab the

View file

@ -241,7 +241,7 @@ class PypoPush(Thread):
for mkey in sorted_keys:
media_item = media_schedule[mkey]
if media_item['type'] == "event":
if media_item['independent_event']:
chains.append([media_item])
elif len(current_chain) == 0:
current_chain.append(media_item)
@ -353,9 +353,55 @@ class PypoPush(Thread):
PypoFetch.disconnect_source(self.logger, self.telnet_lock, "live_dj")
elif media_item['event_type'] == "switch_off":
PypoFetch.switch_source(self.logger, self.telnet_lock, "live_dj", "off")
elif media_item['type'] == "stream":
"""
Source is a stream that we need to being downloading to a file. Then we may simply
point Liquidsoap to play this file.
"""
self.start_web_stream(media_item)
elif media_item['type'] == "stream_end":
self.stop_web_stream(media_item)
except Exception, e:
self.logger.error('Pypo Push Exception: %s', e)
def start_web_stream(self, media_item):
try:
self.telnet_lock.acquire()
tn = telnetlib.Telnet(LS_HOST, LS_PORT)
#dynamic_source.start http://87.230.101.24:80/top100station.mp3
msg = 'streams.scheduled_play_start\n'
tn.write(msg)
msg = 'dynamic_source.start %s\n' % media_item['uri'].encode('latin-1')
self.logger.debug(msg)
tn.write(msg)
tn.write("exit\n")
self.logger.debug(tn.read_all())
except Exception, e:
self.logger.error(str(e))
finally:
self.telnet_lock.release()
def stop_web_stream(self, media_item):
try:
self.telnet_lock.acquire()
tn = telnetlib.Telnet(LS_HOST, LS_PORT)
#dynamic_source.stop http://87.230.101.24:80/top100station.mp3
msg = 'dynamic_source.stop %s\n' % media_item['uri'].encode('latin-1')
self.logger.debug(msg)
tn.write(msg)
tn.write("exit\n")
self.logger.debug(tn.read_all())
except Exception, e:
self.logger.error(str(e))
finally:
self.telnet_lock.release()
def clear_liquidsoap_queue(self):
self.logger.debug("Clearing Liquidsoap queue")
try: