CC-2661: Uptrade script for stream config feature
- codes for conserving user's liquidsoap.cfg and porting into new stream setting config. - extra fix: fixed a bug with shoutcast(default value has to be set for some variables)
This commit is contained in:
parent
17e7e9b80a
commit
39b688c256
|
@ -18,7 +18,7 @@ class Application_Form_StreamSetting extends Zend_Form
|
||||||
$output_sound_device = new Zend_Form_Element_Checkbox('output_sound_device');
|
$output_sound_device = new Zend_Form_Element_Checkbox('output_sound_device');
|
||||||
$output_sound_device->setLabel('Enabled')
|
$output_sound_device->setLabel('Enabled')
|
||||||
->setRequired(false)
|
->setRequired(false)
|
||||||
->setValue($setting['output_sound_device'])
|
->setValue(($setting['output_sound_device'] == "true")?1:0)
|
||||||
->setDecorators(array('ViewHelper'));
|
->setDecorators(array('ViewHelper'));
|
||||||
$this->addElement($output_sound_device);
|
$this->addElement($output_sound_device);
|
||||||
}
|
}
|
||||||
|
|
|
@ -99,13 +99,9 @@ class Application_Form_StreamSettingSubForm extends Zend_Form_SubForm{
|
||||||
->setDecorators(array('ViewHelper'));
|
->setDecorators(array('ViewHelper'));
|
||||||
$this->addElement($description);
|
$this->addElement($description);
|
||||||
|
|
||||||
$mount_info = array();
|
|
||||||
if(isset($setting[$prefix.'_mount'])){
|
|
||||||
$mount_info = explode('.',$setting[$prefix.'_mount']);
|
|
||||||
}
|
|
||||||
$mount = new Zend_Form_Element_Text('mount');
|
$mount = new Zend_Form_Element_Text('mount');
|
||||||
$mount->setLabel("Mount Point")
|
$mount->setLabel("Mount Point")
|
||||||
->setValue(isset($mount_info[0])?$mount_info[0]:"")
|
->setValue(isset($setting[$prefix.'_mount'])?$setting[$prefix.'_mount']:"")
|
||||||
->setDecorators(array('ViewHelper'));
|
->setDecorators(array('ViewHelper'));
|
||||||
$this->addElement($mount);
|
$this->addElement($mount);
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,7 @@ class Application_Model_StreamSetting {
|
||||||
$v = 'disabled';
|
$v = 'disabled';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
$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'";
|
||||||
$CC_DBC->query($sql);
|
$CC_DBC->query($sql);
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ INSERT INTO cc_pref("keystr", "valstr") VALUES('num_of_streams', '3');
|
||||||
INSERT INTO cc_pref("keystr", "valstr") VALUES('max_bitrate', '320');
|
INSERT INTO cc_pref("keystr", "valstr") VALUES('max_bitrate', '320');
|
||||||
|
|
||||||
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 ('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');
|
||||||
|
|
|
@ -51,12 +51,14 @@ class AirtimeInstall{
|
||||||
{
|
{
|
||||||
global $CC_DBC;
|
global $CC_DBC;
|
||||||
|
|
||||||
|
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');
|
||||||
INSERT INTO cc_pref(keystr, valstr) VALUES('num_of_streams', '3');
|
INSERT INTO cc_pref(keystr, valstr) VALUES('num_of_streams', '3');
|
||||||
INSERT INTO cc_pref(keystr, valstr) VALUES('max_bitrate', '128');
|
INSERT INTO cc_pref(keystr, valstr) VALUES('max_bitrate', '128');
|
||||||
|
|
||||||
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 ('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');
|
||||||
|
@ -135,6 +137,79 @@ class AirtimeInstall{
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
public static function GetOldLiquidsoapCfgAndUpdate(){
|
||||||
|
global $CC_DBC;
|
||||||
|
echo "* Retrieving old liquidsoap configuration".PHP_EOL;
|
||||||
|
$map = array();
|
||||||
|
$fh = fopen("/etc/airtime/liquidsoap.cfg", 'r');
|
||||||
|
$newConfigMap = array();
|
||||||
|
|
||||||
|
while(!feof($fh)){
|
||||||
|
$line = fgets($fh);
|
||||||
|
if(substr(trim($line), 0, 1) == '#' || trim($line) == ""){
|
||||||
|
continue;
|
||||||
|
}else{
|
||||||
|
$info = explode('=', $line, 2);
|
||||||
|
$map[trim($info[0])] = trim($info[1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$newConfigMap['output_sound_device'] = $map['output_sound_device'];
|
||||||
|
$newConfigMap['icecast_vorbis_metadata'] = $map['output_icecast_vorbis_metadata'];
|
||||||
|
$newConfigMap['log_file'] = $map['log_file'];
|
||||||
|
|
||||||
|
$count = 1;
|
||||||
|
if( $map['output_icecast_vorbis'] == 'true'){
|
||||||
|
$newConfigMap['s'.$count.'_output'] = 'icecast';
|
||||||
|
$newConfigMap['s'.$count.'_host'] = $map['icecast_host'];
|
||||||
|
$newConfigMap['s'.$count.'_port'] = $map['icecast_port'];
|
||||||
|
$newConfigMap['s'.$count.'_pass'] = $map['icecast_pass'];
|
||||||
|
$newConfigMap['s'.$count.'_mount'] = $map['mount_point_vorbis'];
|
||||||
|
$newConfigMap['s'.$count.'_url'] = $map['icecast_url'];
|
||||||
|
$newConfigMap['s'.$count.'_description'] = $map['icecast_description'];
|
||||||
|
$newConfigMap['s'.$count.'_genre'] = $map['icecast_genre'];
|
||||||
|
$newConfigMap['s'.$count.'_type'] = "ogg";
|
||||||
|
$newConfigMap['s'.$count.'_bitrate'] = "128";
|
||||||
|
$count++;
|
||||||
|
}
|
||||||
|
if($map['output_icecast_mp3'] == 'true'){
|
||||||
|
$newConfigMap['s'.$count.'_output'] = 'icecast';
|
||||||
|
$newConfigMap['s'.$count.'_host'] = $map['icecast_host'];
|
||||||
|
$newConfigMap['s'.$count.'_port'] = $map['icecast_port'];
|
||||||
|
$newConfigMap['s'.$count.'_pass'] = $map['icecast_pass'];
|
||||||
|
$newConfigMap['s'.$count.'_mount'] = $map['mount_point_mp3'];
|
||||||
|
$newConfigMap['s'.$count.'_url'] = $map['icecast_url'];
|
||||||
|
$newConfigMap['s'.$count.'_description'] = $map['icecast_description'];
|
||||||
|
$newConfigMap['s'.$count.'_genre'] = $map['icecast_genre'];
|
||||||
|
$newConfigMap['s'.$count.'_type'] = "mp3";
|
||||||
|
$newConfigMap['s'.$count.'_bitrate'] = "128";
|
||||||
|
$count++;
|
||||||
|
}
|
||||||
|
if($map['output_shoutcast'] == 'true'){
|
||||||
|
$newConfigMap['s'.$count.'_output'] = 'shoutcast';
|
||||||
|
$newConfigMap['s'.$count.'_host'] = $map['shoutcast_host'];
|
||||||
|
$newConfigMap['s'.$count.'_port'] = $map['shoutcast_port'];
|
||||||
|
$newConfigMap['s'.$count.'_pass'] = $map['shoutcast_pass'];
|
||||||
|
$newConfigMap['s'.$count.'_url'] = $map['shoutcast_url'];
|
||||||
|
$newConfigMap['s'.$count.'_genre'] = $map['shoutcast_genre'];
|
||||||
|
$newConfigMap['s'.$count.'_type'] = "mp3";
|
||||||
|
$newConfigMap['s'.$count.'_bitrate'] = "128";
|
||||||
|
$count++;
|
||||||
|
}
|
||||||
|
|
||||||
|
$sql = "";
|
||||||
|
foreach( $newConfigMap as $key=>$val){
|
||||||
|
if(substr($val, 0, 1) == '"' && substr($val, strlen($val)-1,1)){
|
||||||
|
$val = ltrim($val, '"');
|
||||||
|
$val = rtrim($val, '"');
|
||||||
|
}
|
||||||
|
$sql .= "UPDATE cc_stream_setting SET value='$val' WHERE keyname='$key';";
|
||||||
|
}
|
||||||
|
$result = $CC_DBC->query($sql);
|
||||||
|
if (PEAR::isError($result)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Airtime200Upgrade{
|
class Airtime200Upgrade{
|
||||||
|
@ -284,14 +359,17 @@ class AirtimeIni200{
|
||||||
public static function ReadPythonConfig($p_filename)
|
public static function ReadPythonConfig($p_filename)
|
||||||
{
|
{
|
||||||
$values = array();
|
$values = array();
|
||||||
|
|
||||||
$lines = file($p_filename);
|
$fh = fopen($p_filename, 'r');
|
||||||
$n=count($lines);
|
|
||||||
for ($i=0; $i<$n; $i++) {
|
while(!feof($fh)){
|
||||||
if (strlen($lines[$i]) && !in_array(substr($lines[$i], 0, 1), array('#', PHP_EOL))){
|
$line = fgets($fh);
|
||||||
$info = explode("=", $lines[$i]);
|
if(substr(trim($line), 0, 1) == '#' || trim($line) == ""){
|
||||||
$values[trim($info[0])] = trim($info[1]);
|
continue;
|
||||||
}
|
}else{
|
||||||
|
$info = explode('=', $line, 2);
|
||||||
|
$values[trim($info[0])] = trim($info[1]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $values;
|
return $values;
|
||||||
|
@ -346,7 +424,8 @@ class AirtimeIni200{
|
||||||
AirtimeIni200::CONF_FILE_PYPO,
|
AirtimeIni200::CONF_FILE_PYPO,
|
||||||
AirtimeIni200::CONF_FILE_RECORDER,
|
AirtimeIni200::CONF_FILE_RECORDER,
|
||||||
AirtimeIni200::CONF_FILE_LIQUIDSOAP,
|
AirtimeIni200::CONF_FILE_LIQUIDSOAP,
|
||||||
AirtimeIni200::CONF_FILE_MONIT);
|
AirtimeIni200::CONF_FILE_MONIT,
|
||||||
|
AirtimeIni200::CONF_FILE_API_CLIENT);
|
||||||
|
|
||||||
// Backup the config files
|
// Backup the config files
|
||||||
$suffix = date("Ymdhis")."-1.9.3";
|
$suffix = date("Ymdhis")."-1.9.3";
|
||||||
|
@ -388,9 +467,13 @@ class AirtimeIni200{
|
||||||
echo "Could not copy recorder.cfg to /etc/airtime/. Exiting.";
|
echo "Could not copy recorder.cfg to /etc/airtime/. Exiting.";
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
if (!copy(__DIR__."/liquidsoap.cfg.$suffix", AirtimeIni200::CONF_FILE_LIQUIDSOAP)){
|
/*if (!copy(__DIR__."/liquidsoap.cfg.$suffix", AirtimeIni200::CONF_FILE_LIQUIDSOAP)){
|
||||||
echo "Could not copy liquidsoap.cfg to /etc/airtime/. Exiting.";
|
echo "Could not copy liquidsoap.cfg to /etc/airtime/. Exiting.";
|
||||||
exit(1);
|
exit(1);
|
||||||
|
}*/
|
||||||
|
if (!copy(__DIR__."/api_client.cfg.$suffix", AirtimeIni200::CONF_FILE_API_CLIENT)){
|
||||||
|
echo "Could not copy airtime-monit.cfg to /etc/monit/conf.d/. Exiting.";
|
||||||
|
exit(1);
|
||||||
}
|
}
|
||||||
if (!copy(__DIR__."/airtime-monit.cfg.$suffix", AirtimeIni200::CONF_FILE_MONIT)){
|
if (!copy(__DIR__."/airtime-monit.cfg.$suffix", AirtimeIni200::CONF_FILE_MONIT)){
|
||||||
echo "Could not copy airtime-monit.cfg to /etc/monit/conf.d/. Exiting.";
|
echo "Could not copy airtime-monit.cfg to /etc/monit/conf.d/. Exiting.";
|
||||||
|
@ -429,6 +512,8 @@ AirtimeInstall::MigrateTablesToVersion(__DIR__, '20110829143306');
|
||||||
|
|
||||||
AirtimeInstall::SetDefaultStreamSetting();
|
AirtimeInstall::SetDefaultStreamSetting();
|
||||||
|
|
||||||
|
AirtimeInstall::GetOldLiquidsoapCfgAndUpdate();
|
||||||
|
|
||||||
// restart monit
|
// restart monit
|
||||||
exec("service monit restart");
|
exec("service monit restart");
|
||||||
|
|
||||||
|
|
|
@ -45,6 +45,8 @@ remove_watched_dir = 'remove-watched-dir/format/json/api_key/%%api_key%%/path/%%
|
||||||
# URL to tell Airtime we want to add watched directory
|
# URL to tell Airtime we want to add watched directory
|
||||||
set_storage_dir = 'set-storage-dir/format/json/api_key/%%api_key%%/path/%%path%%'
|
set_storage_dir = 'set-storage-dir/format/json/api_key/%%api_key%%/path/%%path%%'
|
||||||
|
|
||||||
|
# URL to tell Airtime we want to get stream setting
|
||||||
|
get_stream_setting = 'get-stream-setting/format/json/api_key/%%api_key%%/'
|
||||||
|
|
||||||
#############################
|
#############################
|
||||||
## Config for Recorder
|
## Config for Recorder
|
||||||
|
|
|
@ -61,4 +61,4 @@ s3_genre = "genre"
|
||||||
# when the metadata changes to a new track. Some versions of
|
# when the metadata changes to a new track. Some versions of
|
||||||
# mplayer and VLC have this problem. Enable this option at your
|
# mplayer and VLC have this problem. Enable this option at your
|
||||||
# own risk!
|
# own risk!
|
||||||
output_icecast_vorbis_metadata = false
|
icecast_vorbis_metadata = false
|
||||||
|
|
|
@ -139,10 +139,10 @@ try:
|
||||||
buffer += temp
|
buffer += temp
|
||||||
buffer += "\n"
|
buffer += "\n"
|
||||||
fh.write(buffer)
|
fh.write(buffer)
|
||||||
fh.write("output_icecast_vorbis_metadata = false\n");
|
|
||||||
fh.write("log_file = \"/var/log/airtime/pypo-liquidsoap/<script>.log\"\n");
|
fh.write("log_file = \"/var/log/airtime/pypo-liquidsoap/<script>.log\"\n");
|
||||||
fh.close()
|
fh.close()
|
||||||
|
else:
|
||||||
|
print "Unable to connect to the Airtime server."
|
||||||
print "Waiting for processes to start..."
|
print "Waiting for processes to start..."
|
||||||
p = Popen("/etc/init.d/airtime-playout start", shell=True)
|
p = Popen("/etc/init.d/airtime-playout start", shell=True)
|
||||||
sts = os.waitpid(p.pid, 0)[1]
|
sts = os.waitpid(p.pid, 0)[1]
|
||||||
|
|
|
@ -58,4 +58,4 @@ s3_genre = "genre"
|
||||||
# when the metadata changes to a new track. Some versions of
|
# when the metadata changes to a new track. Some versions of
|
||||||
# mplayer and VLC have this problem. Enable this option at your
|
# mplayer and VLC have this problem. Enable this option at your
|
||||||
# own risk!
|
# own risk!
|
||||||
output_icecast_vorbis_metadata = false
|
icecast_vorbis_metadata = false
|
||||||
|
|
|
@ -80,7 +80,7 @@ def output_to(output_type, type, bitrate, host, port, pass, mount_point, url, de
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
source = ref s
|
source = ref s
|
||||||
if not output_icecast_vorbis_metadata then
|
if not icecast_vorbis_metadata then
|
||||||
source := add(normalize=false, [amplify(0.00001, noise()),s])
|
source := add(normalize=false, [amplify(0.00001, noise()),s])
|
||||||
end
|
end
|
||||||
if bitrate == 24 then
|
if bitrate == 24 then
|
||||||
|
@ -112,15 +112,30 @@ def output_to(output_type, type, bitrate, host, port, pass, mount_point, url, de
|
||||||
if user == "" then
|
if user == "" then
|
||||||
user_ref := "source"
|
user_ref := "source"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
description_ref = ref description
|
||||||
|
if description == "" then
|
||||||
|
description_ref := "N/A"
|
||||||
|
end
|
||||||
|
|
||||||
|
genre_ref = ref genre
|
||||||
|
if genre == "" then
|
||||||
|
genre_ref := "N/A"
|
||||||
|
end
|
||||||
|
|
||||||
|
url_ref = ref url
|
||||||
|
if url == "" then
|
||||||
|
url_ref := "N/A"
|
||||||
|
end
|
||||||
output.shoutcast = output.shoutcast(host = host,
|
output.shoutcast = output.shoutcast(host = host,
|
||||||
port = port,
|
port = port,
|
||||||
password = pass,
|
password = pass,
|
||||||
fallible = true,
|
fallible = true,
|
||||||
restart = true,
|
restart = true,
|
||||||
restart_delay = 5,
|
restart_delay = 5,
|
||||||
url = url,
|
url = !url_ref,
|
||||||
genre = genre,
|
genre = !genre_ref,
|
||||||
name = description,
|
name = !description_ref,
|
||||||
user = !user_ref)
|
user = !user_ref)
|
||||||
if bitrate == 24 then
|
if bitrate == 24 then
|
||||||
ignore(output.shoutcast(%mp3(bitrate = 24),s))
|
ignore(output.shoutcast(%mp3(bitrate = 24),s))
|
||||||
|
|
|
@ -140,7 +140,7 @@ class PypoFetch(Thread):
|
||||||
logger.info("Looking for changes...")
|
logger.info("Looking for changes...")
|
||||||
# look for changes
|
# look for changes
|
||||||
for s in setting:
|
for s in setting:
|
||||||
if "output_sound_device" in s[u'keyname']:
|
if "output_sound_device" in s[u'keyname'] or "icecast_vorbis_metadata" in s[u'keyname']:
|
||||||
dump, stream = s[u'keyname'].split('_', 1)
|
dump, stream = s[u'keyname'].split('_', 1)
|
||||||
state_change_restart[stream] = False
|
state_change_restart[stream] = False
|
||||||
# This is the case where restart is required no matter what
|
# This is the case where restart is required no matter what
|
||||||
|
@ -196,7 +196,6 @@ class PypoFetch(Thread):
|
||||||
buffer += temp
|
buffer += temp
|
||||||
buffer += "\n"
|
buffer += "\n"
|
||||||
fh.write(buffer)
|
fh.write(buffer)
|
||||||
fh.write("output_icecast_vorbis_metadata = false\n");
|
|
||||||
fh.write("log_file = \"/var/log/airtime/pypo-liquidsoap/<script>.log\"\n");
|
fh.write("log_file = \"/var/log/airtime/pypo-liquidsoap/<script>.log\"\n");
|
||||||
fh.close()
|
fh.close()
|
||||||
# restarting pypo.
|
# restarting pypo.
|
||||||
|
|
Loading…
Reference in New Issue