Refactor some stuff related to four streams, Liquidsoap is a piece of
shit too - no dynamic variables
This commit is contained in:
parent
6232e3f4f0
commit
0042fb50fe
|
@ -1308,7 +1308,7 @@ class ApiController extends Zend_Controller_Action
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getStreamParametersAction() {
|
public function getStreamParametersAction() {
|
||||||
$streams = array("s1", "s2", "s3");
|
$streams = array("s1", "s2", "s3", "s4");
|
||||||
$stream_params = array();
|
$stream_params = array();
|
||||||
foreach ($streams as $s) {
|
foreach ($streams as $s) {
|
||||||
$stream_params[$s] =
|
$stream_params[$s] =
|
||||||
|
|
|
@ -141,11 +141,7 @@ class PreferenceController extends Zend_Controller_Action
|
||||||
$this->view->headScript()->appendFile($baseUrl.'js/airtime/preferences/streamsetting.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
|
$this->view->headScript()->appendFile($baseUrl.'js/airtime/preferences/streamsetting.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
|
||||||
|
|
||||||
// get current settings
|
// get current settings
|
||||||
$temp = Application_Model_StreamSetting::getStreamSetting();
|
$setting = Application_Model_StreamSetting::getStreamSetting();
|
||||||
$setting = array();
|
|
||||||
foreach ($temp as $t) {
|
|
||||||
$setting[$t['keyname']] = $t['value'];
|
|
||||||
}
|
|
||||||
|
|
||||||
$name_map = array(
|
$name_map = array(
|
||||||
'ogg' => 'Ogg Vorbis',
|
'ogg' => 'Ogg Vorbis',
|
||||||
|
@ -208,6 +204,7 @@ class PreferenceController extends Zend_Controller_Action
|
||||||
$s1_data = array();
|
$s1_data = array();
|
||||||
$s2_data = array();
|
$s2_data = array();
|
||||||
$s3_data = array();
|
$s3_data = array();
|
||||||
|
$s4_data = array();
|
||||||
$values = array();
|
$values = array();
|
||||||
foreach($postData as $k=>$v) {
|
foreach($postData as $k=>$v) {
|
||||||
$v = explode('=', urldecode($v));
|
$v = explode('=', urldecode($v));
|
||||||
|
@ -447,7 +444,8 @@ class PreferenceController extends Zend_Controller_Action
|
||||||
public function getAdminPasswordStatusAction()
|
public function getAdminPasswordStatusAction()
|
||||||
{
|
{
|
||||||
$out = array();
|
$out = array();
|
||||||
for ($i=1; $i<=4; $i++) {
|
$num_of_stream = intval(Application_Model_Preference::GetNumOfStreams());
|
||||||
|
for ($i=1; $i<=$num_of_stream; $i++) {
|
||||||
if (Application_Model_StreamSetting::getAdminPass('s'.$i)=='') {
|
if (Application_Model_StreamSetting::getAdminPass('s'.$i)=='') {
|
||||||
$out["s".$i] = false;
|
$out["s".$i] = false;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -1,4 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
define("MAX_NUM_STREAMS", 4);
|
||||||
|
|
||||||
class Application_Model_StreamSetting
|
class Application_Model_StreamSetting
|
||||||
{
|
{
|
||||||
public static function setValue($key, $value, $type)
|
public static function setValue($key, $value, $type)
|
||||||
|
@ -41,7 +44,7 @@ class Application_Model_StreamSetting
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getValue($key)
|
public static function getValue($key, $default="")
|
||||||
{
|
{
|
||||||
$con = Propel::getConnection();
|
$con = Propel::getConnection();
|
||||||
|
|
||||||
|
@ -59,7 +62,7 @@ class Application_Model_StreamSetting
|
||||||
throw new Exception("Error: $msg");
|
throw new Exception("Error: $msg");
|
||||||
}
|
}
|
||||||
|
|
||||||
return $result ? $result : "";
|
return $result ? $result : $default;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Returns the id's of all streams that are enabled in an array. An
|
/* Returns the id's of all streams that are enabled in an array. An
|
||||||
|
@ -83,50 +86,62 @@ class Application_Model_StreamSetting
|
||||||
return $ids;
|
return $ids;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Returns only global data as array*/
|
|
||||||
public static function getGlobalData()
|
|
||||||
{
|
|
||||||
$con = Propel::getConnection();
|
|
||||||
$sql = "SELECT * "
|
|
||||||
."FROM cc_stream_setting "
|
|
||||||
."WHERE keyname IN ('output_sound_device', 'icecast_vorbis_metadata')";
|
|
||||||
|
|
||||||
$rows = Application_Common_Database::prepareAndExecute($sql, array(), 'all');
|
|
||||||
|
|
||||||
$data = array();
|
|
||||||
|
|
||||||
foreach ($rows as $row) {
|
|
||||||
$data[$row["keyname"]] = $row["value"];
|
|
||||||
}
|
|
||||||
|
|
||||||
return $data;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Returns all information related to a specific stream. An example
|
/* Returns all information related to a specific stream. An example
|
||||||
* of a stream id is 's1' or 's2'. */
|
* of a stream id is 's1' or 's2'. */
|
||||||
public static function getStreamData($p_streamId)
|
public static function getStreamData($p_streamId)
|
||||||
{
|
{
|
||||||
$con = Propel::getConnection();
|
$rows = CcStreamSettingQuery::create()
|
||||||
$streamId = pg_escape_string($p_streamId);
|
->filterByDbKeyName("${p_streamId}_%")
|
||||||
$sql = "SELECT * "
|
->find();
|
||||||
."FROM cc_stream_setting "
|
|
||||||
."WHERE keyname LIKE '{$streamId}_%'";
|
|
||||||
|
|
||||||
$stmt = $con->prepare($sql);
|
|
||||||
|
|
||||||
if ($stmt->execute()) {
|
|
||||||
$rows = $stmt->fetchAll();
|
|
||||||
} else {
|
|
||||||
$msg = implode(',', $stmt->errorInfo());
|
|
||||||
throw new Exception("Error: $msg");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
//This is way too much code because someone made only stupid decisions about how
|
||||||
|
//the layout of this table worked. The git history doesn't lie.
|
||||||
$data = array();
|
$data = array();
|
||||||
|
|
||||||
foreach ($rows as $row) {
|
foreach ($rows as $row) {
|
||||||
$data[$row["keyname"]] = $row["value"];
|
$key = $row->getDbKeyName();
|
||||||
|
$value = $row->getDbValue();
|
||||||
|
$type = $row->getDbType();
|
||||||
|
//Fix stupid defaults so we end up with proper typing in our JSON
|
||||||
|
if ($row->getDbType() == "boolean") {
|
||||||
|
if (empty($value)) {
|
||||||
|
//In Python, there is no way to tell the difference between ints and booleans,
|
||||||
|
//which we need to differentiate between for when we're generating the Liquidsoap
|
||||||
|
//config file. Returning booleans as a string is a workaround that lets us do that.
|
||||||
|
$value = "false";
|
||||||
|
}
|
||||||
|
$data[$key] = $value;
|
||||||
|
}
|
||||||
|
elseif ($row->getDbType() == "integer") {
|
||||||
|
if (empty($value)) {
|
||||||
|
$value = 0;
|
||||||
|
}
|
||||||
|
$data[$key] = intval($value);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$data[$key] = $value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Add in defaults in case they don't exist in the database.
|
||||||
|
$keyPrefix = $p_streamId . '_';
|
||||||
|
self::ensureKeyExists($keyPrefix . 'admin_pass', $data);
|
||||||
|
self::ensureKeyExists($keyPrefix . 'admin_user', $data);
|
||||||
|
self::ensureKeyExists($keyPrefix . 'bitrate', $data, 128);
|
||||||
|
self::ensureKeyExists($keyPrefix . 'channels', $data, "stereo");
|
||||||
|
self::ensureKeyExists($keyPrefix . 'description', $data);
|
||||||
|
self::ensureKeyExists($keyPrefix . 'enable', $data, "false");
|
||||||
|
self::ensureKeyExists($keyPrefix . 'genre', $data);
|
||||||
|
self::ensureKeyExists($keyPrefix . 'host', $data);
|
||||||
|
self::ensureKeyExists($keyPrefix . 'liquidsoap_error', $data, "waiting");
|
||||||
|
self::ensureKeyExists($keyPrefix . 'mount', $data);
|
||||||
|
self::ensureKeyExists($keyPrefix . 'name', $data);
|
||||||
|
self::ensureKeyExists($keyPrefix . 'output', $data);
|
||||||
|
self::ensureKeyExists($keyPrefix . 'pass', $data);
|
||||||
|
self::ensureKeyExists($keyPrefix . 'port', $data, 8000);
|
||||||
|
self::ensureKeyExists($keyPrefix . 'type', $data);
|
||||||
|
self::ensureKeyExists($keyPrefix . 'url', $data);
|
||||||
|
self::ensureKeyExists($keyPrefix . 'user', $data);
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,76 +149,41 @@ class Application_Model_StreamSetting
|
||||||
* make data easier to iterate over */
|
* make data easier to iterate over */
|
||||||
public static function getStreamDataNormalized($p_streamId)
|
public static function getStreamDataNormalized($p_streamId)
|
||||||
{
|
{
|
||||||
$con = Propel::getConnection();
|
$settings = self::getStreamData($p_streamId);
|
||||||
$streamId = pg_escape_string($p_streamId);
|
foreach ($settings as $key => $value)
|
||||||
$sql = "SELECT * "
|
{
|
||||||
."FROM cc_stream_setting "
|
unset($settings[$key]);
|
||||||
."WHERE keyname LIKE '{$streamId}_%'";
|
$newKey = substr($key, strlen($p_streamId)+1); //$p_streamId is assumed to be the key prefix.
|
||||||
|
$settings[$newKey] = $value;
|
||||||
$stmt = $con->prepare($sql);
|
|
||||||
|
|
||||||
if ($stmt->execute()) {
|
|
||||||
$rows = $stmt->fetchAll();
|
|
||||||
} else {
|
|
||||||
$msg = implode(',', $stmt->errorInfo());
|
|
||||||
throw new Exception("Error: $msg");
|
|
||||||
}
|
}
|
||||||
|
return $settings;
|
||||||
|
}
|
||||||
|
|
||||||
$data = array();
|
private static function ensureKeyExists($key, &$array, $default='')
|
||||||
|
{
|
||||||
foreach ($rows as $row) {
|
if (!array_key_exists($key, $array)) {
|
||||||
list($id, $key) = explode("_", $row["keyname"], 2);
|
$array[$key] = $default;
|
||||||
$data[$key] = $row["value"];
|
|
||||||
}
|
}
|
||||||
|
return $array;
|
||||||
return $data;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getStreamSetting()
|
public static function getStreamSetting()
|
||||||
{
|
{
|
||||||
$con = Propel::getConnection();
|
$settings = array();
|
||||||
$sql = "SELECT *"
|
$numStreams = MAX_NUM_STREAMS;
|
||||||
." FROM cc_stream_setting"
|
for ($streamIdx = 1; $streamIdx <= $numStreams; $streamIdx++)
|
||||||
." WHERE keyname not like '%_error' AND keyname not like '%_admin_%'";
|
{
|
||||||
|
$settings = array_merge($settings, self::getStreamData("s" . $streamIdx));
|
||||||
$rows = Application_Common_Database::prepareAndExecute($sql, array(), 'all');
|
|
||||||
|
|
||||||
$exists = array();
|
|
||||||
|
|
||||||
foreach ($rows as $r) {
|
|
||||||
if ($r['keyname'] == 'master_live_stream_port') {
|
|
||||||
$exists['master_live_stream_port'] = true;
|
|
||||||
} elseif ($r['keyname'] == 'master_live_stream_mp') {
|
|
||||||
$exists['master_live_stream_mp'] = true;
|
|
||||||
} elseif ($r['keyname'] == 'dj_live_stream_port') {
|
|
||||||
$exists['dj_live_stream_port'] = true;
|
|
||||||
} elseif ($r['keyname'] == 'dj_live_stream_mp') {
|
|
||||||
$exists['dj_live_stream_mp'] = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
$settings["master_live_stream_port"] = self::getMasterLiveStreamPort();
|
||||||
if (!isset($exists["master_live_stream_port"])) {
|
$settings["master_live_stream_mp"] = self::getMasterLiveStreamMountPoint();
|
||||||
$rows[] = array("keyname" =>"master_live_stream_port",
|
$settings["dj_live_stream_port"] = self::getDjLiveStreamPort();
|
||||||
"value"=>self::getMasterLiveStreamPort(),
|
$settings["dj_live_stream_mp"] = self::getDjLiveStreamMountPoint();
|
||||||
"type"=>"integer");
|
$settings["off_air_meta"] = self::getOffAirMeta();
|
||||||
}
|
$settings["icecast_vorbis_metadata"] = self::getIcecastVorbisMetadata();
|
||||||
if (!isset($exists["master_live_stream_mp"])) {
|
$settings["output_sound_device"] = self::getOutputSoundDevice();
|
||||||
$rows[] = array("keyname" =>"master_live_stream_mp",
|
$settings["output_sound_device_type"] = self::getOutputSoundDeviceType();
|
||||||
"value"=>self::getMasterLiveStreamMountPoint(),
|
return $settings;
|
||||||
"type"=>"string");
|
|
||||||
}
|
|
||||||
if (!isset($exists["dj_live_stream_port"])) {
|
|
||||||
$rows[] = array("keyname" =>"dj_live_stream_port",
|
|
||||||
"value"=>self::getDjLiveStreamPort(),
|
|
||||||
"type"=>"integer");
|
|
||||||
}
|
|
||||||
if (!isset($exists["dj_live_stream_mp"])) {
|
|
||||||
$rows[] = array("keyname" =>"dj_live_stream_mp",
|
|
||||||
"value"=>self::getDjLiveStreamMountPoint(),
|
|
||||||
"type"=>"string");
|
|
||||||
}
|
|
||||||
|
|
||||||
return $rows;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -211,7 +191,10 @@ class Application_Model_StreamSetting
|
||||||
{
|
{
|
||||||
$stream_setting = CcStreamSettingQuery::create()->filterByDbKeyName($key)->findOne();
|
$stream_setting = CcStreamSettingQuery::create()->filterByDbKeyName($key)->findOne();
|
||||||
if (is_null($stream_setting)) {
|
if (is_null($stream_setting)) {
|
||||||
throw new Exception("Keyname $key does not exist!");
|
//throw new Exception("Keyname $key does not exist!");
|
||||||
|
$stream_setting = new CcStreamSetting();
|
||||||
|
$stream_setting->setDbKeyName($key);
|
||||||
|
$stream_setting->setDbType("");
|
||||||
}
|
}
|
||||||
|
|
||||||
$stream_setting->setDbValue($value);
|
$stream_setting->setDbValue($value);
|
||||||
|
@ -411,7 +394,7 @@ class Application_Model_StreamSetting
|
||||||
|
|
||||||
public static function getMasterLiveStreamPort()
|
public static function getMasterLiveStreamPort()
|
||||||
{
|
{
|
||||||
return self::getValue("master_live_stream_port");
|
return self::getValue("master_live_stream_port", 8001);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function setMasterLiveStreamMountPoint($value)
|
public static function setMasterLiveStreamMountPoint($value)
|
||||||
|
@ -421,7 +404,7 @@ class Application_Model_StreamSetting
|
||||||
|
|
||||||
public static function getMasterLiveStreamMountPoint()
|
public static function getMasterLiveStreamMountPoint()
|
||||||
{
|
{
|
||||||
return self::getValue("master_live_stream_mp");
|
return self::getValue("master_live_stream_mp", "/master");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function setDjLiveStreamPort($value)
|
public static function setDjLiveStreamPort($value)
|
||||||
|
@ -431,7 +414,7 @@ class Application_Model_StreamSetting
|
||||||
|
|
||||||
public static function getDjLiveStreamPort()
|
public static function getDjLiveStreamPort()
|
||||||
{
|
{
|
||||||
return self::getValue("dj_live_stream_port");
|
return self::getValue("dj_live_stream_port", 8001);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function setDjLiveStreamMountPoint($value)
|
public static function setDjLiveStreamMountPoint($value)
|
||||||
|
@ -441,7 +424,7 @@ class Application_Model_StreamSetting
|
||||||
|
|
||||||
public static function getDjLiveStreamMountPoint()
|
public static function getDjLiveStreamMountPoint()
|
||||||
{
|
{
|
||||||
return self::getValue("dj_live_stream_mp");
|
return self::getValue("dj_live_stream_mp", "/show");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getAdminUser($stream){
|
public static function getAdminUser($stream){
|
||||||
|
@ -488,4 +471,16 @@ class Application_Model_StreamSetting
|
||||||
public static function SetListenerStatError($key, $v) {
|
public static function SetListenerStatError($key, $v) {
|
||||||
self::setValue($key, $v, 'string');
|
self::setValue($key, $v, 'string');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function getIcecastVorbisMetadata() {
|
||||||
|
return self::getValue("icecast_vorbis_metadata", "");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getOutputSoundDevice() {
|
||||||
|
return self::getValue("output_sound_device", "false");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getOutputSoundDeviceType() {
|
||||||
|
return self::getValue("output_sound_device_type", "");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,18 +10,23 @@ def generate_liquidsoap_config(ss):
|
||||||
fh.write("################################################\n")
|
fh.write("################################################\n")
|
||||||
fh.write("# THIS FILE IS AUTO GENERATED. DO NOT CHANGE!! #\n")
|
fh.write("# THIS FILE IS AUTO GENERATED. DO NOT CHANGE!! #\n")
|
||||||
fh.write("################################################\n")
|
fh.write("################################################\n")
|
||||||
|
fh.write("# The ignore() lines are to squash unused variable warnings\n")
|
||||||
|
|
||||||
for d in data:
|
for key, value in data.iteritems():
|
||||||
key = d['keyname']
|
try:
|
||||||
|
str_buffer = "%s = %s\n" % (key, int(value))
|
||||||
|
except ValueError:
|
||||||
|
try: # Is it a boolean?
|
||||||
|
if "true" in value or "false" in value:
|
||||||
|
str_buffer = "%s = %s\n" % (key, value.lower())
|
||||||
|
else:
|
||||||
|
raise ValueError() # Just drop into the except below
|
||||||
|
except: #Everything else is a string
|
||||||
|
str_buffer = "%s = \"%s\"\n" % (key, value)
|
||||||
|
|
||||||
str_buffer = d[u'keyname'] + " = "
|
|
||||||
if d[u'type'] == 'string':
|
|
||||||
val = '"%s"' % d['value']
|
|
||||||
else:
|
|
||||||
val = d[u'value']
|
|
||||||
val = val if len(val) > 0 else "0"
|
|
||||||
str_buffer = "%s = %s\n" % (key, val)
|
|
||||||
fh.write(str_buffer.encode('utf-8'))
|
fh.write(str_buffer.encode('utf-8'))
|
||||||
|
# ignore squashes unused variable errors from Liquidsoap
|
||||||
|
fh.write(("ignore(%s)\n" % key).encode('utf-8'))
|
||||||
|
|
||||||
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()
|
||||||
|
|
|
@ -104,7 +104,7 @@ server.register(namespace="vars",
|
||||||
fun (s) -> begin log("vars.bootup_time") time := s s end)
|
fun (s) -> begin log("vars.bootup_time") time := s s end)
|
||||||
server.register(namespace="streams",
|
server.register(namespace="streams",
|
||||||
"connection_status",
|
"connection_status",
|
||||||
fun (s) -> begin log("streams.connection_status") "1:#{!s1_connected},2:#{!s2_connected},3:#{!s3_connected}:#{!s4_connected}" end)
|
fun (s) -> begin log("streams.connection_status") "1:#{!s1_connected},2:#{!s2_connected},3:#{!s3_connected},4:#{!s4_connected}" end)
|
||||||
server.register(namespace="vars",
|
server.register(namespace="vars",
|
||||||
"default_dj_fade",
|
"default_dj_fade",
|
||||||
fun (s) -> begin log("vars.default_dj_fade") default_dj_fade := float_of_string(s) s end)
|
fun (s) -> begin log("vars.default_dj_fade") default_dj_fade := float_of_string(s) s end)
|
||||||
|
@ -400,9 +400,9 @@ if s3_enable == true then
|
||||||
s3_connected, s3_description, s3_channels)
|
s3_connected, s3_description, s3_channels)
|
||||||
end
|
end
|
||||||
|
|
||||||
%ifdef s4_enable
|
|
||||||
s4_namespace = ref ''
|
s4_namespace = ref ''
|
||||||
if s4_enable == true then
|
if s4_enable == true then
|
||||||
|
log("Stream 4 Enabled")
|
||||||
if s4_output == 'shoutcast' then
|
if s4_output == 'shoutcast' then
|
||||||
s4_namespace := "shoutcast_stream_4"
|
s4_namespace := "shoutcast_stream_4"
|
||||||
else
|
else
|
||||||
|
@ -413,7 +413,6 @@ if s4_enable == true then
|
||||||
s4_mount, s4_url, s4_name, s4_genre, s4_user, s, "4",
|
s4_mount, s4_url, s4_name, s4_genre, s4_user, s, "4",
|
||||||
s4_connected, s4_description, s4_channels)
|
s4_connected, s4_description, s4_channels)
|
||||||
end
|
end
|
||||||
%endif
|
|
||||||
|
|
||||||
|
|
||||||
command = "/usr/lib/airtime/pypo/bin/liquidsoap_scripts/notify.sh --liquidsoap-started &"
|
command = "/usr/lib/airtime/pypo/bin/liquidsoap_scripts/notify.sh --liquidsoap-started &"
|
||||||
|
|
|
@ -118,10 +118,10 @@ class ListenerStat(Thread):
|
||||||
else:
|
else:
|
||||||
stats.append(self.get_shoutcast_stats(v))
|
stats.append(self.get_shoutcast_stats(v))
|
||||||
self.update_listener_stat_error(v["mount"], 'OK')
|
self.update_listener_stat_error(v["mount"], 'OK')
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
try:
|
try:
|
||||||
self.update_listener_stat_error(v["mount"], str(e))
|
self.update_listener_stat_error(v["mount"], str(e))
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
self.logger.error('Exception: %s', e)
|
self.logger.error('Exception: %s', e)
|
||||||
|
|
||||||
return stats
|
return stats
|
||||||
|
|
|
@ -216,98 +216,9 @@ class PypoFetch(Thread):
|
||||||
TODO: This function needs to be way shorter, and refactored :/ - MK
|
TODO: This function needs to be way shorter, and refactored :/ - MK
|
||||||
"""
|
"""
|
||||||
def regenerate_liquidsoap_conf(self, setting):
|
def regenerate_liquidsoap_conf(self, setting):
|
||||||
existing = {}
|
self.restart_liquidsoap()
|
||||||
|
self.update_liquidsoap_connection_status()
|
||||||
|
|
||||||
setting = sorted(setting.items())
|
|
||||||
try:
|
|
||||||
fh = open('/etc/airtime/liquidsoap.cfg', 'r')
|
|
||||||
except IOError, e:
|
|
||||||
#file does not exist
|
|
||||||
self.restart_liquidsoap()
|
|
||||||
return
|
|
||||||
|
|
||||||
self.logger.info("Reading existing config...")
|
|
||||||
# read existing conf file and build dict
|
|
||||||
while True:
|
|
||||||
line = fh.readline()
|
|
||||||
|
|
||||||
# empty line means EOF
|
|
||||||
if not line:
|
|
||||||
break
|
|
||||||
|
|
||||||
line = line.strip()
|
|
||||||
|
|
||||||
if not len(line) or line[0] == "#":
|
|
||||||
continue
|
|
||||||
|
|
||||||
try:
|
|
||||||
key, value = line.split('=', 1)
|
|
||||||
except ValueError:
|
|
||||||
continue
|
|
||||||
key = key.strip()
|
|
||||||
value = value.strip()
|
|
||||||
value = value.replace('"', '')
|
|
||||||
if value == '' or value == "0":
|
|
||||||
value = ''
|
|
||||||
existing[key] = value
|
|
||||||
fh.close()
|
|
||||||
|
|
||||||
# dict flag for any change in config
|
|
||||||
change = {}
|
|
||||||
# this flag is to detect disable -> disable change
|
|
||||||
# in that case, we don't want to restart even if there are changes.
|
|
||||||
state_change_restart = {}
|
|
||||||
#restart flag
|
|
||||||
restart = False
|
|
||||||
|
|
||||||
self.logger.info("Looking for changes...")
|
|
||||||
# look for changes
|
|
||||||
for k, s in setting:
|
|
||||||
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
|
|
||||||
if (existing[s[u'keyname']] != str(s[u'value'])):
|
|
||||||
self.logger.info("'Need-to-restart' state detected for %s...", s[u'keyname'])
|
|
||||||
restart = True;
|
|
||||||
elif "master_live_stream_port" in s[u'keyname'] or "master_live_stream_mp" in s[u'keyname'] or "dj_live_stream_port" in s[u'keyname'] or "dj_live_stream_mp" in s[u'keyname'] or "off_air_meta" in s[u'keyname']:
|
|
||||||
if (existing[s[u'keyname']] != s[u'value']):
|
|
||||||
self.logger.info("'Need-to-restart' state detected for %s...", s[u'keyname'])
|
|
||||||
restart = True;
|
|
||||||
else:
|
|
||||||
stream, dump = s[u'keyname'].split('_', 1)
|
|
||||||
if "_output" in s[u'keyname']:
|
|
||||||
if (existing[s[u'keyname']] != s[u'value']):
|
|
||||||
self.logger.info("'Need-to-restart' state detected for %s...", s[u'keyname'])
|
|
||||||
restart = True;
|
|
||||||
state_change_restart[stream] = True
|
|
||||||
elif (s[u'value'] != 'disabled'):
|
|
||||||
state_change_restart[stream] = True
|
|
||||||
else:
|
|
||||||
state_change_restart[stream] = False
|
|
||||||
else:
|
|
||||||
# setting inital value
|
|
||||||
if stream not in change:
|
|
||||||
change[stream] = False
|
|
||||||
if not (s[u'value'] == existing[s[u'keyname']]):
|
|
||||||
self.logger.info("Keyname: %s, Current value: %s, New Value: %s", s[u'keyname'], existing[s[u'keyname']], s[u'value'])
|
|
||||||
change[stream] = True
|
|
||||||
|
|
||||||
# set flag change for sound_device alway True
|
|
||||||
self.logger.info("Change:%s, State_Change:%s...", change, state_change_restart)
|
|
||||||
|
|
||||||
for k, v in state_change_restart.items():
|
|
||||||
if k == "sound_device" and v:
|
|
||||||
restart = True
|
|
||||||
elif v and change[k]:
|
|
||||||
self.logger.info("'Need-to-restart' state detected for %s...", k)
|
|
||||||
restart = True
|
|
||||||
# rewrite
|
|
||||||
if restart:
|
|
||||||
self.restart_liquidsoap()
|
|
||||||
else:
|
|
||||||
self.logger.info("No change detected in setting...")
|
|
||||||
self.update_liquidsoap_connection_status()
|
|
||||||
|
|
||||||
@ls_timeout
|
@ls_timeout
|
||||||
def update_liquidsoap_connection_status(self):
|
def update_liquidsoap_connection_status(self):
|
||||||
|
|
|
@ -15,6 +15,7 @@ class PypoLiquidsoap():
|
||||||
"s1": None,
|
"s1": None,
|
||||||
"s2": None,
|
"s2": None,
|
||||||
"s3": None,
|
"s3": None,
|
||||||
|
"s4": None,
|
||||||
}
|
}
|
||||||
|
|
||||||
self.telnet_liquidsoap = TelnetLiquidsoap(telnet_lock, \
|
self.telnet_liquidsoap = TelnetLiquidsoap(telnet_lock, \
|
||||||
|
|
|
@ -83,12 +83,12 @@ class Notify:
|
||||||
|
|
||||||
# @pram time: time that LS started
|
# @pram time: time that LS started
|
||||||
def notify_liquidsoap_status(self, msg, stream_id, time):
|
def notify_liquidsoap_status(self, msg, stream_id, time):
|
||||||
logger.debug('#################################################')
|
logger.info('#################################################')
|
||||||
logger.debug('# Calling server to update liquidsoap status #')
|
logger.info('# Calling server to update liquidsoap status #')
|
||||||
logger.debug('#################################################')
|
logger.info('#################################################')
|
||||||
logger.debug('msg = ' + str(msg))
|
logger.info('msg = ' + str(msg))
|
||||||
response = self.api_client.notify_liquidsoap_status(msg, stream_id, time)
|
response = self.api_client.notify_liquidsoap_status(msg, stream_id, time)
|
||||||
logger.debug("Response: " + json.dumps(response))
|
logger.info("Response: " + json.dumps(response))
|
||||||
|
|
||||||
def notify_source_status(self, source_name, status):
|
def notify_source_status(self, source_name, status):
|
||||||
logger.debug('#################################################')
|
logger.debug('#################################################')
|
||||||
|
|
Loading…
Reference in New Issue