Merge branch 'devel' of dev.sourcefabric.org:airtime into devel

This commit is contained in:
Martin Konecny 2011-11-30 11:41:24 -05:00
commit 17884dbe49
15 changed files with 110 additions and 59 deletions

View file

@ -772,15 +772,17 @@ class ApiController extends Zend_Controller_Action
$error_msg = $request->getParam('error_msg'); $error_msg = $request->getParam('error_msg');
$stream_id = $request->getParam('stream_id'); $stream_id = $request->getParam('stream_id');
Application_Model_StreamSetting::setLiquidsoapError($stream_id, $error_msg); $boot_time = $request->getParam('boot_time');
Application_Model_StreamSetting::setLiquidsoapError($stream_id, $error_msg, $boot_time);
} }
public function updateLiquidsoapConnectionAction(){ public function updateLiquidsoapConnectionAction(){
$request = $this->getRequest(); $request = $this->getRequest();
$stream_id = $request->getParam('stream_id'); $stream_id = $request->getParam('stream_id');
$boot_time = $request->getParam('boot_time');
// setting error_msg as "" when there is no error_msg // setting error_msg as "" when there is no error_msg
Application_Model_StreamSetting::setLiquidsoapError($stream_id, "OK"); Application_Model_StreamSetting::setLiquidsoapError($stream_id, "OK", $boot_time);
} }
/** /**

View file

@ -203,6 +203,11 @@ class PreferenceController extends Zend_Controller_Action
Application_Model_StreamSetting::setStreamSetting($values); Application_Model_StreamSetting::setStreamSetting($values);
$data = array(); $data = array();
$data['setting'] = Application_Model_StreamSetting::getStreamSetting(); $data['setting'] = Application_Model_StreamSetting::getStreamSetting();
for($i=1;$i<=$num_of_stream;$i++){
Application_Model_StreamSetting::setLiquidsoapError($i, "waiting");
}
// store stream update timestamp
Application_Model_Preference::SetStreamUpdateTimestamp();
Application_Model_RabbitMq::SendMessageToPypo("update_stream_setting", $data); Application_Model_RabbitMq::SendMessageToPypo("update_stream_setting", $data);
$this->view->statusMsg = "<div class='success'>Stream Setting Updated.</div>"; $this->view->statusMsg = "<div class='success'>Stream Setting Updated.</div>";
} }

View file

@ -43,7 +43,7 @@ class Application_Form_StreamSettingSubForm extends Zend_Form_SubForm{
$enable = new Zend_Form_Element_Checkbox('enable'); $enable = new Zend_Form_Element_Checkbox('enable');
$enable->setLabel('Enabled:') $enable->setLabel('Enabled:')
->setValue($setting[$prefix.'_output'] != 'disabled'?1:0) ->setValue($setting[$prefix.'_enable'] == 'true' ? 1 : 0)
->setDecorators(array('ViewHelper')); ->setDecorators(array('ViewHelper'));
if($disable_all){ if($disable_all){
$enable->setAttrib("disabled", "disabled"); $enable->setAttrib("disabled", "disabled");

View file

@ -573,6 +573,25 @@ class Application_Model_Preference
return $val; return $val;
} }
} }
/**
* Stores the last timestamp of user updating stream setting
*/
public static function SetStreamUpdateTimestamp() {
$now = time();
self::SetValue("stream_update_timestamp", $now);
}
/**
* Gets the last timestamp of user updating stream setting
*/
public static function GetStreamUpdateTimestemp() {
$update_time = self::GetValue("stream_update_timestamp");
if($update_time == null){
$update_time = 0;
}
return $update_time;
}
/* User specific preferences start */ /* User specific preferences start */

View file

@ -7,8 +7,8 @@ class Application_Model_StreamSetting {
global $CC_DBC; global $CC_DBC;
$sql = "SELECT * " $sql = "SELECT * "
."FROM cc_stream_setting " ."FROM cc_stream_setting "
."WHERE keyname LIKE '%_output' " ."WHERE keyname LIKE '%_enable' "
."AND value != 'disabled'"; ."AND value == true";
$rows = $CC_DBC->getAll($sql); $rows = $CC_DBC->getAll($sql);
$ids = array(); $ids = array();
@ -75,21 +75,18 @@ class Application_Model_StreamSetting {
*/ */
public static function setStreamSetting($data){ public static function setStreamSetting($data){
global $CC_DBC; global $CC_DBC;
foreach($data as $key=>$d){ foreach ($data as $key=>$d) {
if($key == "output_sound_device" || $key == "icecast_vorbis_metadata"){ if ($key == "output_sound_device" || $key == "icecast_vorbis_metadata") {
$v = $d == 1?"true":"false"; $v = $d == 1?"true":"false";
$sql = "UPDATE cc_stream_setting SET value='$v' WHERE keyname='$key'"; $sql = "UPDATE cc_stream_setting SET value='$v' WHERE keyname='$key'";
$CC_DBC->query($sql); $CC_DBC->query($sql);
} } else {
else{
$temp = explode('_', $key); $temp = explode('_', $key);
$prefix = $temp[0]; $prefix = $temp[0];
foreach($d as $k=>$v){ foreach ($d as $k=>$v) {
$keyname = $prefix."_".$k; $keyname = $prefix . "_" . $k;
if( $k == 'output'){ if ($k == 'enable') {
if( $d["enable"] == 0){ $v = $d['enable'] == 1 ? 'true' : 'false';
$v = 'disabled';
}
} }
$v = trim($v); $v = trim($v);
$sql = "UPDATE cc_stream_setting SET value='$v' WHERE keyname='$keyname'"; $sql = "UPDATE cc_stream_setting SET value='$v' WHERE keyname='$keyname'";
@ -113,22 +110,29 @@ class Application_Model_StreamSetting {
} }
} }
public static function setLiquidsoapError($stream_id, $msg){ /*
* Stores liquidsoap status if $boot_time > save time.
* save time is the time that user clicked save on stream setting page
*/
public static function setLiquidsoapError($stream_id, $msg, $boot_time=null){
global $CC_DBC; global $CC_DBC;
$keyname = "s".$stream_id."_liquidsoap_error"; $update_time = Application_Model_Preference::GetStreamUpdateTimestemp();
$sql = "SELECT COUNT(*) FROM cc_stream_setting" if($boot_time == null || $boot_time > $update_time ){
." WHERE keyname = '$keyname'"; $keyname = "s".$stream_id."_liquidsoap_error";
$result = $CC_DBC->GetOne($sql); $sql = "SELECT COUNT(*) FROM cc_stream_setting"
if ($result == 1){
$sql = "UPDATE cc_stream_setting"
." SET value = '$msg'"
." WHERE keyname = '$keyname'"; ." WHERE keyname = '$keyname'";
}else{ $result = $CC_DBC->GetOne($sql);
$sql = "INSERT INTO cc_stream_setting (keyname, value, type)" if ($result == 1){
." VALUES ('$keyname', '$msg', 'string')"; $sql = "UPDATE cc_stream_setting"
." SET value = '$msg'"
." WHERE keyname = '$keyname'";
}else{
$sql = "INSERT INTO cc_stream_setting (keyname, value, type)"
." VALUES ('$keyname', '$msg', 'string')";
}
$res = $CC_DBC->query($sql);
} }
$res = $CC_DBC->query($sql);
} }
public static function getLiquidsoapError($stream_id){ public static function getLiquidsoapError($stream_id){
@ -145,17 +149,15 @@ class Application_Model_StreamSetting {
public static function getStreamEnabled($stream_id){ public static function getStreamEnabled($stream_id){
global $CC_DBC; global $CC_DBC;
$keyname = "s".$stream_id."_output"; $keyname = "s" . $stream_id . "_enable";
$sql = "SELECT value FROM cc_stream_setting" $sql = "SELECT value FROM cc_stream_setting"
." WHERE keyname = '$keyname'"; ." WHERE keyname = '$keyname'";
$result = $CC_DBC->GetOne($sql); $result = $CC_DBC->GetOne($sql);
if ($result == 'false') {
if($result == 'disabled'){
$result = false; $result = false;
}else{ } else {
$result = true; $result = true;
} }
return $result; return $result;
} }
} }

View file

@ -10,6 +10,7 @@ INSERT INTO cc_pref("keystr", "valstr") VALUES('plan_level', 'disabled');
INSERT INTO cc_stream_setting ("keyname", "value", "type") VALUES ('output_sound_device', 'false', 'boolean'); INSERT INTO cc_stream_setting ("keyname", "value", "type") VALUES ('output_sound_device', 'false', 'boolean');
INSERT INTO cc_stream_setting ("keyname", "value", "type") VALUES ('icecast_vorbis_metadata', 'false', 'boolean'); INSERT INTO cc_stream_setting ("keyname", "value", "type") VALUES ('icecast_vorbis_metadata', 'false', 'boolean');
INSERT INTO cc_stream_setting ("keyname", "value", "type") VALUES ('s1_enable', 'true', 'boolean');
INSERT INTO cc_stream_setting ("keyname", "value", "type") VALUES ('s1_output', 'icecast', 'string'); INSERT INTO cc_stream_setting ("keyname", "value", "type") VALUES ('s1_output', 'icecast', 'string');
INSERT INTO cc_stream_setting ("keyname", "value", "type") VALUES ('s1_type', 'ogg', 'string'); INSERT INTO cc_stream_setting ("keyname", "value", "type") VALUES ('s1_type', 'ogg', 'string');
INSERT INTO cc_stream_setting ("keyname", "value", "type") VALUES ('s1_bitrate', '128', 'integer'); INSERT INTO cc_stream_setting ("keyname", "value", "type") VALUES ('s1_bitrate', '128', 'integer');
@ -22,7 +23,8 @@ INSERT INTO cc_stream_setting ("keyname", "value", "type") VALUES ('s1_url', 'ht
INSERT INTO cc_stream_setting ("keyname", "value", "type") VALUES ('s1_description', 'Airtime Radio! Stream #1', 'string'); INSERT INTO cc_stream_setting ("keyname", "value", "type") VALUES ('s1_description', 'Airtime Radio! Stream #1', 'string');
INSERT INTO cc_stream_setting ("keyname", "value", "type") VALUES ('s1_genre', 'genre', 'string'); INSERT INTO cc_stream_setting ("keyname", "value", "type") VALUES ('s1_genre', 'genre', 'string');
INSERT INTO cc_stream_setting ("keyname", "value", "type") VALUES ('s2_output', 'disabled', 'string'); INSERT INTO cc_stream_setting ("keyname", "value", "type") VALUES ('s2_enable', 'false', 'boolean');
INSERT INTO cc_stream_setting ("keyname", "value", "type") VALUES ('s2_output', 'icecast', 'string');
INSERT INTO cc_stream_setting ("keyname", "value", "type") VALUES ('s2_type', '', 'string'); INSERT INTO cc_stream_setting ("keyname", "value", "type") VALUES ('s2_type', '', 'string');
INSERT INTO cc_stream_setting ("keyname", "value", "type") VALUES ('s2_bitrate', '', 'integer'); INSERT INTO cc_stream_setting ("keyname", "value", "type") VALUES ('s2_bitrate', '', 'integer');
INSERT INTO cc_stream_setting ("keyname", "value", "type") VALUES ('s2_host', '', 'string'); INSERT INTO cc_stream_setting ("keyname", "value", "type") VALUES ('s2_host', '', 'string');
@ -34,7 +36,8 @@ INSERT INTO cc_stream_setting ("keyname", "value", "type") VALUES ('s2_url', '',
INSERT INTO cc_stream_setting ("keyname", "value", "type") VALUES ('s2_description', '', 'string'); INSERT INTO cc_stream_setting ("keyname", "value", "type") VALUES ('s2_description', '', 'string');
INSERT INTO cc_stream_setting ("keyname", "value", "type") VALUES ('s2_genre', '', 'string'); INSERT INTO cc_stream_setting ("keyname", "value", "type") VALUES ('s2_genre', '', 'string');
INSERT INTO cc_stream_setting ("keyname", "value", "type") VALUES ('s3_output', 'disabled', 'string'); INSERT INTO cc_stream_setting ("keyname", "value", "type") VALUES ('s3_enable', 'false', 'boolean');
INSERT INTO cc_stream_setting ("keyname", "value", "type") VALUES ('s3_output', 'icecast', 'string');
INSERT INTO cc_stream_setting ("keyname", "value", "type") VALUES ('s3_type', '', 'string'); INSERT INTO cc_stream_setting ("keyname", "value", "type") VALUES ('s3_type', '', 'string');
INSERT INTO cc_stream_setting ("keyname", "value", "type") VALUES ('s3_bitrate', '', 'integer'); INSERT INTO cc_stream_setting ("keyname", "value", "type") VALUES ('s3_bitrate', '', 'integer');
INSERT INTO cc_stream_setting ("keyname", "value", "type") VALUES ('s3_host', '', 'string'); INSERT INTO cc_stream_setting ("keyname", "value", "type") VALUES ('s3_host', '', 'string');

View file

@ -96,6 +96,8 @@ function checkLiquidsoapStatus(){
html = '<div class="stream-status status-good"><h3>Connected to the streaming server</h3></div>' html = '<div class="stream-status status-good"><h3>Connected to the streaming server</h3></div>'
}else if(status == "N/A"){ }else if(status == "N/A"){
html = '<div class="stream-status status-disabled"><h3>The stream is disabled</h3></div>' html = '<div class="stream-status status-disabled"><h3>The stream is disabled</h3></div>'
}else if(status == "waiting"){
html = '<div class="stream-status status-info"><h3>Getting information from the server...</h3></div>'
}else{ }else{
html = '<div class="stream-status status-error"><h3>Can not connect to the streaming server</h3><p>'+status+'</p></div>' html = '<div class="stream-status status-error"><h3>Can not connect to the streaming server</h3><p>'+status+'</p></div>'
} }
@ -163,6 +165,6 @@ $(document).ready(function() {
}) })
showErrorSections() showErrorSections()
setInterval('checkLiquidsoapStatus()', 7000) setInterval('checkLiquidsoapStatus()', 1000)
}); });

View file

@ -153,7 +153,7 @@ class AirtimeDatabaseUpgrade{
private static function SetDefaultStreamSetting() private static function SetDefaultStreamSetting()
{ {
global $CC_DBC; global $CC_DBC;
echo "* Setting up default stream setting".PHP_EOL; echo "* Setting up default stream setting".PHP_EOL;
$sql = "INSERT INTO cc_pref(keystr, valstr) VALUES('stream_type', 'ogg, mp3'); $sql = "INSERT INTO cc_pref(keystr, valstr) VALUES('stream_type', 'ogg, mp3');
INSERT INTO cc_pref(keystr, valstr) VALUES('stream_bitrate', '24, 32, 48, 64, 96, 128, 160, 192, 224, 256, 320'); INSERT INTO cc_pref(keystr, valstr) VALUES('stream_bitrate', '24, 32, 48, 64, 96, 128, 160, 192, 224, 256, 320');
@ -164,6 +164,7 @@ class AirtimeDatabaseUpgrade{
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('output_sound_device', 'false', 'boolean'); INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('output_sound_device', 'false', 'boolean');
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('icecast_vorbis_metadata', 'false', 'boolean'); INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('icecast_vorbis_metadata', 'false', 'boolean');
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s1_enable', 'true', 'boolean');
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s1_output', 'icecast', 'string'); INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s1_output', 'icecast', 'string');
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s1_type', 'ogg', 'string'); INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s1_type', 'ogg', 'string');
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s1_bitrate', '128', 'integer'); INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s1_bitrate', '128', 'integer');
@ -176,7 +177,8 @@ class AirtimeDatabaseUpgrade{
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s1_description', 'Airtime Radio! Stream #1', 'string'); INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s1_description', 'Airtime Radio! Stream #1', 'string');
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s1_genre', 'genre', 'string'); INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s1_genre', 'genre', 'string');
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s2_output', 'disabled', 'string'); INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s2_enable', 'false', 'boolean');
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s2_output', 'icecast', 'string');
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s2_type', '', 'string'); INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s2_type', '', 'string');
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s2_bitrate', '', 'integer'); INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s2_bitrate', '', 'integer');
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s2_host', '', 'string'); INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s2_host', '', 'string');
@ -188,7 +190,8 @@ class AirtimeDatabaseUpgrade{
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s2_description', '', 'string'); INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s2_description', '', 'string');
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s2_genre', '', 'string'); INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s2_genre', '', 'string');
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s3_output', 'disabled', 'string'); INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s3_enable', 'false', 'boolean');
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s3_output', 'icecast', 'string');
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s3_type', '', 'string'); INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s3_type', '', 'string');
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s3_bitrate', '', 'integer'); INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s3_bitrate', '', 'integer');
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s3_host', '', 'string'); INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s3_host', '', 'string');

View file

@ -7,8 +7,12 @@
########################################### ###########################################
output_sound_device = false output_sound_device = false
s1_output = "icecast" s1_output = "icecast"
s2_output = "disabled" s2_output = "icecast"
s3_output = "disabled" s3_output = "icecast"
s1_enable = true
s2_enable = false
s3_enable = false
s1_type = "ogg" s1_type = "ogg"
s2_type = "ogg" s2_type = "ogg"

View file

@ -93,10 +93,10 @@ generate_range_url = 'generate_range_dp.php'
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 error msg
update_liquidsoap_error = 'update-liquidsoap-error/format/json/api_key/%%api_key%%/error_msg/%%error_msg%%/stream_id/%%stream_id%%' 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 #URL to update liquidsoap connection
update_liquidsoap_connection = 'update-liquidsoap-connection/format/json/api_key/%%api_key%%/stream_id/%%stream_id%%' update_liquidsoap_connection = 'update-liquidsoap-connection/format/json/api_key/%%api_key%%/stream_id/%%stream_id%%/boot_time/%%boot_time%%'
############## ##############
# OBP config # # OBP config #

View file

@ -571,7 +571,7 @@ 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): def notify_liquidsoap_error(self, error_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_error"])
@ -581,19 +581,21 @@ class AirTimeApiClient(ApiClientInterface):
encoded_msg = urllib.quote(error_msg, '') encoded_msg = urllib.quote(error_msg, '')
url = url.replace("%%error_msg%%", encoded_msg) url = url.replace("%%error_msg%%", encoded_msg)
url = url.replace("%%stream_id%%", stream_id) url = url.replace("%%stream_id%%", stream_id)
url = url.replace("%%boot_time%%", time)
logger.debug(url) logger.debug(url)
req = urllib2.Request(url) req = urllib2.Request(url)
response = urllib2.urlopen(req).read() response = urllib2.urlopen(req).read()
except Exception, e: except Exception, e:
logger.error("Exception: %s", e) logger.error("Exception: %s", e)
def notify_liquidsoap_connection(self, stream_id): def notify_liquidsoap_connection(self, 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_connection"]) 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"])
url = url.replace("%%stream_id%%", stream_id) url = url.replace("%%stream_id%%", stream_id)
url = url.replace("%%boot_time%%", time)
logger.debug(url) logger.debug(url)
req = urllib2.Request(url) req = urllib2.Request(url)
response = urllib2.urlopen(req).read() response = urllib2.urlopen(req).read()

