CC-2590 : Make bitrate for liquidsoap and show-recorder adjustable from the config file
This commit is contained in:
parent
1366b159f2
commit
f0bf7c00c3
|
@ -10,6 +10,10 @@ output_icecast_vorbis = true
|
||||||
output_icecast_mp3 = false
|
output_icecast_mp3 = false
|
||||||
output_shoutcast = false
|
output_shoutcast = false
|
||||||
|
|
||||||
|
output_bitrate = 128
|
||||||
|
output_samplerate = 44100
|
||||||
|
output_stereo = true
|
||||||
|
|
||||||
###########################################
|
###########################################
|
||||||
# Logging settings #
|
# Logging settings #
|
||||||
###########################################
|
###########################################
|
||||||
|
@ -23,7 +27,7 @@ icecast_host = "127.0.0.1"
|
||||||
icecast_port = 8000
|
icecast_port = 8000
|
||||||
icecast_pass = "hackme"
|
icecast_pass = "hackme"
|
||||||
|
|
||||||
# Icecast mountpoint names
|
# Icecast mountpoint names
|
||||||
mount_point_mp3 = "airtime.mp3"
|
mount_point_mp3 = "airtime.mp3"
|
||||||
mount_point_vorbis = "airtime.ogg"
|
mount_point_vorbis = "airtime.ogg"
|
||||||
|
|
||||||
|
|
|
@ -57,7 +57,9 @@ if output_sound_device then
|
||||||
end
|
end
|
||||||
|
|
||||||
if output_icecast_mp3 then
|
if output_icecast_mp3 then
|
||||||
ignore(output.icecast(%mp3,
|
|
||||||
|
#%mp3(bitrate=32, samplerate=22050, stereo=false)
|
||||||
|
ignore(output.icecast(%mp3(bitrate=output_bitrate, samplerate=output_samplerate, stereo=output_stereo),
|
||||||
host = icecast_host,
|
host = icecast_host,
|
||||||
port = icecast_port,
|
port = icecast_port,
|
||||||
password = icecast_pass,
|
password = icecast_pass,
|
||||||
|
@ -74,7 +76,7 @@ end
|
||||||
|
|
||||||
if output_icecast_vorbis then
|
if output_icecast_vorbis then
|
||||||
if output_icecast_vorbis_metadata then
|
if output_icecast_vorbis_metadata then
|
||||||
ignore(output.icecast(%vorbis,
|
ignore(output.icecast(%vorbis(bitrate=output_bitrate, samplerate=output_samplerate, stereo=output_stereo),
|
||||||
host = icecast_host,
|
host = icecast_host,
|
||||||
port = icecast_port,
|
port = icecast_port,
|
||||||
password = icecast_pass,
|
password = icecast_pass,
|
||||||
|
@ -91,7 +93,7 @@ if output_icecast_vorbis then
|
||||||
#remove metadata from ogg source and merge tracks to fix bug
|
#remove metadata from ogg source and merge tracks to fix bug
|
||||||
#with vlc and mplayer disconnecting at the end of every track
|
#with vlc and mplayer disconnecting at the end of every track
|
||||||
s = add(normalize=false, [amplify(0.00001, noise()),s])
|
s = add(normalize=false, [amplify(0.00001, noise()),s])
|
||||||
ignore(output.icecast(%vorbis,
|
ignore(output.icecast(%vorbis(bitrate=output_bitrate, samplerate=output_samplerate, stereo=output_stereo),
|
||||||
host = icecast_host,
|
host = icecast_host,
|
||||||
port = icecast_port,
|
port = icecast_port,
|
||||||
password = icecast_pass,
|
password = icecast_pass,
|
||||||
|
@ -108,7 +110,7 @@ if output_icecast_vorbis then
|
||||||
end
|
end
|
||||||
|
|
||||||
if output_shoutcast then
|
if output_shoutcast then
|
||||||
ignore(output.shoutcast(%mp3,
|
ignore(output.shoutcast(%mp3(bitrate=output_bitrate, samplerate=output_samplerate, stereo=output_stereo),
|
||||||
host = shoutcast_host,
|
host = shoutcast_host,
|
||||||
port = shoutcast_port,
|
port = shoutcast_port,
|
||||||
password = shoutcast_pass,
|
password = shoutcast_pass,
|
||||||
|
|
|
@ -16,3 +16,11 @@ rabbitmq_host = 'localhost'
|
||||||
rabbitmq_user = 'guest'
|
rabbitmq_user = 'guest'
|
||||||
rabbitmq_password = 'guest'
|
rabbitmq_password = 'guest'
|
||||||
|
|
||||||
|
############################################
|
||||||
|
# Recorded Audio settings #
|
||||||
|
############################################
|
||||||
|
record_bitrate = 128
|
||||||
|
record_samplerate = 44100
|
||||||
|
record_channels = 2
|
||||||
|
record_sample_size = 16
|
||||||
|
|
||||||
|
|
|
@ -61,15 +61,21 @@ class ShowRecorder(Thread):
|
||||||
self.show_name = show_name
|
self.show_name = show_name
|
||||||
self.logger = logging.getLogger('root')
|
self.logger = logging.getLogger('root')
|
||||||
self.p = None
|
self.p = None
|
||||||
|
|
||||||
def record_show(self):
|
def record_show(self):
|
||||||
length = str(self.filelength)+".0"
|
length = str(self.filelength)+".0"
|
||||||
filename = self.start_time
|
filename = self.start_time
|
||||||
filename = filename.replace(" ", "-")
|
filename = filename.replace(" ", "-")
|
||||||
filepath = "%s%s.%s" % (config["base_recorded_files"], filename, self.filetype)
|
filepath = "%s%s.%s" % (config["base_recorded_files"], filename, self.filetype)
|
||||||
|
|
||||||
command = "ecasound -i alsa -o %s -t:%s" % (filepath, length)
|
br = config["record_bitrate"]
|
||||||
#-ge:0.1,0.1,0,-1
|
sr = config["record_samplerate"]
|
||||||
|
c = config["record_channels"]
|
||||||
|
ss = config["record_sample_size"]
|
||||||
|
|
||||||
|
#-f:16,2,44100
|
||||||
|
#-b:256
|
||||||
|
command = "ecasound -f:%s,%s,%s -b:%s -i alsa -o %s -t:%s" % (ss, c, sr, br, filepath, length)
|
||||||
args = command.split(" ")
|
args = command.split(" ")
|
||||||
|
|
||||||
self.logger.info("starting record")
|
self.logger.info("starting record")
|
||||||
|
@ -80,26 +86,26 @@ class ShowRecorder(Thread):
|
||||||
#blocks at the following line until the child process
|
#blocks at the following line until the child process
|
||||||
#quits
|
#quits
|
||||||
code = self.p.wait()
|
code = self.p.wait()
|
||||||
|
|
||||||
self.logger.info("finishing record, return code %s", self.p.returncode)
|
self.logger.info("finishing record, return code %s", self.p.returncode)
|
||||||
code = self.p.returncode
|
code = self.p.returncode
|
||||||
|
|
||||||
self.p = None
|
self.p = None
|
||||||
|
|
||||||
return code, filepath
|
return code, filepath
|
||||||
|
|
||||||
def cancel_recording(self):
|
def cancel_recording(self):
|
||||||
#add 3 second delay before actually cancelling the show. The reason
|
#add 3 second delay before actually cancelling the show. The reason
|
||||||
#for this is because it appears that ecasound starts 1 second later than
|
#for this is because it appears that ecasound starts 1 second later than
|
||||||
#it should, and therefore this method is sometimes incorrectly called 1
|
#it should, and therefore this method is sometimes incorrectly called 1
|
||||||
#second before the show ends.
|
#second before the show ends.
|
||||||
#time.sleep(3)
|
#time.sleep(3)
|
||||||
|
|
||||||
#send signal interrupt (2)
|
#send signal interrupt (2)
|
||||||
self.logger.info("Show manually cancelled!")
|
self.logger.info("Show manually cancelled!")
|
||||||
if (self.p is not None):
|
if (self.p is not None):
|
||||||
self.p.kill()
|
self.p.kill()
|
||||||
|
|
||||||
#if self.p is defined, then the child process ecasound is recording
|
#if self.p is defined, then the child process ecasound is recording
|
||||||
def is_recording(self):
|
def is_recording(self):
|
||||||
return (self.p is not None)
|
return (self.p is not None)
|
||||||
|
@ -116,7 +122,7 @@ class ShowRecorder(Thread):
|
||||||
datagen, headers = multipart_encode({"file": open(filepath, "rb"), 'name': filename, 'show_instance': self.show_instance})
|
datagen, headers = multipart_encode({"file": open(filepath, "rb"), 'name': filename, 'show_instance': self.show_instance})
|
||||||
|
|
||||||
self.api_client.upload_recorded_show(datagen, headers)
|
self.api_client.upload_recorded_show(datagen, headers)
|
||||||
|
|
||||||
def set_metadata_and_save(self, filepath):
|
def set_metadata_and_save(self, filepath):
|
||||||
try:
|
try:
|
||||||
date = self.start_time
|
date = self.start_time
|
||||||
|
@ -145,9 +151,9 @@ class ShowRecorder(Thread):
|
||||||
if code == 0:
|
if code == 0:
|
||||||
try:
|
try:
|
||||||
self.logger.info("Preparing to upload %s" % filepath)
|
self.logger.info("Preparing to upload %s" % filepath)
|
||||||
|
|
||||||
self.set_metadata_and_save(filepath)
|
self.set_metadata_and_save(filepath)
|
||||||
|
|
||||||
self.upload_file(filepath)
|
self.upload_file(filepath)
|
||||||
os.remove(filepath)
|
os.remove(filepath)
|
||||||
except Exceptio, e:
|
except Exceptio, e:
|
||||||
|
@ -173,16 +179,16 @@ class CommandListener(Thread):
|
||||||
schedule_exchange = Exchange("airtime-show-recorder", "direct", durable=True, auto_delete=True)
|
schedule_exchange = Exchange("airtime-show-recorder", "direct", durable=True, auto_delete=True)
|
||||||
schedule_queue = Queue("recorder-fetch", exchange=schedule_exchange, key="foo")
|
schedule_queue = Queue("recorder-fetch", exchange=schedule_exchange, key="foo")
|
||||||
self.connection = BrokerConnection(config["rabbitmq_host"], config["rabbitmq_user"], config["rabbitmq_password"], "/")
|
self.connection = BrokerConnection(config["rabbitmq_host"], config["rabbitmq_user"], config["rabbitmq_password"], "/")
|
||||||
channel = self.connection.channel()
|
channel = self.connection.channel()
|
||||||
consumer = Consumer(channel, schedule_queue)
|
consumer = Consumer(channel, schedule_queue)
|
||||||
consumer.register_callback(self.handle_message)
|
consumer.register_callback(self.handle_message)
|
||||||
consumer.consume()
|
consumer.consume()
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
self.logger.error(e)
|
self.logger.error(e)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def handle_message(self, body, message):
|
def handle_message(self, body, message):
|
||||||
# ACK the message to take it off the queue
|
# ACK the message to take it off the queue
|
||||||
message.ack()
|
message.ack()
|
||||||
|
@ -190,7 +196,7 @@ class CommandListener(Thread):
|
||||||
m = json.loads(message.body)
|
m = json.loads(message.body)
|
||||||
command = m['event_type']
|
command = m['event_type']
|
||||||
self.logger.info("Handling command: " + command)
|
self.logger.info("Handling command: " + command)
|
||||||
|
|
||||||
if(command == 'update_schedule'):
|
if(command == 'update_schedule'):
|
||||||
temp = m['shows']
|
temp = m['shows']
|
||||||
if temp is not None:
|
if temp is not None:
|
||||||
|
@ -198,7 +204,7 @@ class CommandListener(Thread):
|
||||||
elif(command == 'cancel_recording'):
|
elif(command == 'cancel_recording'):
|
||||||
if self.sr.is_recording():
|
if self.sr.is_recording():
|
||||||
self.sr.cancel_recording()
|
self.sr.cancel_recording()
|
||||||
|
|
||||||
def parse_shows(self, shows):
|
def parse_shows(self, shows):
|
||||||
self.logger.info("Parsing show schedules...")
|
self.logger.info("Parsing show schedules...")
|
||||||
self.shows_to_record = {}
|
self.shows_to_record = {}
|
||||||
|
@ -208,30 +214,30 @@ class CommandListener(Thread):
|
||||||
time_delta = show_end - show_starts
|
time_delta = show_end - show_starts
|
||||||
|
|
||||||
self.shows_to_record[show[u'starts']] = [time_delta, show[u'instance_id'], show[u'name']]
|
self.shows_to_record[show[u'starts']] = [time_delta, show[u'instance_id'], show[u'name']]
|
||||||
|
|
||||||
delta = self.get_time_till_next_show()
|
delta = self.get_time_till_next_show()
|
||||||
# awake at least 5 seconds prior to the show start
|
# awake at least 5 seconds prior to the show start
|
||||||
self.time_till_next_show = delta - 5
|
self.time_till_next_show = delta - 5
|
||||||
|
|
||||||
self.logger.info(self.shows_to_record)
|
self.logger.info(self.shows_to_record)
|
||||||
|
|
||||||
def get_time_till_next_show(self):
|
def get_time_till_next_show(self):
|
||||||
if len(self.shows_to_record) != 0:
|
if len(self.shows_to_record) != 0:
|
||||||
tnow = datetime.datetime.now()
|
tnow = datetime.datetime.now()
|
||||||
sorted_show_keys = sorted(self.shows_to_record.keys())
|
sorted_show_keys = sorted(self.shows_to_record.keys())
|
||||||
|
|
||||||
start_time = sorted_show_keys[0]
|
start_time = sorted_show_keys[0]
|
||||||
next_show = getDateTimeObj(start_time)
|
next_show = getDateTimeObj(start_time)
|
||||||
|
|
||||||
delta = next_show - tnow
|
delta = next_show - tnow
|
||||||
out = delta.seconds
|
out = delta.seconds
|
||||||
|
|
||||||
self.logger.debug("Next show %s", next_show)
|
self.logger.debug("Next show %s", next_show)
|
||||||
self.logger.debug("Now %s", tnow)
|
self.logger.debug("Now %s", tnow)
|
||||||
else:
|
else:
|
||||||
out = 3600
|
out = 3600
|
||||||
return out
|
return out
|
||||||
|
|
||||||
def start_record(self):
|
def start_record(self):
|
||||||
if len(self.shows_to_record) != 0:
|
if len(self.shows_to_record) != 0:
|
||||||
try:
|
try:
|
||||||
|
@ -239,16 +245,16 @@ class CommandListener(Thread):
|
||||||
|
|
||||||
self.logger.debug("sleeping %s seconds until show", delta)
|
self.logger.debug("sleeping %s seconds until show", delta)
|
||||||
time.sleep(delta)
|
time.sleep(delta)
|
||||||
|
|
||||||
sorted_show_keys = sorted(self.shows_to_record.keys())
|
sorted_show_keys = sorted(self.shows_to_record.keys())
|
||||||
start_time = sorted_show_keys[0]
|
start_time = sorted_show_keys[0]
|
||||||
show_length = self.shows_to_record[start_time][0]
|
show_length = self.shows_to_record[start_time][0]
|
||||||
show_instance = self.shows_to_record[start_time][1]
|
show_instance = self.shows_to_record[start_time][1]
|
||||||
show_name = self.shows_to_record[start_time][2]
|
show_name = self.shows_to_record[start_time][2]
|
||||||
|
|
||||||
self.sr = ShowRecorder(show_instance, show_name, show_length.seconds, start_time, filetype="mp3")
|
self.sr = ShowRecorder(show_instance, show_name, show_length.seconds, start_time, filetype="mp3")
|
||||||
self.sr.start()
|
self.sr.start()
|
||||||
|
|
||||||
#remove show from shows to record.
|
#remove show from shows to record.
|
||||||
del self.shows_to_record[start_time]
|
del self.shows_to_record[start_time]
|
||||||
self.time_till_next_show = 3600
|
self.time_till_next_show = 3600
|
||||||
|
@ -256,7 +262,7 @@ class CommandListener(Thread):
|
||||||
self.logger.error(e)
|
self.logger.error(e)
|
||||||
else:
|
else:
|
||||||
self.logger.debug("No recording scheduled...")
|
self.logger.debug("No recording scheduled...")
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Main loop of the thread:
|
Main loop of the thread:
|
||||||
Wait for schedule updates from RabbitMQ, but in case there arent any,
|
Wait for schedule updates from RabbitMQ, but in case there arent any,
|
||||||
|
@ -269,7 +275,7 @@ class CommandListener(Thread):
|
||||||
time.sleep(5)
|
time.sleep(5)
|
||||||
|
|
||||||
# Bootstrap: since we are just starting up, we need to grab the
|
# Bootstrap: since we are just starting up, we need to grab the
|
||||||
# most recent schedule. After that we can just wait for updates.
|
# most recent schedule. After that we can just wait for updates.
|
||||||
try:
|
try:
|
||||||
temp = self.api_client.get_shows_to_record()
|
temp = self.api_client.get_shows_to_record()
|
||||||
if temp is not None:
|
if temp is not None:
|
||||||
|
@ -278,8 +284,8 @@ class CommandListener(Thread):
|
||||||
self.logger.info("Bootstrap complete: got initial copy of the schedule")
|
self.logger.info("Bootstrap complete: got initial copy of the schedule")
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
self.logger.error(e)
|
self.logger.error(e)
|
||||||
|
|
||||||
loops = 1
|
loops = 1
|
||||||
while True:
|
while True:
|
||||||
self.logger.info("Loop #%s", loops)
|
self.logger.info("Loop #%s", loops)
|
||||||
try:
|
try:
|
||||||
|
@ -289,11 +295,11 @@ class CommandListener(Thread):
|
||||||
self.logger.info(e)
|
self.logger.info(e)
|
||||||
# start recording
|
# start recording
|
||||||
self.start_record()
|
self.start_record()
|
||||||
|
|
||||||
loops += 1
|
loops += 1
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
cl = CommandListener()
|
cl = CommandListener()
|
||||||
cl.start()
|
cl.start()
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue