Merge branch 'airtime-2.0.x' of dev.sourcefabric.org:airtime into airtime-2.0.x
This commit is contained in:
commit
e9634f94a1
|
@ -23,8 +23,7 @@ class ApiController extends Zend_Controller_Action
|
||||||
->addActionContext('get-stream-setting', 'json')
|
->addActionContext('get-stream-setting', 'json')
|
||||||
->addActionContext('status', 'json')
|
->addActionContext('status', 'json')
|
||||||
->addActionContext('register-component', 'json')
|
->addActionContext('register-component', 'json')
|
||||||
->addActionContext('update-liquidsoap-error', 'json')
|
->addActionContext('update-liquidsoap-status', 'json')
|
||||||
->addActionContext('update-liquidsoap-connection', 'json')
|
|
||||||
->addActionContext('library-init', 'json')
|
->addActionContext('library-init', 'json')
|
||||||
->addActionContext('live-chat', 'json')
|
->addActionContext('live-chat', 'json')
|
||||||
->initContext();
|
->initContext();
|
||||||
|
@ -780,22 +779,14 @@ class ApiController extends Zend_Controller_Action
|
||||||
Application_Model_ServiceRegister::Register($component, $remoteAddr);
|
Application_Model_ServiceRegister::Register($component, $remoteAddr);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function updateLiquidsoapErrorAction(){
|
public function updateLiquidsoapStatusAction(){
|
||||||
$request = $this->getRequest();
|
$request = $this->getRequest();
|
||||||
|
|
||||||
$error_msg = $request->getParam('error_msg');
|
$msg = $request->getParam('msg');
|
||||||
$stream_id = $request->getParam('stream_id');
|
$stream_id = $request->getParam('stream_id');
|
||||||
$boot_time = $request->getParam('boot_time');
|
$boot_time = $request->getParam('boot_time');
|
||||||
Application_Model_StreamSetting::setLiquidsoapError($stream_id, $error_msg, $boot_time);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function updateLiquidsoapConnectionAction(){
|
|
||||||
$request = $this->getRequest();
|
|
||||||
|
|
||||||
$stream_id = $request->getParam('stream_id');
|
Application_Model_StreamSetting::setLiquidsoapError($stream_id, $msg, $boot_time);
|
||||||
$boot_time = $request->getParam('boot_time');
|
|
||||||
// setting error_msg as "" when there is no error_msg
|
|
||||||
Application_Model_StreamSetting::setLiquidsoapError($stream_id, "OK", $boot_time);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -92,11 +92,8 @@ generate_range_url = 'generate_range_dp.php'
|
||||||
# URL to tell Airtime we want to get stream setting
|
# URL to tell Airtime we want to get stream setting
|
||||||
get_stream_setting = 'get-stream-setting/format/json/api_key/%%api_key%%/'
|
get_stream_setting = 'get-stream-setting/format/json/api_key/%%api_key%%/'
|
||||||
|
|
||||||
#URL to update liquidsoap error msg
|
#URL to update liquidsoap status
|
||||||
update_liquidsoap_error = 'update-liquidsoap-error/format/json/api_key/%%api_key%%/error_msg/%%error_msg%%/stream_id/%%stream_id%%/boot_time/%%boot_time%%'
|
update_liquidsoap_status = 'update-liquidsoap-status/format/json/api_key/%%api_key%%/msg/%%msg%%/stream_id/%%stream_id%%/boot_time/%%boot_time%%'
|
||||||
|
|
||||||
#URL to update liquidsoap connection
|
|
||||||
update_liquidsoap_connection = 'update-liquidsoap-connection/format/json/api_key/%%api_key%%/stream_id/%%stream_id%%/boot_time/%%boot_time%%'
|
|
||||||
|
|
||||||
##############
|
##############
|
||||||
# OBP config #
|
# OBP config #
|
||||||
|
|
|
@ -92,11 +92,8 @@ generate_range_url = 'generate_range_dp.php'
|
||||||
# URL to tell Airtime we want to get stream setting
|
# URL to tell Airtime we want to get stream setting
|
||||||
get_stream_setting = 'get-stream-setting/format/json/api_key/%%api_key%%/'
|
get_stream_setting = 'get-stream-setting/format/json/api_key/%%api_key%%/'
|
||||||
|
|
||||||
#URL to update liquidsoap error msg
|
#URL to update liquidsoap status
|
||||||
update_liquidsoap_error = 'update-liquidsoap-error/format/json/api_key/%%api_key%%/error_msg/%%error_msg%%/stream_id/%%stream_id%%/boot_time/%%boot_time%%'
|
update_liquidsoap_status = 'update-liquidsoap-status/format/json/api_key/%%api_key%%/msg/%%msg%%/stream_id/%%stream_id%%/boot_time/%%boot_time%%'
|
||||||
|
|
||||||
#URL to update liquidsoap connection
|
|
||||||
update_liquidsoap_connection = 'update-liquidsoap-connection/format/json/api_key/%%api_key%%/stream_id/%%stream_id%%/boot_time/%%boot_time%%'
|
|
||||||
|
|
||||||
##############
|
##############
|
||||||
# OBP config #
|
# OBP config #
|
||||||
|
|
|
@ -571,29 +571,15 @@ class AirTimeApiClient(ApiClientInterface):
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
logger.error("Exception: %s", e)
|
logger.error("Exception: %s", e)
|
||||||
|
|
||||||
def notify_liquidsoap_error(self, error_msg, stream_id, time):
|
def notify_liquidsoap_status(self, msg, stream_id, time):
|
||||||
logger = logging.getLogger()
|
logger = logging.getLogger()
|
||||||
try:
|
try:
|
||||||
url = "http://%s:%s/%s/%s" % (self.config["base_url"], str(self.config["base_port"]), self.config["api_base"], self.config["update_liquidsoap_error"])
|
url = "http://%s:%s/%s/%s" % (self.config["base_url"], str(self.config["base_port"]), self.config["api_base"], self.config["update_liquidsoap_status"])
|
||||||
|
|
||||||
url = url.replace("%%api_key%%", self.config["api_key"])
|
|
||||||
error_msg = error_msg.replace('/', ' ')
|
|
||||||
encoded_msg = urllib.quote(error_msg, '')
|
|
||||||
url = url.replace("%%error_msg%%", encoded_msg)
|
|
||||||
url = url.replace("%%stream_id%%", stream_id)
|
|
||||||
url = url.replace("%%boot_time%%", time)
|
|
||||||
logger.debug(url)
|
|
||||||
req = urllib2.Request(url)
|
|
||||||
response = urllib2.urlopen(req).read()
|
|
||||||
except Exception, e:
|
|
||||||
logger.error("Exception: %s", e)
|
|
||||||
|
|
||||||
def notify_liquidsoap_connection(self, stream_id, time):
|
|
||||||
logger = logging.getLogger()
|
|
||||||
try:
|
|
||||||
url = "http://%s:%s/%s/%s" % (self.config["base_url"], str(self.config["base_port"]), self.config["api_base"], self.config["update_liquidsoap_connection"])
|
|
||||||
|
|
||||||
url = url.replace("%%api_key%%", self.config["api_key"])
|
url = url.replace("%%api_key%%", self.config["api_key"])
|
||||||
|
msg = msg.replace('/', ' ')
|
||||||
|
encoded_msg = urllib.quote(msg, '')
|
||||||
|
url = url.replace("%%msg%%", encoded_msg)
|
||||||
url = url.replace("%%stream_id%%", stream_id)
|
url = url.replace("%%stream_id%%", stream_id)
|
||||||
url = url.replace("%%boot_time%%", time)
|
url = url.replace("%%boot_time%%", time)
|
||||||
logger.debug(url)
|
logger.debug(url)
|
||||||
|
|
|
@ -37,15 +37,17 @@ def to_live(old,new) =
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
def output_to(output_type, type, bitrate, host, port, pass, mount_point, url, description, genre, user, s, stream) =
|
def output_to(output_type, type, bitrate, host, port, pass, mount_point, url, description, genre, user, s, stream, connected) =
|
||||||
def on_error(msg)
|
def on_error(msg)
|
||||||
system("/usr/lib/airtime/pypo/bin/liquidsoap_scripts/notify.sh --error='#{msg}' --stream-id=#{stream} --time=#{time}")
|
connected := "false"
|
||||||
log("/usr/lib/airtime/pypo/bin/liquidsoap_scripts/notify.sh --error='#{msg}' --stream-id=#{stream} --time=#{time}")
|
system("/usr/lib/airtime/pypo/bin/liquidsoap_scripts/notify.sh --error='#{msg}' --stream-id=#{stream} --time=#{!time}")
|
||||||
|
log("/usr/lib/airtime/pypo/bin/liquidsoap_scripts/notify.sh --error='#{msg}' --stream-id=#{stream} --time=#{!time}")
|
||||||
5.
|
5.
|
||||||
end
|
end
|
||||||
def on_connect()
|
def on_connect()
|
||||||
system("/usr/lib/airtime/pypo/bin/liquidsoap_scripts/notify.sh --connect --stream-id=#{stream} --time=#{time}")
|
connected := "true"
|
||||||
log("/usr/lib/airtime/pypo/bin/liquidsoap_scripts/notify.sh --connect --stream-id=#{stream} --time=#{time}")
|
system("/usr/lib/airtime/pypo/bin/liquidsoap_scripts/notify.sh --connect --stream-id=#{stream} --time=#{!time}")
|
||||||
|
log("/usr/lib/airtime/pypo/bin/liquidsoap_scripts/notify.sh --connect --stream-id=#{stream} --time=#{!time}")
|
||||||
end
|
end
|
||||||
if output_type == "icecast" then
|
if output_type == "icecast" then
|
||||||
user_ref = ref user
|
user_ref = ref user
|
||||||
|
@ -136,7 +138,8 @@ def output_to(output_type, type, bitrate, host, port, pass, mount_point, url, de
|
||||||
if url == "" then
|
if url == "" then
|
||||||
url_ref := "N/A"
|
url_ref := "N/A"
|
||||||
end
|
end
|
||||||
output.shoutcast = output.shoutcast(host = host,
|
output.shoutcast = output.shoutcast(id = "shoutcast_stream_#{stream}",
|
||||||
|
host = host,
|
||||||
port = port,
|
port = port,
|
||||||
password = pass,
|
password = pass,
|
||||||
fallible = true,
|
fallible = true,
|
||||||
|
|
|
@ -6,7 +6,7 @@ set("log.stdout", true)
|
||||||
set("server.telnet", true)
|
set("server.telnet", true)
|
||||||
set("server.telnet.port", 1234)
|
set("server.telnet.port", 1234)
|
||||||
|
|
||||||
time = gettimeofday()
|
time = ref string_of(gettimeofday())
|
||||||
|
|
||||||
queue = audio_to_stereo(request.queue(id="queue", length=0.5))
|
queue = audio_to_stereo(request.queue(id="queue", length=0.5))
|
||||||
queue = cue_cut(queue)
|
queue = cue_cut(queue)
|
||||||
|
@ -17,6 +17,13 @@ stream_metadata_type = ref 0
|
||||||
station_name = ref ''
|
station_name = ref ''
|
||||||
show_name = ref ''
|
show_name = ref ''
|
||||||
|
|
||||||
|
s1_connected = ref ''
|
||||||
|
s2_connected = ref ''
|
||||||
|
s3_connected = ref ''
|
||||||
|
s1_namespace = ref ''
|
||||||
|
s2_namespace = ref ''
|
||||||
|
s3_namespace = ref ''
|
||||||
|
|
||||||
%include "ls_lib.liq"
|
%include "ls_lib.liq"
|
||||||
|
|
||||||
server.register(namespace="vars", "pypo_data", fun (s) -> begin pypo_data := s "Done" end)
|
server.register(namespace="vars", "pypo_data", fun (s) -> begin pypo_data := s "Done" end)
|
||||||
|
@ -24,6 +31,8 @@ server.register(namespace="vars", "web_stream_enabled", fun (s) -> begin web_str
|
||||||
server.register(namespace="vars", "stream_metadata_type", fun (s) -> begin stream_metadata_type := int_of_string(s) s 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", "show_name", fun (s) -> begin show_name := s s end)
|
||||||
server.register(namespace="vars", "station_name", fun (s) -> begin station_name := s s end)
|
server.register(namespace="vars", "station_name", fun (s) -> begin station_name := s s end)
|
||||||
|
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)
|
||||||
|
|
||||||
|
|
||||||
default = amplify(0.00001, noise())
|
default = amplify(0.00001, noise())
|
||||||
|
@ -100,19 +109,34 @@ if output_sound_device then
|
||||||
end
|
end
|
||||||
|
|
||||||
if s1_enable == true then
|
if s1_enable == true then
|
||||||
#output_to(output_type, type, bitrate, host, port, pass, mount_point, url, description, genre, s)
|
if s1_output == 'shoutcast' then
|
||||||
output_to(s1_output, s1_type, s1_bitrate, s1_host, s1_port, s1_pass, s1_mount, s1_url, s1_description, s1_genre, s1_user, s, "1")
|
s1_namespace := "shoutcast_stream_1"
|
||||||
|
else
|
||||||
|
s1_namespace := s1_mount
|
||||||
|
end
|
||||||
|
server.register(namespace=!s1_namespace, "connected", fun (s) -> begin !s1_connected end)
|
||||||
|
output_to(s1_output, s1_type, s1_bitrate, s1_host, s1_port, s1_pass, s1_mount, s1_url, s1_description, s1_genre, s1_user, s, "1", s1_connected)
|
||||||
end
|
end
|
||||||
|
|
||||||
if s2_enable == true then
|
if s2_enable == true then
|
||||||
#output_to(output_type, type, bitrate, host, port, pass, mount_point, url, description, genre, s)
|
if s2_output == 'shoutcast' then
|
||||||
output_to(s2_output, s2_type, s2_bitrate, s2_host, s2_port, s2_pass, s2_mount, s2_url, s2_description, s2_genre, s2_user, s, "2")
|
s2_namespace := "shoutcast_stream_2"
|
||||||
|
else
|
||||||
|
s2_namespace := s2_mount
|
||||||
|
end
|
||||||
|
server.register(namespace=!s2_namespace, "connected", fun (s) -> begin !s2_connected end)
|
||||||
|
output_to(s2_output, s2_type, s2_bitrate, s2_host, s2_port, s2_pass, s2_mount, s2_url, s2_description, s2_genre, s2_user, s, "2", s2_connected)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if s3_enable == true then
|
if s3_enable == true then
|
||||||
#output_to(output_type, type, bitrate, host, port, pass, mount_point, url, description, genre, s)
|
if s3_output == 'shoutcast' then
|
||||||
output_to(s3_output, s3_type, s3_bitrate, s3_host, s3_port, s3_pass, s3_mount, s3_url, s3_description, s3_genre, s3_user, s, "3")
|
s3_namespace := "shoutcast_stream_3"
|
||||||
|
else
|
||||||
|
s3_namespace := s3_mount
|
||||||
|
end
|
||||||
|
server.register(namespace=!s3_namespace, "connected", fun (s) -> begin !s3_connected end)
|
||||||
|
output_to(s3_output, s3_type, s3_bitrate, s3_host, s3_port, s3_pass, s3_mount, s3_url, s3_description, s3_genre, s3_user, s, "3", s3_connected)
|
||||||
end
|
end
|
||||||
|
|
||||||
ignore(output.dummy(blank()))
|
ignore(output.dummy(blank()))
|
||||||
|
|
|
@ -82,24 +82,14 @@ class Notify:
|
||||||
logger.debug("Response: "+json.dumps(response))
|
logger.debug("Response: "+json.dumps(response))
|
||||||
|
|
||||||
# @pram time: time that LS started
|
# @pram time: time that LS started
|
||||||
def notify_liquidsoap_error(self, error_msg, stream_id, time):
|
def notify_liquidsoap_status(self, msg, stream_id, time):
|
||||||
logger = logging.getLogger()
|
logger = logging.getLogger()
|
||||||
|
|
||||||
logger.debug('#################################################')
|
logger.debug('#################################################')
|
||||||
logger.debug('# Calling server to update liquidsoap error #')
|
logger.debug('# Calling server to update liquidsoap status #')
|
||||||
logger.debug('#################################################')
|
logger.debug('#################################################')
|
||||||
logger.debug('error msg = '+ str(error_msg))
|
logger.debug('msg = '+ str(msg))
|
||||||
response = self.api_client.notify_liquidsoap_error(error_msg, stream_id, time)
|
response = self.api_client.notify_liquidsoap_status(msg, stream_id, time)
|
||||||
logger.debug("Response: "+json.dumps(response))
|
|
||||||
|
|
||||||
# @pram time: time that LS started
|
|
||||||
def notify_liquidsoap_connection(self, stream_id, time):
|
|
||||||
logger = logging.getLogger()
|
|
||||||
|
|
||||||
logger.debug('#################################################')
|
|
||||||
logger.debug('# Calling server to update liquidsoap connection#')
|
|
||||||
logger.debug('#################################################')
|
|
||||||
response = self.api_client.notify_liquidsoap_connection(stream_id, time)
|
|
||||||
logger.debug("Response: "+json.dumps(response))
|
logger.debug("Response: "+json.dumps(response))
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
@ -115,13 +105,13 @@ if __name__ == '__main__':
|
||||||
if options.error and options.stream_id:
|
if options.error and options.stream_id:
|
||||||
try:
|
try:
|
||||||
n = Notify()
|
n = Notify()
|
||||||
n.notify_liquidsoap_error(options.error, options.stream_id, options.time)
|
n.notify_liquidsoap_status(options.error, options.stream_id, options.time)
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
print e
|
print e
|
||||||
elif options.connect and options.stream_id:
|
elif options.connect and options.stream_id:
|
||||||
try:
|
try:
|
||||||
n = Notify()
|
n = Notify()
|
||||||
n.notify_liquidsoap_connection(options.stream_id, options.time)
|
n.notify_liquidsoap_status("OK", options.stream_id, options.time)
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
print e
|
print e
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -216,6 +216,41 @@ class PypoFetch(Thread):
|
||||||
self.process_schedule(self.schedule_data, "scheduler", False)
|
self.process_schedule(self.schedule_data, "scheduler", False)
|
||||||
else:
|
else:
|
||||||
logger.info("No change detected in setting...")
|
logger.info("No change detected in setting...")
|
||||||
|
self.update_liquidsoap_connection_status()
|
||||||
|
"""
|
||||||
|
updates the status of liquidsoap connection to the streaming server
|
||||||
|
This fucntion updates the bootup time variable in liquidsoap script
|
||||||
|
"""
|
||||||
|
def update_liquidsoap_connection_status(self):
|
||||||
|
logger = logging.getLogger('fetch')
|
||||||
|
tn = telnetlib.Telnet(LS_HOST, LS_PORT)
|
||||||
|
# update the boot up time of liquidsoap. Since liquidsoap is not restarting,
|
||||||
|
# we are manually adjusting the bootup time variable so the status msg will get
|
||||||
|
# updated.
|
||||||
|
current_time = time.time()
|
||||||
|
boot_up_time_command = "vars.bootup_time "+str(current_time)+"\n"
|
||||||
|
tn.write(boot_up_time_command)
|
||||||
|
tn.write("streams.connection_status\n")
|
||||||
|
tn.write('exit\n')
|
||||||
|
|
||||||
|
output = tn.read_all()
|
||||||
|
output_list = output.split("\r\n")
|
||||||
|
stream_info = output_list[2]
|
||||||
|
|
||||||
|
# streamin info is in the form of:
|
||||||
|
# eg. s1:true,2:true,3:false
|
||||||
|
streams = stream_info.split(",")
|
||||||
|
logger.info(streams)
|
||||||
|
|
||||||
|
fake_time = current_time + 1
|
||||||
|
for s in streams:
|
||||||
|
info = s.split(':')
|
||||||
|
stream_id = info[0]
|
||||||
|
status = info[1]
|
||||||
|
if(status == "true"):
|
||||||
|
self.api_client.notify_liquidsoap_status("OK", stream_id, str(fake_time))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def set_export_source(self, export_source):
|
def set_export_source(self, export_source):
|
||||||
logger = logging.getLogger('fetch')
|
logger = logging.getLogger('fetch')
|
||||||
|
|
Loading…
Reference in New Issue