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->setLabel('Enabled')
|
||||
->setRequired(false)
|
||||
->setValue($setting['output_sound_device'])
|
||||
->setValue(($setting['output_sound_device'] == "true")?1:0)
|
||||
->setDecorators(array('ViewHelper'));
|
||||
$this->addElement($output_sound_device);
|
||||
}
|
||||
|
|
|
@ -99,13 +99,9 @@ class Application_Form_StreamSettingSubForm extends Zend_Form_SubForm{
|
|||
->setDecorators(array('ViewHelper'));
|
||||
$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->setLabel("Mount Point")
|
||||
->setValue(isset($mount_info[0])?$mount_info[0]:"")
|
||||
->setValue(isset($setting[$prefix.'_mount'])?$setting[$prefix.'_mount']:"")
|
||||
->setDecorators(array('ViewHelper'));
|
||||
$this->addElement($mount);
|
||||
|
||||
|
|
|
@ -30,6 +30,7 @@ class Application_Model_StreamSetting {
|
|||
$v = 'disabled';
|
||||
}
|
||||
}
|
||||
$v = trim($v);
|
||||
$sql = "UPDATE cc_stream_setting SET value='$v' WHERE keyname='$keyname'";
|
||||
$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_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_type', 'ogg', 'string');
|
||||
|
|
|
@ -51,12 +51,14 @@ class AirtimeInstall{
|
|||
{
|
||||
global $CC_DBC;
|
||||
|
||||
echo "* Setting up default stream setting".PHP_EOL;
|
||||
$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('num_of_streams', '3');
|
||||
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 ('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_type', 'ogg', 'string');
|
||||
|
@ -135,6 +137,79 @@ class AirtimeInstall{
|
|||
}
|
||||
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{
|
||||
|
@ -284,14 +359,17 @@ class AirtimeIni200{
|
|||
public static function ReadPythonConfig($p_filename)
|
||||
{
|
||||
$values = array();
|
||||
|
||||
$lines = file($p_filename);
|
||||
$n=count($lines);
|
||||
for ($i=0; $i<$n; $i++) {
|
||||
if (strlen($lines[$i]) && !in_array(substr($lines[$i], 0, 1), array('#', PHP_EOL))){
|
||||
$info = explode("=", $lines[$i]);
|
||||
$values[trim($info[0])] = trim($info[1]);
|
||||
}
|
||||
|
||||
$fh = fopen($p_filename, 'r');
|
||||
|
||||
while(!feof($fh)){
|
||||
$line = fgets($fh);
|
||||
if(substr(trim($line), 0, 1) == '#' || trim($line) == ""){
|
||||
continue;
|
||||
}else{
|
||||
$info = explode('=', $line, 2);
|
||||
$values[trim($info[0])] = trim($info[1]);
|
||||
}
|
||||
}
|
||||
|
||||
return $values;
|
||||
|
@ -346,7 +424,8 @@ class AirtimeIni200{
|
|||
AirtimeIni200::CONF_FILE_PYPO,
|
||||
AirtimeIni200::CONF_FILE_RECORDER,
|
||||
AirtimeIni200::CONF_FILE_LIQUIDSOAP,
|
||||
AirtimeIni200::CONF_FILE_MONIT);
|
||||
AirtimeIni200::CONF_FILE_MONIT,
|
||||
AirtimeIni200::CONF_FILE_API_CLIENT);
|
||||
|
||||
// Backup the config files
|
||||
$suffix = date("Ymdhis")."-1.9.3";
|
||||
|
@ -388,9 +467,13 @@ class AirtimeIni200{
|
|||
echo "Could not copy recorder.cfg to /etc/airtime/. Exiting.";
|
||||
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.";
|
||||
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)){
|
||||
echo "Could not copy airtime-monit.cfg to /etc/monit/conf.d/. Exiting.";
|
||||
|
@ -429,6 +512,8 @@ AirtimeInstall::MigrateTablesToVersion(__DIR__, '20110829143306');
|
|||
|
||||
AirtimeInstall::SetDefaultStreamSetting();
|
||||
|
||||
AirtimeInstall::GetOldLiquidsoapCfgAndUpdate();
|
||||
|
||||
// restart monit
|
||||
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
|
||||
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
|
||||
|
|
|
@ -61,4 +61,4 @@ s3_genre = "genre"
|
|||
# when the metadata changes to a new track. Some versions of
|
||||
# mplayer and VLC have this problem. Enable this option at your
|
||||
# own risk!
|
||||
output_icecast_vorbis_metadata = false
|
||||
icecast_vorbis_metadata = false
|
||||
|
|
|
@ -139,10 +139,10 @@ try:
|
|||
buffer += temp
|
||||
buffer += "\n"
|
||||
fh.write(buffer)
|
||||
fh.write("output_icecast_vorbis_metadata = false\n");
|
||||
fh.write("log_file = \"/var/log/airtime/pypo-liquidsoap/<script>.log\"\n");
|
||||
fh.close()
|
||||
|
||||
else:
|
||||
print "Unable to connect to the Airtime server."
|
||||
print "Waiting for processes to start..."
|
||||
p = Popen("/etc/init.d/airtime-playout start", shell=True)
|
||||
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
|
||||
# mplayer and VLC have this problem. Enable this option at your
|
||||
# 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
|
||||
else
|
||||
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])
|
||||
end
|
||||
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
|
||||
user_ref := "source"
|
||||
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,
|
||||
port = port,
|
||||
password = pass,
|
||||
fallible = true,
|
||||
restart = true,
|
||||
restart_delay = 5,
|
||||
url = url,
|
||||
genre = genre,
|
||||
name = description,
|
||||
url = !url_ref,
|
||||
genre = !genre_ref,
|
||||
name = !description_ref,
|
||||
user = !user_ref)
|
||||
if bitrate == 24 then
|
||||
ignore(output.shoutcast(%mp3(bitrate = 24),s))
|
||||
|
|
|
@ -140,7 +140,7 @@ class PypoFetch(Thread):
|
|||
logger.info("Looking for changes...")
|
||||
# look for changes
|
||||
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)
|
||||
state_change_restart[stream] = False
|
||||
# This is the case where restart is required no matter what
|
||||
|
@ -196,7 +196,6 @@ class PypoFetch(Thread):
|
|||
buffer += temp
|
||||
buffer += "\n"
|
||||
fh.write(buffer)
|
||||
fh.write("output_icecast_vorbis_metadata = false\n");
|
||||
fh.write("log_file = \"/var/log/airtime/pypo-liquidsoap/<script>.log\"\n");
|
||||
fh.close()
|
||||
# restarting pypo.
|
||||
|
|
Loading…
Reference in New Issue