2011-08-15 22:10:46 +02:00
|
|
|
<?php
|
2015-03-11 00:15:38 +01:00
|
|
|
|
2021-10-11 16:10:47 +02:00
|
|
|
define('MAX_NUM_STREAMS', 4);
|
2015-03-11 00:15:38 +01:00
|
|
|
|
2012-07-16 03:17:13 +02:00
|
|
|
class Application_Model_StreamSetting
|
|
|
|
{
|
2012-07-10 05:32:21 +02:00
|
|
|
public static function setValue($key, $value, $type)
|
2012-04-01 21:51:03 +02:00
|
|
|
{
|
|
|
|
$con = Propel::getConnection();
|
2012-03-02 22:55:11 +01:00
|
|
|
|
2012-04-01 21:51:03 +02:00
|
|
|
// Check if key already exists
|
2021-10-11 16:10:47 +02:00
|
|
|
$sql = 'SELECT COUNT(*) FROM cc_stream_setting'
|
|
|
|
. ' WHERE keyname = :key';
|
2012-04-01 21:51:03 +02:00
|
|
|
|
2012-09-05 21:15:56 +02:00
|
|
|
$stmt = $con->prepare($sql);
|
|
|
|
$stmt->bindParam(':key', $key);
|
2021-10-11 16:10:47 +02:00
|
|
|
|
2012-09-05 21:15:56 +02:00
|
|
|
if ($stmt->execute()) {
|
|
|
|
$result = $stmt->fetchColumn(0);
|
|
|
|
} else {
|
|
|
|
$msg = implode(',', $stmt->errorInfo());
|
2021-10-11 16:10:47 +02:00
|
|
|
|
|
|
|
throw new Exception("Error: {$msg}");
|
2012-09-05 21:15:56 +02:00
|
|
|
}
|
2012-03-02 22:55:11 +01:00
|
|
|
|
2012-04-01 21:51:03 +02:00
|
|
|
if ($result == 1) {
|
2021-10-11 16:10:47 +02:00
|
|
|
$sql = 'UPDATE cc_stream_setting'
|
2022-07-07 20:01:15 +02:00
|
|
|
. ' SET value = :value, type = :type'
|
|
|
|
. ' WHERE keyname = :key';
|
2012-03-02 22:55:11 +01:00
|
|
|
} else {
|
2021-10-11 16:10:47 +02:00
|
|
|
$sql = 'INSERT INTO cc_stream_setting (keyname, value, type)'
|
2022-07-07 20:01:15 +02:00
|
|
|
. ' VALUES (:key, :value, :type)';
|
2012-03-02 22:55:11 +01:00
|
|
|
}
|
2012-04-01 21:51:03 +02:00
|
|
|
|
2012-09-05 21:15:56 +02:00
|
|
|
$stmt = $con->prepare($sql);
|
|
|
|
$stmt->bindParam(':key', $key);
|
|
|
|
$stmt->bindParam(':value', $value);
|
|
|
|
$stmt->bindParam(':type', $type);
|
2021-10-11 16:10:47 +02:00
|
|
|
|
2012-09-05 21:15:56 +02:00
|
|
|
if ($stmt->execute()) {
|
2022-03-14 11:15:04 +01:00
|
|
|
// do nothing
|
2012-09-05 21:15:56 +02:00
|
|
|
} else {
|
|
|
|
$msg = implode(',', $stmt->errorInfo());
|
2021-10-11 16:10:47 +02:00
|
|
|
|
|
|
|
throw new Exception("Error: {$msg}");
|
2012-09-05 21:15:56 +02:00
|
|
|
}
|
2012-03-02 22:55:11 +01:00
|
|
|
}
|
2012-04-01 21:51:03 +02:00
|
|
|
|
2021-10-11 16:10:47 +02:00
|
|
|
public static function getValue($key, $default = '')
|
2012-04-01 21:51:03 +02:00
|
|
|
{
|
2012-07-16 03:17:13 +02:00
|
|
|
$con = Propel::getConnection();
|
2021-10-11 16:10:47 +02:00
|
|
|
|
2022-03-14 11:15:04 +01:00
|
|
|
// Check if key already exists
|
2021-10-11 16:10:47 +02:00
|
|
|
$sql = 'SELECT value FROM cc_stream_setting'
|
2022-07-07 20:01:15 +02:00
|
|
|
. ' WHERE keyname = :key';
|
2012-03-02 22:55:11 +01:00
|
|
|
|
2012-09-05 21:15:56 +02:00
|
|
|
$stmt = $con->prepare($sql);
|
|
|
|
$stmt->bindParam(':key', $key);
|
2021-10-11 16:10:47 +02:00
|
|
|
|
2012-09-05 21:15:56 +02:00
|
|
|
if ($stmt->execute()) {
|
|
|
|
$result = $stmt->fetchColumn(0);
|
2012-07-10 05:32:21 +02:00
|
|
|
} else {
|
2012-09-05 21:15:56 +02:00
|
|
|
$msg = implode(',', $stmt->errorInfo());
|
2021-10-11 16:10:47 +02:00
|
|
|
|
|
|
|
throw new Exception("Error: {$msg}");
|
2012-03-02 22:55:11 +01:00
|
|
|
}
|
2012-09-05 21:15:56 +02:00
|
|
|
|
2015-03-11 00:15:38 +01:00
|
|
|
return $result ? $result : $default;
|
2012-03-02 22:55:11 +01:00
|
|
|
}
|
2015-02-20 21:50:40 +01:00
|
|
|
|
2015-03-23 17:37:22 +01:00
|
|
|
public static function getEnabledStreamData()
|
|
|
|
{
|
2021-10-11 16:10:47 +02:00
|
|
|
$streams = [];
|
2015-03-23 17:37:22 +01:00
|
|
|
$streamIds = self::getEnabledStreamIds();
|
|
|
|
foreach ($streamIds as $id) {
|
|
|
|
$streamData = self::getStreamData($id);
|
2021-10-11 16:10:47 +02:00
|
|
|
$prefix = $id . '_';
|
|
|
|
$host = $streamData[$prefix . 'host'];
|
|
|
|
$port = $streamData[$prefix . 'port'];
|
|
|
|
$mount = $streamData[$prefix . 'mount'];
|
|
|
|
if ($streamData[$prefix . 'output'] == 'shoutcast') {
|
2022-03-14 11:15:04 +01:00
|
|
|
$url = "http://{$host}:{$port}/;"; // The semi-colon is important to make Shoutcast stream URLs play instead turn into a page.
|
|
|
|
} else { // Icecast
|
2021-10-11 16:10:47 +02:00
|
|
|
$url = "http://{$host}:{$port}/{$mount}";
|
2015-06-09 23:14:33 +02:00
|
|
|
}
|
2021-10-11 16:10:47 +02:00
|
|
|
$streams[$id] = [
|
|
|
|
'url' => $url,
|
|
|
|
'codec' => $streamData[$prefix . 'type'],
|
|
|
|
'bitrate' => $streamData[$prefix . 'bitrate'],
|
|
|
|
'mobile' => $streamData[$prefix . 'mobile'],
|
|
|
|
];
|
2015-03-23 17:37:22 +01:00
|
|
|
}
|
2021-10-11 16:10:47 +02:00
|
|
|
|
2015-03-23 17:37:22 +01:00
|
|
|
return $streams;
|
|
|
|
}
|
|
|
|
|
2011-09-27 21:26:40 +02:00
|
|
|
/* Returns the id's of all streams that are enabled in an array. An
|
|
|
|
* example of the array returned in JSON notation is ["s1", "s2", "s3"] */
|
2012-04-01 21:51:03 +02:00
|
|
|
public static function getEnabledStreamIds()
|
|
|
|
{
|
|
|
|
$con = Propel::getConnection();
|
2021-10-11 16:10:47 +02:00
|
|
|
$sql = 'SELECT * '
|
2022-07-07 20:01:15 +02:00
|
|
|
. 'FROM cc_stream_setting '
|
|
|
|
. "WHERE keyname LIKE '%_enable' "
|
|
|
|
. "AND value='true'";
|
2021-10-11 16:10:47 +02:00
|
|
|
|
|
|
|
$ids = [];
|
2011-09-27 21:26:40 +02:00
|
|
|
|
2021-10-11 16:10:47 +02:00
|
|
|
$rows = Application_Common_Database::prepareAndExecute($sql, [], 'all');
|
2011-09-27 21:26:40 +02:00
|
|
|
|
2012-04-01 21:51:03 +02:00
|
|
|
foreach ($rows as $row) {
|
2021-10-11 16:10:47 +02:00
|
|
|
$ids[] = substr($row['keyname'], 0, strpos($row['keyname'], '_'));
|
2011-09-27 21:26:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return $ids;
|
|
|
|
}
|
2012-04-01 21:51:03 +02:00
|
|
|
|
2011-09-27 21:26:40 +02:00
|
|
|
/* Returns all information related to a specific stream. An example
|
|
|
|
* of a stream id is 's1' or 's2'. */
|
2012-04-01 21:51:03 +02:00
|
|
|
public static function getStreamData($p_streamId)
|
|
|
|
{
|
2015-03-11 00:15:38 +01:00
|
|
|
$rows = CcStreamSettingQuery::create()
|
2021-10-11 16:10:47 +02:00
|
|
|
->filterByDbKeyName("{$p_streamId}_%")
|
2022-01-23 19:15:55 +01:00
|
|
|
->find();
|
2011-09-27 21:26:40 +02:00
|
|
|
|
2022-03-14 11:15:04 +01:00
|
|
|
// 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.
|
2021-10-11 16:10:47 +02:00
|
|
|
$data = [];
|
2012-04-01 21:51:03 +02:00
|
|
|
foreach ($rows as $row) {
|
2015-03-11 00:15:38 +01:00
|
|
|
$key = $row->getDbKeyName();
|
|
|
|
$value = $row->getDbValue();
|
|
|
|
$type = $row->getDbType();
|
2022-03-14 11:15:04 +01:00
|
|
|
// Fix stupid defaults so we end up with proper typing in our JSON
|
2021-10-11 16:10:47 +02:00
|
|
|
if ($row->getDbType() == 'boolean') {
|
2015-03-11 00:15:38 +01:00
|
|
|
if (empty($value)) {
|
2022-03-14 11:15:04 +01:00
|
|
|
// 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.
|
2021-10-11 16:10:47 +02:00
|
|
|
$value = 'false';
|
2015-03-11 00:15:38 +01:00
|
|
|
}
|
|
|
|
$data[$key] = $value;
|
2021-10-11 16:10:47 +02:00
|
|
|
} elseif ($row->getDbType() == 'integer') {
|
2015-03-11 00:15:38 +01:00
|
|
|
if (empty($value)) {
|
|
|
|
$value = 0;
|
|
|
|
}
|
|
|
|
$data[$key] = intval($value);
|
2021-10-11 16:10:47 +02:00
|
|
|
} else {
|
2015-03-11 00:15:38 +01:00
|
|
|
$data[$key] = $value;
|
|
|
|
}
|
2011-09-27 21:26:40 +02:00
|
|
|
}
|
|
|
|
|
2022-03-14 11:15:04 +01:00
|
|
|
// Add in defaults in case they don't exist in the database.
|
2015-03-11 00:15:38 +01:00
|
|
|
$keyPrefix = $p_streamId . '_';
|
|
|
|
self::ensureKeyExists($keyPrefix . 'admin_pass', $data);
|
|
|
|
self::ensureKeyExists($keyPrefix . 'admin_user', $data);
|
|
|
|
self::ensureKeyExists($keyPrefix . 'bitrate', $data, 128);
|
2021-10-11 16:10:47 +02:00
|
|
|
self::ensureKeyExists($keyPrefix . 'channels', $data, 'stereo');
|
2015-03-11 00:15:38 +01:00
|
|
|
self::ensureKeyExists($keyPrefix . 'description', $data);
|
2021-10-11 16:10:47 +02:00
|
|
|
self::ensureKeyExists($keyPrefix . 'enable', $data, 'false');
|
2015-03-11 00:15:38 +01:00
|
|
|
self::ensureKeyExists($keyPrefix . 'genre', $data);
|
2021-01-01 16:28:50 +01:00
|
|
|
self::ensureKeyExists($keyPrefix . 'host', $data);
|
2021-10-11 16:10:47 +02:00
|
|
|
self::ensureKeyExists($keyPrefix . 'liquidsoap_error', $data, 'waiting');
|
2015-03-11 00:15:38 +01:00
|
|
|
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);
|
2015-04-01 19:05:08 +02:00
|
|
|
self::ensureKeyExists($keyPrefix . 'mobile', $data);
|
2015-03-11 00:15:38 +01:00
|
|
|
|
2011-09-27 21:26:40 +02:00
|
|
|
return $data;
|
2011-08-15 22:10:46 +02:00
|
|
|
}
|
2012-04-01 21:51:03 +02:00
|
|
|
|
2012-11-02 22:50:43 +01:00
|
|
|
/* Similar to getStreamData, but removes all sX prefixes to
|
|
|
|
* make data easier to iterate over */
|
|
|
|
public static function getStreamDataNormalized($p_streamId)
|
|
|
|
{
|
2015-03-11 00:15:38 +01:00
|
|
|
$settings = self::getStreamData($p_streamId);
|
2021-10-11 16:10:47 +02:00
|
|
|
foreach ($settings as $key => $value) {
|
2015-03-11 00:15:38 +01:00
|
|
|
unset($settings[$key]);
|
2022-03-14 11:15:04 +01:00
|
|
|
$newKey = substr($key, strlen($p_streamId) + 1); // $p_streamId is assumed to be the key prefix.
|
2015-03-11 00:15:38 +01:00
|
|
|
$settings[$newKey] = $value;
|
2012-11-02 22:50:43 +01:00
|
|
|
}
|
2021-10-11 16:10:47 +02:00
|
|
|
|
2015-03-11 00:15:38 +01:00
|
|
|
return $settings;
|
|
|
|
}
|
2012-11-02 22:50:43 +01:00
|
|
|
|
2021-10-11 16:10:47 +02:00
|
|
|
private static function ensureKeyExists($key, &$array, $default = '')
|
2015-03-11 00:15:38 +01:00
|
|
|
{
|
|
|
|
if (!array_key_exists($key, $array)) {
|
|
|
|
$array[$key] = $default;
|
2012-11-02 22:50:43 +01:00
|
|
|
}
|
2021-10-11 16:10:47 +02:00
|
|
|
|
2015-03-11 00:15:38 +01:00
|
|
|
return $array;
|
2012-11-02 22:50:43 +01:00
|
|
|
}
|
|
|
|
|
2012-04-01 21:51:03 +02:00
|
|
|
public static function getStreamSetting()
|
|
|
|
{
|
2021-10-11 16:10:47 +02:00
|
|
|
$settings = [];
|
2015-03-11 00:15:38 +01:00
|
|
|
$numStreams = MAX_NUM_STREAMS;
|
2021-10-11 16:10:47 +02:00
|
|
|
for ($streamIdx = 1; $streamIdx <= $numStreams; ++$streamIdx) {
|
|
|
|
$settings = array_merge($settings, self::getStreamData('s' . $streamIdx));
|
2012-03-02 22:55:11 +01:00
|
|
|
}
|
2021-10-11 16:10:47 +02:00
|
|
|
$settings['master_live_stream_port'] = self::getMasterLiveStreamPort();
|
|
|
|
$settings['master_live_stream_mp'] = self::getMasterLiveStreamMountPoint();
|
|
|
|
$settings['dj_live_stream_port'] = self::getDjLiveStreamPort();
|
|
|
|
$settings['dj_live_stream_mp'] = self::getDjLiveStreamMountPoint();
|
|
|
|
$settings['off_air_meta'] = self::getOffAirMeta();
|
|
|
|
$settings['icecast_vorbis_metadata'] = self::getIcecastVorbisMetadata();
|
|
|
|
$settings['output_sound_device'] = self::getOutputSoundDevice();
|
|
|
|
$settings['output_sound_device_type'] = self::getOutputSoundDeviceType();
|
|
|
|
|
2015-03-11 00:15:38 +01:00
|
|
|
return $settings;
|
2011-08-15 22:10:46 +02:00
|
|
|
}
|
2012-04-01 21:51:03 +02:00
|
|
|
|
2012-08-29 23:51:47 +02:00
|
|
|
private static function saveStreamSetting($key, $value)
|
|
|
|
{
|
|
|
|
$stream_setting = CcStreamSettingQuery::create()->filterByDbKeyName($key)->findOne();
|
|
|
|
if (is_null($stream_setting)) {
|
2022-03-14 11:15:04 +01:00
|
|
|
// throw new Exception("Keyname $key does not exist!");
|
2015-03-11 00:15:38 +01:00
|
|
|
$stream_setting = new CcStreamSetting();
|
|
|
|
$stream_setting->setDbKeyName($key);
|
2021-10-11 16:10:47 +02:00
|
|
|
$stream_setting->setDbType('');
|
2012-08-29 23:51:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$stream_setting->setDbValue($value);
|
|
|
|
$stream_setting->save();
|
|
|
|
}
|
|
|
|
|
2011-11-13 21:34:26 +01:00
|
|
|
/*
|
|
|
|
* function that take all the information of stream and sets them.
|
|
|
|
* This is used by stream setting via UI.
|
2012-04-01 21:51:03 +02:00
|
|
|
*
|
2011-11-13 21:34:26 +01:00
|
|
|
* @param $data - array that contains all the data. $data is [][] which
|
|
|
|
* contains multiple stream information
|
|
|
|
*/
|
2012-04-01 21:51:03 +02:00
|
|
|
public static function setStreamSetting($data)
|
|
|
|
{
|
2012-07-10 05:32:21 +02:00
|
|
|
foreach ($data as $key => $d) {
|
2021-10-11 16:10:47 +02:00
|
|
|
if ($key == 'output_sound_device' || $key == 'icecast_vorbis_metadata') {
|
|
|
|
$v = ($d == 1) ? 'true' : 'false';
|
2012-08-29 23:51:47 +02:00
|
|
|
|
|
|
|
self::saveStreamSetting($key, $v);
|
2021-10-11 16:10:47 +02:00
|
|
|
} elseif ($key == 'output_sound_device_type') {
|
2012-09-04 22:00:12 +02:00
|
|
|
self::saveStreamSetting($key, $d);
|
2012-07-16 03:17:13 +02:00
|
|
|
} elseif (is_array($d)) {
|
2011-08-18 19:53:12 +02:00
|
|
|
$temp = explode('_', $key);
|
|
|
|
$prefix = $temp[0];
|
2015-07-13 18:28:58 +02:00
|
|
|
// SAAS-876 - If we're using Airtime Pro streaming, set the stream to use the default settings
|
|
|
|
if (!Application_Model_Preference::getUsingCustomStreamSettings()) {
|
|
|
|
$d = array_merge($d, static::getDefaults($prefix));
|
|
|
|
}
|
2012-07-10 05:32:21 +02:00
|
|
|
foreach ($d as $k => $v) {
|
2021-10-11 16:10:47 +02:00
|
|
|
$keyname = $prefix . '_' . $k;
|
2011-11-29 22:25:30 +01:00
|
|
|
if ($k == 'enable') {
|
|
|
|
$v = $d['enable'] == 1 ? 'true' : 'false';
|
2011-08-18 19:53:12 +02:00
|
|
|
}
|
2011-09-01 22:02:06 +02:00
|
|
|
$v = trim($v);
|
2013-01-16 20:36:56 +01:00
|
|
|
if ($k != 'admin_pass') {
|
|
|
|
self::saveStreamSetting($keyname, $v);
|
|
|
|
} elseif ($v != 'xxxxxx') {
|
2022-07-07 23:45:15 +02:00
|
|
|
// We use 'xxxxxx' as the admin password placeholder so we
|
|
|
|
// only want to save it when it is a different string
|
2013-01-16 20:36:56 +01:00
|
|
|
self::saveStreamSetting($keyname, $v);
|
|
|
|
}
|
2011-08-18 19:53:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-04-01 21:51:03 +02:00
|
|
|
|
2015-07-13 18:28:58 +02:00
|
|
|
/**
|
2021-10-11 16:10:47 +02:00
|
|
|
* SAAS-876 - Get the default stream settings values for Airtime Pro streaming.
|
2015-07-13 18:28:58 +02:00
|
|
|
*
|
|
|
|
* @param int $prefix
|
|
|
|
*
|
|
|
|
* @return array array of default stream setting values
|
|
|
|
*/
|
2021-10-11 16:10:47 +02:00
|
|
|
public static function getDefaults($prefix)
|
|
|
|
{
|
2015-07-13 18:28:58 +02:00
|
|
|
$config = Config::getConfig();
|
2021-10-11 16:10:47 +02:00
|
|
|
|
|
|
|
return [
|
2022-07-07 23:45:15 +02:00
|
|
|
'host' => $config['public_url_raw']->getHost(),
|
2021-10-11 16:10:47 +02:00
|
|
|
'port' => DEFAULT_ICECAST_PORT,
|
2015-07-13 18:28:58 +02:00
|
|
|
'output' => 'icecast',
|
2021-10-11 16:10:47 +02:00
|
|
|
'user' => $config['stationId'],
|
|
|
|
'pass' => Application_Model_Preference::getDefaultIcecastPassword(),
|
2020-12-31 02:59:28 +01:00
|
|
|
// Manually setting default mountpoint
|
2022-06-09 18:05:35 +02:00
|
|
|
'mount' => Application_Model_Preference::getDefaultStreamMountpoint(),
|
2021-10-11 16:10:47 +02:00
|
|
|
];
|
2015-07-13 18:28:58 +02:00
|
|
|
}
|
|
|
|
|
2012-10-17 21:28:05 +02:00
|
|
|
/*
|
2015-07-13 18:28:58 +02:00
|
|
|
* Sets individual stream setting.
|
2012-10-17 21:28:05 +02:00
|
|
|
*
|
|
|
|
* $data - data array. $data is [].
|
|
|
|
* TODO: Make this SQL a prepared statement!
|
|
|
|
*
|
|
|
|
* Do not remove this function. It is called by airtime-system.php
|
|
|
|
*/
|
|
|
|
public static function setIndividualStreamSetting($data)
|
|
|
|
{
|
|
|
|
foreach ($data as $keyname => $v) {
|
2021-10-11 16:10:47 +02:00
|
|
|
$sql = 'UPDATE cc_stream_setting SET value=:v WHERE keyname=:keyname';
|
|
|
|
$map = [':v' => $v, ':keyname' => $keyname];
|
2013-05-09 21:08:47 +02:00
|
|
|
|
2021-10-11 16:10:47 +02:00
|
|
|
$res = Application_Common_Database::prepareAndExecute(
|
|
|
|
$sql,
|
|
|
|
$map,
|
|
|
|
Application_Common_Database::EXECUTE
|
|
|
|
);
|
2012-10-17 21:28:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-30 02:15:38 +01:00
|
|
|
/*
|
|
|
|
* Stores liquidsoap status if $boot_time > save time.
|
|
|
|
* save time is the time that user clicked save on stream setting page
|
|
|
|
*/
|
2021-10-11 16:10:47 +02:00
|
|
|
public static function setLiquidsoapError($stream_id, $msg, $boot_time = null)
|
2012-04-01 21:51:03 +02:00
|
|
|
{
|
2012-07-16 03:17:13 +02:00
|
|
|
$con = Propel::getConnection();
|
2012-04-01 21:51:03 +02:00
|
|
|
|
2011-11-30 02:15:38 +01:00
|
|
|
$update_time = Application_Model_Preference::GetStreamUpdateTimestemp();
|
2021-10-11 16:10:47 +02:00
|
|
|
|
2012-04-01 21:51:03 +02:00
|
|
|
if ($boot_time == null || $boot_time > $update_time) {
|
2021-10-11 16:10:47 +02:00
|
|
|
$keyname = 's' . $stream_id . '_liquidsoap_error';
|
|
|
|
$sql = 'SELECT COUNT(*) FROM cc_stream_setting'
|
|
|
|
. ' WHERE keyname = :keyname';
|
2012-09-05 21:15:56 +02:00
|
|
|
|
|
|
|
$stmt = $con->prepare($sql);
|
|
|
|
$stmt->bindParam(':keyname', $keyname);
|
|
|
|
|
|
|
|
if ($stmt->execute()) {
|
2021-10-11 16:10:47 +02:00
|
|
|
$result = $stmt->fetchColumn(0);
|
2012-09-05 21:15:56 +02:00
|
|
|
} else {
|
|
|
|
$msg = implode(',', $stmt->errorInfo());
|
2021-10-11 16:10:47 +02:00
|
|
|
|
|
|
|
throw new Exception("Error: {$msg}");
|
2012-09-05 21:15:56 +02:00
|
|
|
}
|
|
|
|
|
2012-04-01 21:51:03 +02:00
|
|
|
if ($result == 1) {
|
2021-10-11 16:10:47 +02:00
|
|
|
$sql = 'UPDATE cc_stream_setting'
|
|
|
|
. ' SET value = :msg'
|
|
|
|
. ' WHERE keyname = :keyname';
|
2012-04-01 21:51:03 +02:00
|
|
|
} else {
|
2021-10-11 16:10:47 +02:00
|
|
|
$sql = 'INSERT INTO cc_stream_setting (keyname, value, type)'
|
|
|
|
. " VALUES (:keyname, :msg, 'string')";
|
2012-09-05 21:15:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$stmt = $con->prepare($sql);
|
|
|
|
$stmt->bindParam(':keyname', $keyname);
|
|
|
|
$stmt->bindParam(':msg', $msg);
|
2021-10-11 16:10:47 +02:00
|
|
|
|
2012-09-05 21:15:56 +02:00
|
|
|
if ($stmt->execute()) {
|
2022-03-14 11:15:04 +01:00
|
|
|
// do nothing
|
2012-09-05 21:15:56 +02:00
|
|
|
} else {
|
|
|
|
$msg = implode(',', $stmt->errorInfo());
|
2021-10-11 16:10:47 +02:00
|
|
|
|
|
|
|
throw new Exception("Error: {$msg}");
|
2011-11-30 02:15:38 +01:00
|
|
|
}
|
2011-10-11 02:14:27 +02:00
|
|
|
}
|
|
|
|
}
|
2012-04-01 21:51:03 +02:00
|
|
|
|
|
|
|
public static function getLiquidsoapError($stream_id)
|
|
|
|
{
|
2012-07-16 03:17:13 +02:00
|
|
|
$con = Propel::getConnection();
|
2012-04-01 21:51:03 +02:00
|
|
|
|
2021-10-11 16:10:47 +02:00
|
|
|
$keyname = 's' . $stream_id . '_liquidsoap_error';
|
|
|
|
$sql = 'SELECT value FROM cc_stream_setting'
|
|
|
|
. ' WHERE keyname = :keyname';
|
2012-09-05 21:15:56 +02:00
|
|
|
|
|
|
|
$stmt = $con->prepare($sql);
|
|
|
|
$stmt->bindParam(':keyname', $keyname);
|
|
|
|
|
|
|
|
if ($stmt->execute()) {
|
2021-10-11 16:10:47 +02:00
|
|
|
$result = $stmt->fetchColumn(0);
|
2012-09-05 21:15:56 +02:00
|
|
|
} else {
|
|
|
|
$msg = implode(',', $stmt->errorInfo());
|
2021-10-11 16:10:47 +02:00
|
|
|
|
|
|
|
throw new Exception("Error: {$msg}");
|
2012-09-05 21:15:56 +02:00
|
|
|
}
|
2012-04-01 21:51:03 +02:00
|
|
|
|
2012-07-10 05:32:21 +02:00
|
|
|
return ($result !== false) ? $result : null;
|
2011-10-11 02:14:27 +02:00
|
|
|
}
|
2012-04-01 21:51:03 +02:00
|
|
|
|
|
|
|
public static function getStreamEnabled($stream_id)
|
|
|
|
{
|
2012-07-16 03:17:13 +02:00
|
|
|
$con = Propel::getConnection();
|
2012-04-01 21:51:03 +02:00
|
|
|
|
2021-10-11 16:10:47 +02:00
|
|
|
$keyname = 's' . $stream_id . '_enable';
|
|
|
|
$sql = 'SELECT value FROM cc_stream_setting'
|
2022-07-07 20:01:15 +02:00
|
|
|
. ' WHERE keyname = :keyname';
|
2012-09-05 21:15:56 +02:00
|
|
|
|
|
|
|
$stmt = $con->prepare($sql);
|
|
|
|
$stmt->bindParam(':keyname', $keyname);
|
|
|
|
|
|
|
|
if ($stmt->execute()) {
|
2021-10-11 16:10:47 +02:00
|
|
|
$result = $stmt->fetchColumn(0);
|
2011-11-29 22:25:30 +01:00
|
|
|
} else {
|
2012-09-05 21:15:56 +02:00
|
|
|
$msg = implode(',', $stmt->errorInfo());
|
2021-10-11 16:10:47 +02:00
|
|
|
|
|
|
|
throw new Exception("Error: {$msg}");
|
2011-10-13 20:20:08 +02:00
|
|
|
}
|
2012-07-16 03:17:13 +02:00
|
|
|
|
2021-10-11 16:10:47 +02:00
|
|
|
return $result != 'false';
|
2011-10-13 20:20:08 +02:00
|
|
|
}
|
2012-04-01 21:51:03 +02:00
|
|
|
|
2011-12-07 16:31:16 +01:00
|
|
|
/*
|
|
|
|
* Only returns info that is needed for data collection
|
|
|
|
* returns array('s1'=>array(keyname=>value))
|
|
|
|
*/
|
2012-04-01 21:51:03 +02:00
|
|
|
public static function getStreamInfoForDataCollection()
|
|
|
|
{
|
2012-07-16 03:17:13 +02:00
|
|
|
$con = Propel::getConnection();
|
2012-04-01 21:51:03 +02:00
|
|
|
|
2021-10-11 16:10:47 +02:00
|
|
|
$out = [];
|
2011-12-07 16:31:16 +01:00
|
|
|
$enabled_stream = self::getEnabledStreamIds();
|
2012-04-01 21:51:03 +02:00
|
|
|
|
|
|
|
foreach ($enabled_stream as $stream) {
|
2021-10-11 16:10:47 +02:00
|
|
|
$keys = ["{$stream}_output", "{$stream}_type", "{$stream}_bitrate", "{$stream}_host"];
|
2012-09-05 21:15:56 +02:00
|
|
|
$key_csv = implode(',', $keys);
|
2012-04-01 21:51:03 +02:00
|
|
|
|
2021-10-11 16:10:47 +02:00
|
|
|
$sql = 'SELECT keyname, value FROM cc_stream_setting'
|
|
|
|
. ' WHERE keyname IN (:key_csv)';
|
2012-09-05 21:15:56 +02:00
|
|
|
|
|
|
|
$stmt = $con->prepare($sql);
|
|
|
|
$stmt->bindParam(':key_csv', $key_csv);
|
|
|
|
|
|
|
|
if ($stmt->execute()) {
|
|
|
|
$rows = $stmt->fetchAll();
|
|
|
|
} else {
|
|
|
|
$msg = implode(',', $stmt->errorInfo());
|
2021-10-11 16:10:47 +02:00
|
|
|
|
|
|
|
throw new Exception("Error: {$msg}");
|
2012-09-05 21:15:56 +02:00
|
|
|
}
|
2012-04-01 21:51:03 +02:00
|
|
|
|
2021-10-11 16:10:47 +02:00
|
|
|
$info = [];
|
2012-04-01 21:51:03 +02:00
|
|
|
foreach ($rows as $r) {
|
2021-10-11 16:10:47 +02:00
|
|
|
$temp = explode('_', $r['keyname']);
|
2011-12-07 16:31:16 +01:00
|
|
|
$info[$temp[1]] = $r['value'];
|
2012-04-01 21:51:03 +02:00
|
|
|
$out[$stream] = $info;
|
2011-12-07 16:31:16 +01:00
|
|
|
}
|
|
|
|
}
|
2012-07-16 03:17:13 +02:00
|
|
|
|
2011-12-07 16:31:16 +01:00
|
|
|
return $out;
|
|
|
|
}
|
2012-04-01 21:51:03 +02:00
|
|
|
|
2012-07-10 05:32:21 +02:00
|
|
|
public static function setMasterLiveStreamPort($value)
|
|
|
|
{
|
2021-10-11 16:10:47 +02:00
|
|
|
self::setValue('master_live_stream_port', $value, 'integer');
|
2012-03-02 22:55:11 +01:00
|
|
|
}
|
2012-04-01 21:51:03 +02:00
|
|
|
|
2012-07-10 05:32:21 +02:00
|
|
|
public static function getMasterLiveStreamPort()
|
|
|
|
{
|
2021-10-11 16:10:47 +02:00
|
|
|
return self::getValue('master_live_stream_port', 8001);
|
2012-03-02 22:55:11 +01:00
|
|
|
}
|
2012-04-01 21:51:03 +02:00
|
|
|
|
2012-07-10 05:32:21 +02:00
|
|
|
public static function setMasterLiveStreamMountPoint($value)
|
|
|
|
{
|
2021-10-11 16:10:47 +02:00
|
|
|
self::setValue('master_live_stream_mp', $value, 'string');
|
2012-03-02 22:55:11 +01:00
|
|
|
}
|
2012-04-01 21:51:03 +02:00
|
|
|
|
2012-07-10 05:32:21 +02:00
|
|
|
public static function getMasterLiveStreamMountPoint()
|
|
|
|
{
|
2021-10-11 16:10:47 +02:00
|
|
|
return self::getValue('master_live_stream_mp', '/master');
|
2012-03-02 22:55:11 +01:00
|
|
|
}
|
2012-04-01 21:51:03 +02:00
|
|
|
|
2012-07-10 05:32:21 +02:00
|
|
|
public static function setDjLiveStreamPort($value)
|
|
|
|
{
|
2021-10-11 16:10:47 +02:00
|
|
|
self::setValue('dj_live_stream_port', $value, 'integer');
|
2012-03-02 22:55:11 +01:00
|
|
|
}
|
2012-04-01 21:51:03 +02:00
|
|
|
|
2012-07-10 05:32:21 +02:00
|
|
|
public static function getDjLiveStreamPort()
|
|
|
|
{
|
2021-10-11 16:10:47 +02:00
|
|
|
return self::getValue('dj_live_stream_port', 8002);
|
2012-03-02 22:55:11 +01:00
|
|
|
}
|
2012-04-01 21:51:03 +02:00
|
|
|
|
2012-07-10 05:32:21 +02:00
|
|
|
public static function setDjLiveStreamMountPoint($value)
|
|
|
|
{
|
2021-10-11 16:10:47 +02:00
|
|
|
self::setValue('dj_live_stream_mp', $value, 'string');
|
2012-03-02 22:55:11 +01:00
|
|
|
}
|
2012-04-01 21:51:03 +02:00
|
|
|
|
2012-07-10 05:32:21 +02:00
|
|
|
public static function getDjLiveStreamMountPoint()
|
|
|
|
{
|
2021-10-11 16:10:47 +02:00
|
|
|
return self::getValue('dj_live_stream_mp', '/show');
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function getAdminUser($stream)
|
|
|
|
{
|
|
|
|
return self::getValue($stream . '_admin_user');
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function setAdminUser($stream, $v)
|
|
|
|
{
|
|
|
|
self::setValue($stream . '_admin_user', $v, 'string');
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function getAdminPass($stream)
|
|
|
|
{
|
|
|
|
return self::getValue($stream . '_admin_pass');
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function setAdminPass($stream, $v)
|
|
|
|
{
|
|
|
|
self::setValue($stream . '_admin_pass', $v, 'string');
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function getOffAirMeta()
|
|
|
|
{
|
|
|
|
return self::getValue('off_air_meta');
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function setOffAirMeta($offAirMeta)
|
|
|
|
{
|
|
|
|
self::setValue('off_air_meta', $offAirMeta, 'string');
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function GetAllListenerStatErrors()
|
|
|
|
{
|
|
|
|
$sql = 'SELECT * FROM cc_stream_setting WHERE keyname like :p1';
|
|
|
|
$mounts = Application_Common_Database::prepareAndExecute($sql, [':p1' => '%_mount']);
|
|
|
|
|
|
|
|
$mps = [];
|
|
|
|
|
|
|
|
foreach ($mounts as $mount) {
|
|
|
|
$mps[] = "'" . $mount['value'] . "_listener_stat_error'";
|
|
|
|
}
|
|
|
|
|
|
|
|
$in = implode(',', $mps);
|
|
|
|
|
|
|
|
$sql = "SELECT * FROM cc_stream_setting WHERE keyname IN ( {$in} )";
|
|
|
|
|
|
|
|
return Application_Common_Database::prepareAndExecute($sql, []);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function SetListenerStatError($key, $v)
|
|
|
|
{
|
2013-01-08 23:32:27 +01:00
|
|
|
self::setValue($key, $v, 'string');
|
|
|
|
}
|
2015-03-11 00:15:38 +01:00
|
|
|
|
2021-10-11 16:10:47 +02:00
|
|
|
public static function getIcecastVorbisMetadata()
|
|
|
|
{
|
|
|
|
return self::getValue('icecast_vorbis_metadata', '');
|
2015-03-11 00:15:38 +01:00
|
|
|
}
|
|
|
|
|
2021-10-11 16:10:47 +02:00
|
|
|
public static function getOutputSoundDevice()
|
|
|
|
{
|
|
|
|
return self::getValue('output_sound_device', 'false');
|
2015-03-11 00:15:38 +01:00
|
|
|
}
|
|
|
|
|
2021-10-11 16:10:47 +02:00
|
|
|
public static function getOutputSoundDeviceType()
|
|
|
|
{
|
|
|
|
return self::getValue('output_sound_device_type', '');
|
2015-03-11 00:15:38 +01:00
|
|
|
}
|
2011-09-27 21:26:40 +02:00
|
|
|
}
|