View file

@ -7,8 +7,12 @@
########################################### ###########################################
output_sound_device = false output_sound_device = false
s1_output = "icecast" s1_output = "icecast"
s2_output = "disabled" s2_output = "icecast"
s3_output = "disabled" s3_output = "icecast"
s1_enable = true
s2_enable = false
s3_enable = false
s1_type = "ogg" s1_type = "ogg"
s2_type = "ogg" s2_type = "ogg"

View file

@ -39,13 +39,13 @@ 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) =
def on_error(msg) def on_error(msg)
system("/usr/lib/airtime/pypo/bin/liquidsoap_scripts/notify.sh --error='#{msg}' --stream-id=#{stream}") 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}") 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}") 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}") 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

View file

@ -6,6 +6,8 @@ set("log.stdout", true)
set("server.telnet", true) set("server.telnet", true)
set("server.telnet.port", 1234) set("server.telnet.port", 1234)
time = 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)
@ -54,18 +56,18 @@ if output_sound_device then
ignore(out(s)) ignore(out(s))
end end
if s1_output != "disabled" then if s1_enable == true then
#output_to(output_type, type, bitrate, host, port, pass, mount_point, url, description, genre, s) #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") 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 end
if s2_output != "disabled" then if s2_enable == true then
#output_to(output_type, type, bitrate, host, port, pass, mount_point, url, description, genre, s) #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") 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 end
if s3_output != "disabled" then if s3_enable == true then
#output_to(output_type, type, bitrate, host, port, pass, mount_point, url, description, genre, s) #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") 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 end

