diff --git a/airtime_mvc/application/controllers/ApiController.php b/airtime_mvc/application/controllers/ApiController.php index 2abdc31cc..332a42ce0 100644 --- a/airtime_mvc/application/controllers/ApiController.php +++ b/airtime_mvc/application/controllers/ApiController.php @@ -23,8 +23,7 @@ class ApiController extends Zend_Controller_Action ->addActionContext('get-stream-setting', 'json') ->addActionContext('status', 'json') ->addActionContext('register-component', 'json') - ->addActionContext('update-liquidsoap-error', 'json') - ->addActionContext('update-liquidsoap-connection', 'json') + ->addActionContext('update-liquidsoap-status', 'json') ->addActionContext('library-init', 'json') ->addActionContext('live-chat', 'json') ->initContext(); @@ -780,22 +779,14 @@ class ApiController extends Zend_Controller_Action Application_Model_ServiceRegister::Register($component, $remoteAddr); } - public function updateLiquidsoapErrorAction(){ + public function updateLiquidsoapStatusAction(){ $request = $this->getRequest(); - $error_msg = $request->getParam('error_msg'); + $msg = $request->getParam('msg'); $stream_id = $request->getParam('stream_id'); $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'); - $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); + Application_Model_StreamSetting::setLiquidsoapError($stream_id, $msg, $boot_time); } /** diff --git a/install_minimal/upgrades/airtime-2.0.0/api_client.cfg.200 b/install_minimal/upgrades/airtime-2.0.0/api_client.cfg.200 index f9da7739a..2d51bb2d2 100644 --- a/install_minimal/upgrades/airtime-2.0.0/api_client.cfg.200 +++ b/install_minimal/upgrades/airtime-2.0.0/api_client.cfg.200 @@ -92,11 +92,8 @@ generate_range_url = 'generate_range_dp.php' # URL to tell Airtime we want to get stream setting get_stream_setting = 'get-stream-setting/format/json/api_key/%%api_key%%/' -#URL to update liquidsoap error msg -update_liquidsoap_error = 'update-liquidsoap-error/format/json/api_key/%%api_key%%/error_msg/%%error_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%%' +#URL to update liquidsoap status +update_liquidsoap_status = 'update-liquidsoap-status/format/json/api_key/%%api_key%%/msg/%%msg%%/stream_id/%%stream_id%%/boot_time/%%boot_time%%' ############## # OBP config # diff --git a/python_apps/api_clients/api_client.cfg b/python_apps/api_clients/api_client.cfg index f9da7739a..2d51bb2d2 100644 --- a/python_apps/api_clients/api_client.cfg +++ b/python_apps/api_clients/api_client.cfg @@ -92,11 +92,8 @@ generate_range_url = 'generate_range_dp.php' # URL to tell Airtime we want to get stream setting get_stream_setting = 'get-stream-setting/format/json/api_key/%%api_key%%/' -#URL to update liquidsoap error msg -update_liquidsoap_error = 'update-liquidsoap-error/format/json/api_key/%%api_key%%/error_msg/%%error_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%%' +#URL to update liquidsoap status +update_liquidsoap_status = 'update-liquidsoap-status/format/json/api_key/%%api_key%%/msg/%%msg%%/stream_id/%%stream_id%%/boot_time/%%boot_time%%' ############## # OBP config # diff --git a/python_apps/api_clients/api_client.py b/python_apps/api_clients/api_client.py index 22b13fdcb..7459d63e8 100755 --- a/python_apps/api_clients/api_client.py +++ b/python_apps/api_clients/api_client.py @@ -571,29 +571,15 @@ class AirTimeApiClient(ApiClientInterface): except Exception, 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() 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 = 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 = "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"]) + msg = msg.replace('/', ' ') + encoded_msg = urllib.quote(msg, '') + url = url.replace("%%msg%%", encoded_msg) url = url.replace("%%stream_id%%", stream_id) url = url.replace("%%boot_time%%", time) logger.debug(url) diff --git a/python_apps/pypo/liquidsoap_scripts/ls_lib.liq b/python_apps/pypo/liquidsoap_scripts/ls_lib.liq index f6e966989..b1a98f3c6 100644 --- a/python_apps/pypo/liquidsoap_scripts/ls_lib.liq +++ b/python_apps/pypo/liquidsoap_scripts/ls_lib.liq @@ -37,15 +37,17 @@ def to_live(old,new) = 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) - 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}") + connected := "false" + 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. end def on_connect() - 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}") + connected := "true" + 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 if output_type == "icecast" then 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 url_ref := "N/A" end - output.shoutcast = output.shoutcast(host = host, + output.shoutcast = output.shoutcast(id = "shoutcast_stream_#{stream}", + host = host, port = port, password = pass, fallible = true, diff --git a/python_apps/pypo/liquidsoap_scripts/ls_script.liq b/python_apps/pypo/liquidsoap_scripts/ls_script.liq index 4e72261bb..42bc1e479 100644 --- a/python_apps/pypo/liquidsoap_scripts/ls_script.liq +++ b/python_apps/pypo/liquidsoap_scripts/ls_script.liq @@ -6,7 +6,7 @@ set("log.stdout", true) set("server.telnet", true) set("server.telnet.port", 1234) -time = gettimeofday() +time = ref string_of(gettimeofday()) queue = audio_to_stereo(request.queue(id="queue", length=0.5)) queue = cue_cut(queue) @@ -17,6 +17,13 @@ stream_metadata_type = ref 0 station_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" 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", "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", "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()) @@ -100,19 +109,34 @@ if output_sound_device then end if s1_enable == true then - #output_to(output_type, type, bitrate, host, port, pass, mount_point, url, description, genre, s) - 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") + if s1_output == 'shoutcast' then + 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 if s2_enable == true then - #output_to(output_type, type, bitrate, host, port, pass, mount_point, url, description, genre, s) - 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") + if s2_output == 'shoutcast' then + 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 if s3_enable == true then - #output_to(output_type, type, bitrate, host, port, pass, mount_point, url, description, genre, s) - 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") + if s3_output == 'shoutcast' then + 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 ignore(output.dummy(blank())) diff --git a/python_apps/pypo/pypo-notify.py b/python_apps/pypo/pypo-notify.py index a6cf103dc..42fb523fc 100644 --- a/python_apps/pypo/pypo-notify.py +++ b/python_apps/pypo/pypo-notify.py @@ -82,24 +82,14 @@ class Notify: logger.debug("Response: "+json.dumps(response)) # @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.debug('#################################################') - logger.debug('# Calling server to update liquidsoap error #') + logger.debug('# Calling server to update liquidsoap status #') logger.debug('#################################################') - logger.debug('error msg = '+ str(error_msg)) - response = self.api_client.notify_liquidsoap_error(error_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('msg = '+ str(msg)) + response = self.api_client.notify_liquidsoap_status(msg, stream_id, time) logger.debug("Response: "+json.dumps(response)) if __name__ == '__main__': @@ -115,13 +105,13 @@ if __name__ == '__main__': if options.error and options.stream_id: try: 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: print e elif options.connect and options.stream_id: try: n = Notify() - n.notify_liquidsoap_connection(options.stream_id, options.time) + n.notify_liquidsoap_status("OK", options.stream_id, options.time) except Exception, e: print e else: diff --git a/python_apps/pypo/pypofetch.py b/python_apps/pypo/pypofetch.py index 06d2271bc..7c020586e 100644 --- a/python_apps/pypo/pypofetch.py +++ b/python_apps/pypo/pypofetch.py @@ -216,6 +216,41 @@ class PypoFetch(Thread): self.process_schedule(self.schedule_data, "scheduler", False) else: 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): logger = logging.getLogger('fetch')