2014-06-04 21:37:21 +02:00
|
|
|
<?php
|
2016-12-16 21:49:07 +01:00
|
|
|
namespace AzuraCast\Radio\Frontend;
|
2014-06-04 21:37:21 +02:00
|
|
|
|
2016-11-22 06:09:18 +01:00
|
|
|
use App\Debug;
|
|
|
|
use App\Utilities;
|
2014-06-04 21:37:21 +02:00
|
|
|
|
2016-11-22 06:09:18 +01:00
|
|
|
class ShoutCast2 extends FrontendAbstract
|
2014-06-04 21:37:21 +02:00
|
|
|
{
|
2017-04-13 00:19:02 +02:00
|
|
|
protected $supports_mounts = true;
|
2016-05-06 10:57:34 +02:00
|
|
|
|
2014-06-05 08:48:36 +02:00
|
|
|
/* Process a nowplaying record. */
|
2017-01-24 01:17:50 +01:00
|
|
|
protected function _getNowPlaying(&$np)
|
2017-01-22 21:58:40 +01:00
|
|
|
{
|
2017-01-24 01:17:50 +01:00
|
|
|
$fe_config = (array)$this->station->frontend_config;
|
|
|
|
$radio_port = $fe_config['port'];
|
2014-06-05 08:48:36 +02:00
|
|
|
|
2017-01-24 01:35:16 +01:00
|
|
|
$np_url = 'http://localhost:' . $radio_port . '/stats';
|
2017-01-24 01:17:50 +01:00
|
|
|
$return_raw = $this->getUrl($np_url);
|
|
|
|
|
2017-01-24 01:35:16 +01:00
|
|
|
if (empty($return_raw)) {
|
2017-01-24 01:17:50 +01:00
|
|
|
return false;
|
2017-01-24 01:35:16 +01:00
|
|
|
}
|
2017-01-24 01:17:50 +01:00
|
|
|
|
|
|
|
$current_data = \App\Export::xml_to_array($return_raw);
|
|
|
|
|
|
|
|
Debug::print_r($return_raw);
|
|
|
|
|
|
|
|
$song_data = $current_data['SHOUTCASTSERVER'];
|
|
|
|
|
|
|
|
Debug::print_r($song_data);
|
|
|
|
|
|
|
|
$np['meta']['status'] = 'online';
|
|
|
|
$np['meta']['bitrate'] = $song_data['BITRATE'];
|
|
|
|
$np['meta']['format'] = $song_data['CONTENT'];
|
|
|
|
|
|
|
|
$np['current_song'] = $this->getSongFromString($song_data['SONGTITLE'], '-');
|
|
|
|
|
|
|
|
$u_list = (int)$song_data['UNIQUELISTENERS'];
|
|
|
|
$t_list = (int)$song_data['CURRENTLISTENERS'];
|
2017-01-24 01:35:16 +01:00
|
|
|
$np['listeners'] = [
|
|
|
|
'current' => $this->getListenerCount($u_list, $t_list),
|
|
|
|
'unique' => $u_list,
|
|
|
|
'total' => $t_list,
|
|
|
|
];
|
2014-08-23 10:09:49 +02:00
|
|
|
|
|
|
|
return true;
|
2014-06-05 08:48:36 +02:00
|
|
|
}
|
2016-11-22 06:09:18 +01:00
|
|
|
|
2017-01-24 01:17:50 +01:00
|
|
|
public function read()
|
2016-11-22 06:09:18 +01:00
|
|
|
{
|
|
|
|
|
2017-01-24 01:17:50 +01:00
|
|
|
$config = $this->_getConfig();
|
2016-11-22 06:09:18 +01:00
|
|
|
|
2017-01-24 01:17:50 +01:00
|
|
|
$this->station->frontend_config = $this->_loadFromConfig($config);
|
2017-01-24 01:35:16 +01:00
|
|
|
|
2017-01-24 01:17:50 +01:00
|
|
|
return true;
|
2016-11-22 06:09:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function write()
|
|
|
|
{
|
|
|
|
$config = $this->_getDefaults();
|
|
|
|
|
|
|
|
$frontend_config = (array)$this->station->frontend_config;
|
|
|
|
|
2017-01-24 01:35:16 +01:00
|
|
|
if (!empty($frontend_config['port'])) {
|
2016-11-22 06:09:18 +01:00
|
|
|
$config['portbase'] = $frontend_config['port'];
|
2017-01-24 01:35:16 +01:00
|
|
|
}
|
2016-11-22 06:09:18 +01:00
|
|
|
|
2017-01-24 01:35:16 +01:00
|
|
|
if (!empty($frontend_config['source_pw'])) {
|
2016-11-22 06:09:18 +01:00
|
|
|
$config['password'] = $frontend_config['source_pw'];
|
2017-01-24 01:35:16 +01:00
|
|
|
}
|
2016-11-22 06:09:18 +01:00
|
|
|
|
2017-01-24 01:35:16 +01:00
|
|
|
if (!empty($frontend_config['admin_pw'])) {
|
2016-11-22 06:09:18 +01:00
|
|
|
$config['adminpassword'] = $frontend_config['admin_pw'];
|
2017-01-24 01:35:16 +01:00
|
|
|
}
|
2016-11-22 06:09:18 +01:00
|
|
|
|
2017-01-24 01:35:16 +01:00
|
|
|
if (!empty($frontend_config['custom_config'])) {
|
2016-11-22 06:09:18 +01:00
|
|
|
$custom_conf = $this->_processCustomConfig($frontend_config['custom_config']);
|
2017-01-24 01:35:16 +01:00
|
|
|
if (!empty($custom_conf)) {
|
2016-11-22 06:09:18 +01:00
|
|
|
$config = array_merge($config, $custom_conf);
|
2017-01-24 01:35:16 +01:00
|
|
|
}
|
2016-11-22 06:09:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Set any unset values back to the DB config.
|
|
|
|
$this->station->frontend_config = $this->_loadFromConfig($config);
|
|
|
|
|
|
|
|
$em = $this->di['em'];
|
|
|
|
$em->persist($this->station);
|
|
|
|
$em->flush();
|
|
|
|
|
|
|
|
$config_path = $this->station->getRadioConfigDir();
|
2017-01-24 01:35:16 +01:00
|
|
|
$sc_path = $config_path . '/sc_serv.conf';
|
2016-11-22 06:09:18 +01:00
|
|
|
|
|
|
|
$sc_file = '';
|
2017-01-24 01:35:16 +01:00
|
|
|
foreach ($config as $config_key => $config_value) {
|
|
|
|
$sc_file .= $config_key . '=' . str_replace("\n", "", $config_value) . "\n";
|
|
|
|
}
|
2016-11-22 06:09:18 +01:00
|
|
|
|
|
|
|
file_put_contents($sc_path, $sc_file);
|
|
|
|
}
|
|
|
|
|
2017-01-24 01:17:50 +01:00
|
|
|
/*
|
|
|
|
* Process Management
|
|
|
|
*/
|
2016-11-22 06:09:18 +01:00
|
|
|
|
2016-12-13 00:01:28 +01:00
|
|
|
public function getCommand()
|
2016-11-22 06:09:18 +01:00
|
|
|
{
|
|
|
|
$config_path = $this->station->getRadioConfigDir();
|
2017-01-24 01:35:16 +01:00
|
|
|
$sc_binary = realpath(APP_INCLUDE_ROOT . '/..') . '/servers/sc_serv';
|
|
|
|
$sc_config = $config_path . '/sc_serv.conf';
|
2016-11-22 06:09:18 +01:00
|
|
|
|
2017-01-24 01:35:16 +01:00
|
|
|
return $sc_binary . ' ' . $sc_config;
|
2016-11-22 06:09:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getStreamUrl()
|
|
|
|
{
|
|
|
|
return $this->getUrlForMount('/stream/1/');
|
|
|
|
}
|
|
|
|
|
2017-01-24 01:17:50 +01:00
|
|
|
public function getStreamUrls()
|
|
|
|
{
|
|
|
|
return [$this->getUrlForMount('/stream/1/')];
|
|
|
|
}
|
|
|
|
|
2016-11-22 06:09:18 +01:00
|
|
|
public function getUrlForMount($mount_name)
|
|
|
|
{
|
2017-01-24 01:35:16 +01:00
|
|
|
return $this->getPublicUrl() . $mount_name . '?' . time();
|
2017-01-24 01:17:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getAdminUrl()
|
|
|
|
{
|
2017-01-24 01:35:16 +01:00
|
|
|
return $this->getPublicUrl() . '/admin.cgi';
|
2016-11-22 06:09:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Configuration
|
|
|
|
*/
|
|
|
|
|
2017-01-24 01:17:50 +01:00
|
|
|
protected function _getConfig()
|
2016-11-22 06:09:18 +01:00
|
|
|
{
|
2017-01-24 01:17:50 +01:00
|
|
|
$config_dir = $this->station->getRadioConfigDir();
|
2017-01-24 01:35:16 +01:00
|
|
|
$config = @parse_ini_file($config_dir . '/sc_serv.conf', false, INI_SCANNER_RAW);
|
2017-01-24 01:17:50 +01:00
|
|
|
|
|
|
|
return $config;
|
2016-11-22 06:09:18 +01:00
|
|
|
}
|
|
|
|
|
2017-01-24 01:17:50 +01:00
|
|
|
protected function _loadFromConfig($config)
|
2016-11-22 06:09:18 +01:00
|
|
|
{
|
2017-01-24 01:17:50 +01:00
|
|
|
return [
|
|
|
|
'port' => $config['portbase'],
|
|
|
|
'source_pw' => $config['password'],
|
|
|
|
'admin_pw' => $config['adminpassword'],
|
|
|
|
];
|
2016-11-22 06:09:18 +01:00
|
|
|
}
|
|
|
|
|
2017-01-24 01:17:50 +01:00
|
|
|
protected function _getDefaults()
|
2016-11-22 06:09:18 +01:00
|
|
|
{
|
2017-01-24 01:17:50 +01:00
|
|
|
$config_path = $this->station->getRadioConfigDir();
|
2017-01-22 21:58:40 +01:00
|
|
|
|
2017-01-24 01:17:50 +01:00
|
|
|
$defaults = [
|
2017-01-24 01:35:16 +01:00
|
|
|
'password' => Utilities::generatePassword(),
|
2017-01-24 01:17:50 +01:00
|
|
|
'adminpassword' => Utilities::generatePassword(),
|
2017-01-24 01:35:16 +01:00
|
|
|
'logfile' => $config_path . '/sc_serv.log',
|
|
|
|
'w3clog' => $config_path . '/sc_w3c.log',
|
|
|
|
'publicserver' => 'never',
|
|
|
|
'banfile' => $config_path . '/sc_serv.ban',
|
|
|
|
'ripfile' => $config_path . '/sc_serv.rip',
|
|
|
|
'maxuser' => 500,
|
|
|
|
'portbase' => $this->_getRadioPort(),
|
2016-11-22 06:09:18 +01:00
|
|
|
];
|
|
|
|
|
2017-01-24 01:17:50 +01:00
|
|
|
return $defaults;
|
2016-11-22 06:09:18 +01:00
|
|
|
}
|
2017-04-13 00:19:02 +02:00
|
|
|
|
|
|
|
public function getDefaultMounts()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
[
|
|
|
|
'name' => '/radio.mp3',
|
|
|
|
'is_default' => 1,
|
|
|
|
'enable_streamers' => 1,
|
|
|
|
'enable_autodj' => 1,
|
|
|
|
'autodj_format' => 'mp3',
|
|
|
|
'autodj_bitrate' => 128,
|
|
|
|
]
|
|
|
|
];
|
|
|
|
}
|
2014-05-02 10:13:40 +02:00
|
|
|
}
|