View file

@ -50,6 +50,7 @@ parser.add_option("-m", "--media-id", help="ID of the file that is currently pla
parser.add_option("-e", "--error", action="store", dest="error", type="string", help="liquidsoap error msg.", metavar="error_msg") parser.add_option("-e", "--error", action="store", dest="error", type="string", help="liquidsoap error msg.", metavar="error_msg")
parser.add_option("-s", "--stream-id", help="ID stream", metavar="stream_id") 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") parser.add_option("-c", "--connect", help="liquidsoap connected", action="store_true", metavar="connect")
parser.add_option("-t", "--time", help="liquidsoap boot up time", action="store", dest="time", metavar="time", type="string")
# parse options # parse options
(options, args) = parser.parse_args() (options, args) = parser.parse_args()
@ -80,23 +81,25 @@ class Notify:
response = self.api_client.notify_media_item_start_playing(data, media_id) response = self.api_client.notify_media_item_start_playing(data, media_id)
logger.debug("Response: "+json.dumps(response)) logger.debug("Response: "+json.dumps(response))
def notify_liquidsoap_error(self, error_msg, stream_id): # @pram time: time that LS started
def notify_liquidsoap_error(self, error_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 error #')
logger.debug('#################################################') logger.debug('#################################################')
logger.debug('error msg = '+ str(error_msg)) logger.debug('error msg = '+ str(error_msg))
response = self.api_client.notify_liquidsoap_error(error_msg, stream_id) response = self.api_client.notify_liquidsoap_error(error_msg, stream_id, time)
logger.debug("Response: "+json.dumps(response)) logger.debug("Response: "+json.dumps(response))
def notify_liquidsoap_connection(self, stream_id): # @pram time: time that LS started
def notify_liquidsoap_connection(self, stream_id, time):
logger = logging.getLogger() logger = logging.getLogger()
logger.debug('#################################################') logger.debug('#################################################')
logger.debug('# Calling server to update liquidsoap connection#') logger.debug('# Calling server to update liquidsoap connection#')
logger.debug('#################################################') logger.debug('#################################################')
response = self.api_client.notify_liquidsoap_connection(stream_id) 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__':
@ -112,13 +115,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) n.notify_liquidsoap_error(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) n.notify_liquidsoap_connection(options.stream_id, options.time)
except Exception, e: except Exception, e:
print e print e
else: else: