CC-2745: Show status of liquidsoap/icecast connection on Stream Settings

page

- initial commit
This commit is contained in:
james 2011-10-10 20:14:27 -04:00
parent 5b6b81e5f3
commit d3833f9a32
7 changed files with 156 additions and 22 deletions

View file

@ -92,6 +92,12 @@ 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%%'
#URL to update liquidsoap connection
update_liquidsoap_connection = 'update-liquidsoap-connection/format/json/api_key/%%api_key%%/stream_id/%%stream_id%%'
##############
# OBP config #
##############

View file

@ -140,6 +140,12 @@ class ApiClientInterface:
def register_component(self):
pass
def notify_liquidsoap_error(self, error_msg, stream_id):
pass
def notify_liquidsoap_connection(self, stream_id):
pass
# Put here whatever tests you want to run to make sure your API is working
def test(self):
pass
@ -564,7 +570,34 @@ class AirTimeApiClient(ApiClientInterface):
response = urllib2.urlopen(req).read()
except Exception, e:
logger.error("Exception: %s", e)
def notify_liquidsoap_error(self, error_msg, stream_id):
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"])
url = url.replace("%%error_msg%%", error_msg)
url = url.replace("%%stream_id%%", stream_id)
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):
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("%%stream_id%%", stream_id)
logger.debug(url)
req = urllib2.Request(url)
response = urllib2.urlopen(req).read()
except Exception, e:
logger.error("Exception: %s", e)
################################################################################
# OpenBroadcast API Client
################################################################################

View file

@ -37,7 +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) =
def output_to(output_type, type, bitrate, host, port, pass, mount_point, url, description, genre, user, s, stream) =
def on_error(msg)
system("airtime-check-system > ~/temp/temp1.log 2>&1")
system("/usr/lib/airtime/pypo/bin/liquidsoap_scripts/notify.sh --error='#{msg}' --stream-id=#{stream} > ~/temp/temp.log 2>&1")
log("/usr/lib/airtime/pypo/bin/liquidsoap_scripts/notify.sh --error='#{msg}' --stream-id=#{stream}")
5.
end
def on_connect()
system("/usr/lib/airtime/pypo/bin/liquidsoap_scripts/notify.sh --connect --stream-id=#{stream}")
log("/usr/lib/airtime/pypo/bin/liquidsoap_scripts/notify.sh --connect --stream-id=#{stream}")
end
if output_type == "icecast" then
user_ref = ref user
if user == "" then
@ -52,7 +62,9 @@ def output_to(output_type, type, bitrate, host, port, pass, mount_point, url, de
url = url,
description = description,
genre = genre,
user = !user_ref)
user = !user_ref,
on_error = on_error,
on_connect = on_connect)
if type == "mp3" then
if bitrate == 24 then
ignore(output(%mp3(bitrate = 24),s))

View file

@ -56,17 +56,18 @@ end
if s1_output != "disabled" 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)
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")
end
if s2_output != "disabled" 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)
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")
end
if s3_output != "disabled" 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)
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")
end
ignore(output.dummy(blank()))

View file

@ -47,6 +47,9 @@ parser = OptionParser(usage=usage)
# Options
parser.add_option("-d", "--data", help="Pass JSON data from liquidsoap into this script.", metavar="data")
parser.add_option("-m", "--media-id", help="ID of the file that is currently playing.", metavar="media_id")
parser.add_option("-e", "--error", help="liquidsoap error msg.", metavar="error_msg")
parser.add_option("-s", "--stream-id", help="ID stream", metavar="stream_id")
parser.add_option("-c", "--connect", help="liquidsoap connected", action="store_true", metavar="connect")
# parse options
(options, args) = parser.parse_args()
@ -76,8 +79,26 @@ class Notify:
logger.debug('data = '+ str(data))
response = self.api_client.notify_media_item_start_playing(data, media_id)
logger.debug("Response: "+json.dumps(response))
def notify_liquidsoap_error(self, error_msg, stream_id):
logger = logging.getLogger()
logger.debug('#################################################')
logger.debug('# Calling server to update liquidsoap error #')
logger.debug('#################################################')
logger.debug('error msg = '+ str(error_msg))
response = self.api_client.notify_liquidsoap_error(error_msg, stream_id)
logger.debug("Response: "+json.dumps(response))
def notify_liquidsoap_connection(self, stream_id):
logger = logging.getLogger()
logger.debug('#################################################')
logger.debug('# Calling server to update liquidsoap connection#')
logger.debug('#################################################')
response = self.api_client.notify_liquidsoap_connection(stream_id)
logger.debug("Response: "+json.dumps(response))
if __name__ == '__main__':
print
print '#########################################'
@ -87,17 +108,30 @@ if __name__ == '__main__':
# initialize
logger = logging.getLogger()
if not options.data:
print "NOTICE: 'data' command-line argument not given."
sys.exit()
if not options.media_id:
print "NOTICE: 'media_id' command-line argument not given."
sys.exit()
try:
n = Notify()
n.notify_media_start_playing(options.data, options.media_id)
except Exception, e:
print e
if options.error_msg and options.stream_id:
try:
n = Notify()
n.notify_liquidsoap_error(options.error_msg, options.stream_id)
except Exception, e:
print e
elif optioins.connect and options.stream_id:
try:
n = Notify()
n.notify_liquidsoap_connection(options.stream_id)
except Exception, e:
print e
else:
if not options.data:
print "NOTICE: 'data' command-line argument not given."
sys.exit()
if not options.media_id:
print "NOTICE: 'media_id' command-line argument not given."
sys.exit()
try:
n = Notify()
n.notify_media_start_playing(options.data, options.media_id)
except Exception, e:
print e