2015-01-02 08:16:54 +00:00
|
|
|
<?php
|
|
|
|
namespace Entity;
|
|
|
|
|
2017-05-29 10:47:22 +00:00
|
|
|
use AzuraCast\Radio\Frontend\FrontendAbstract;
|
2017-01-24 00:35:16 +00:00
|
|
|
use Doctrine\Common\Collections\ArrayCollection;
|
2017-08-17 18:28:48 +00:00
|
|
|
use Doctrine\Common\Collections\Collection;
|
2017-09-07 03:53:25 +00:00
|
|
|
use Doctrine\ORM\EntityManager;
|
2016-09-27 21:54:19 +00:00
|
|
|
use Interop\Container\ContainerInterface;
|
2015-01-02 08:16:54 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @Table(name="station")
|
2017-01-17 08:46:43 +00:00
|
|
|
* @Entity(repositoryClass="Entity\Repository\StationRepository")
|
2015-02-26 05:01:02 +00:00
|
|
|
* @HasLifecycleCallbacks
|
2015-01-02 08:16:54 +00:00
|
|
|
*/
|
2017-08-17 18:28:48 +00:00
|
|
|
class Station
|
2015-01-02 08:16:54 +00:00
|
|
|
{
|
2017-08-17 18:28:48 +00:00
|
|
|
/**
|
|
|
|
* @Column(name="id", type="integer")
|
|
|
|
* @Id
|
|
|
|
* @GeneratedValue(strategy="IDENTITY")
|
|
|
|
* @var int
|
|
|
|
*/
|
|
|
|
protected $id;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Column(name="name", type="string", length=100, nullable=true)
|
2017-12-08 09:51:08 +00:00
|
|
|
* @var string|null The full display name of the station.
|
2017-08-17 18:28:48 +00:00
|
|
|
*/
|
|
|
|
protected $name;
|
|
|
|
|
2017-12-08 09:51:08 +00:00
|
|
|
/**
|
|
|
|
* @Column(name="short_name", type="string", length=100, nullable=true)
|
|
|
|
* @var string|null The URL-friendly name for the station, typically auto-generated from the full station name.
|
|
|
|
*/
|
|
|
|
protected $short_name;
|
|
|
|
|
2017-08-17 18:28:48 +00:00
|
|
|
/**
|
|
|
|
* @Column(name="frontend_type", type="string", length=100, nullable=true)
|
|
|
|
* @var string|null
|
|
|
|
*/
|
|
|
|
protected $frontend_type;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Column(name="frontend_config", type="json_array", nullable=true)
|
|
|
|
* @var array|null
|
|
|
|
*/
|
|
|
|
protected $frontend_config;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Column(name="backend_type", type="string", length=100, nullable=true)
|
|
|
|
* @var string|null
|
|
|
|
*/
|
|
|
|
protected $backend_type;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Column(name="backend_config", type="json_array", nullable=true)
|
|
|
|
* @var array|null
|
|
|
|
*/
|
|
|
|
protected $backend_config;
|
|
|
|
|
2017-09-07 03:53:25 +00:00
|
|
|
/**
|
|
|
|
* @Column(name="adapter_api_key", type="string", length=150, nullable=true)
|
|
|
|
* @var string|null
|
|
|
|
*/
|
|
|
|
protected $adapter_api_key;
|
|
|
|
|
2017-08-17 18:28:48 +00:00
|
|
|
/**
|
|
|
|
* @Column(name="description", type="text", nullable=true)
|
|
|
|
* @var string|null
|
|
|
|
*/
|
|
|
|
protected $description;
|
|
|
|
|
|
|
|
/**
|
2017-08-29 03:44:51 +00:00
|
|
|
* @Column(name="url", type="string", length=255, nullable=true)
|
2017-08-17 18:28:48 +00:00
|
|
|
* @var string|null
|
|
|
|
*/
|
|
|
|
protected $url;
|
|
|
|
|
|
|
|
/**
|
2017-08-29 03:44:51 +00:00
|
|
|
* @Column(name="radio_base_dir", type="string", length=255, nullable=true)
|
2017-08-17 18:28:48 +00:00
|
|
|
* @var string|null
|
|
|
|
*/
|
|
|
|
protected $radio_base_dir;
|
|
|
|
|
|
|
|
/**
|
2017-08-29 03:44:51 +00:00
|
|
|
* @Column(name="radio_media_dir", type="string", length=255, nullable=true)
|
2017-08-17 18:28:48 +00:00
|
|
|
* @var string|null
|
|
|
|
*/
|
|
|
|
protected $radio_media_dir;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Column(name="nowplaying", type="array", nullable=true)
|
|
|
|
* @var mixed|null
|
|
|
|
*/
|
|
|
|
protected $nowplaying;
|
|
|
|
|
2017-09-07 03:53:25 +00:00
|
|
|
/**
|
|
|
|
* @Column(name="nowplaying_timestamp", type="integer", nullable=true)
|
|
|
|
* @var int
|
|
|
|
*/
|
|
|
|
protected $nowplaying_timestamp;
|
|
|
|
|
2017-08-17 18:28:48 +00:00
|
|
|
/**
|
|
|
|
* @Column(name="automation_settings", type="json_array", nullable=true)
|
|
|
|
* @var array|null
|
|
|
|
*/
|
|
|
|
protected $automation_settings;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Column(name="automation_timestamp", type="integer", nullable=true)
|
|
|
|
* @var int|null
|
|
|
|
*/
|
|
|
|
protected $automation_timestamp;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Column(name="enable_requests", type="boolean", nullable=false)
|
|
|
|
* @var bool
|
|
|
|
*/
|
|
|
|
protected $enable_requests;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Column(name="request_delay", type="integer", nullable=true)
|
|
|
|
* @var int|null
|
|
|
|
*/
|
|
|
|
protected $request_delay;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Column(name="request_threshold", type="integer", nullable=true)
|
|
|
|
* @var int|null
|
|
|
|
*/
|
|
|
|
protected $request_threshold;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Column(name="enable_streamers", type="boolean", nullable=false)
|
|
|
|
* @var bool
|
|
|
|
*/
|
|
|
|
protected $enable_streamers;
|
|
|
|
|
2017-09-18 03:27:32 +00:00
|
|
|
/**
|
|
|
|
* @Column(name="enable_public_page", type="boolean", nullable=false)
|
|
|
|
* @var bool
|
|
|
|
*/
|
|
|
|
protected $enable_public_page;
|
|
|
|
|
2017-08-17 18:28:48 +00:00
|
|
|
/**
|
|
|
|
* @Column(name="needs_restart", type="boolean")
|
|
|
|
* @var bool
|
|
|
|
*/
|
|
|
|
protected $needs_restart;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Column(name="has_started", type="boolean")
|
|
|
|
* @var bool
|
|
|
|
*/
|
|
|
|
protected $has_started;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @OneToMany(targetEntity="SongHistory", mappedBy="station")
|
|
|
|
* @OrderBy({"timestamp" = "DESC"})
|
|
|
|
* @var Collection
|
|
|
|
*/
|
|
|
|
protected $history;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @OneToMany(targetEntity="StationMedia", mappedBy="station")
|
|
|
|
* @var Collection
|
|
|
|
*/
|
|
|
|
protected $media;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @OneToMany(targetEntity="StationStreamer", mappedBy="station")
|
|
|
|
* @var Collection
|
|
|
|
*/
|
|
|
|
protected $streamers;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @OneToMany(targetEntity="RolePermission", mappedBy="station")
|
|
|
|
* @var Collection
|
|
|
|
*/
|
|
|
|
protected $permissions;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @OneToMany(targetEntity="StationPlaylist", mappedBy="station")
|
|
|
|
* @OrderBy({"type" = "ASC","weight" = "DESC"})
|
|
|
|
* @var Collection
|
|
|
|
*/
|
|
|
|
protected $playlists;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @OneToMany(targetEntity="StationMount", mappedBy="station")
|
|
|
|
* @var Collection
|
|
|
|
*/
|
|
|
|
protected $mounts;
|
|
|
|
|
2017-01-24 00:17:50 +00:00
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
$this->automation_timestamp = 0;
|
|
|
|
$this->enable_streamers = false;
|
|
|
|
$this->enable_requests = false;
|
2017-04-14 21:03:59 +00:00
|
|
|
|
2017-01-24 00:17:50 +00:00
|
|
|
$this->request_delay = 5;
|
2017-04-14 21:03:59 +00:00
|
|
|
$this->request_threshold = 15;
|
2017-01-24 00:17:50 +00:00
|
|
|
|
|
|
|
$this->needs_restart = false;
|
2017-06-06 18:07:18 +00:00
|
|
|
$this->has_started = false;
|
2017-09-18 03:27:32 +00:00
|
|
|
$this->enable_public_page = true;
|
2017-01-24 00:17:50 +00:00
|
|
|
|
|
|
|
$this->history = new ArrayCollection;
|
|
|
|
$this->media = new ArrayCollection;
|
|
|
|
$this->playlists = new ArrayCollection;
|
|
|
|
$this->mounts = new ArrayCollection;
|
|
|
|
$this->streamers = new ArrayCollection;
|
|
|
|
}
|
|
|
|
|
2015-01-02 08:16:54 +00:00
|
|
|
/**
|
2017-08-17 18:28:48 +00:00
|
|
|
* @return int
|
2015-01-02 08:16:54 +00:00
|
|
|
*/
|
2017-08-17 18:28:48 +00:00
|
|
|
public function getId(): int
|
|
|
|
{
|
|
|
|
return $this->id;
|
|
|
|
}
|
2015-01-02 08:16:54 +00:00
|
|
|
|
2017-08-17 18:28:48 +00:00
|
|
|
/**
|
|
|
|
* @return null|string
|
|
|
|
*/
|
|
|
|
public function getName(): ?string
|
|
|
|
{
|
|
|
|
return $this->name;
|
|
|
|
}
|
2015-01-02 08:16:54 +00:00
|
|
|
|
2017-08-17 18:28:48 +00:00
|
|
|
/**
|
2017-12-08 09:51:08 +00:00
|
|
|
* @param null|string $name
|
2017-08-17 18:28:48 +00:00
|
|
|
*/
|
2017-12-08 09:51:08 +00:00
|
|
|
public function setName(string $name = null)
|
2017-01-24 00:17:50 +00:00
|
|
|
{
|
2017-12-08 09:51:08 +00:00
|
|
|
$this->name = $name;
|
|
|
|
|
|
|
|
if (empty($this->short_name) && !empty($name)) {
|
|
|
|
$this->short_name = self::getStationShortName($name);
|
|
|
|
}
|
2017-01-24 00:17:50 +00:00
|
|
|
}
|
|
|
|
|
2017-08-17 18:28:48 +00:00
|
|
|
/**
|
2017-12-08 09:51:08 +00:00
|
|
|
* @return null|string
|
2017-08-17 18:28:48 +00:00
|
|
|
*/
|
2017-12-08 09:51:08 +00:00
|
|
|
public function getShortName(): ?string
|
2017-08-17 18:28:48 +00:00
|
|
|
{
|
2017-12-09 17:29:27 +00:00
|
|
|
return (!empty($this->short_name))
|
|
|
|
? $this->short_name
|
|
|
|
: self::getStationShortName($this->name);
|
2017-12-08 09:51:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param null|string $short_name
|
|
|
|
*/
|
|
|
|
public function setShortName(?string $short_name): void
|
|
|
|
{
|
2017-12-09 17:29:27 +00:00
|
|
|
$short_name = trim($short_name);
|
|
|
|
if (!empty($short_name)) {
|
|
|
|
$this->short_name = $short_name;
|
|
|
|
}
|
2017-08-17 18:28:48 +00:00
|
|
|
}
|
2015-02-16 07:46:37 +00:00
|
|
|
|
2017-08-17 18:28:48 +00:00
|
|
|
/**
|
|
|
|
* @return null|string
|
|
|
|
*/
|
|
|
|
public function getFrontendType(): ?string
|
|
|
|
{
|
|
|
|
return $this->frontend_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param null|string $frontend_type
|
|
|
|
*/
|
|
|
|
public function setFrontendType(string $frontend_type = null)
|
|
|
|
{
|
|
|
|
$this->frontend_type = $frontend_type;
|
|
|
|
}
|
2016-05-19 14:56:21 +00:00
|
|
|
|
2017-08-17 18:28:48 +00:00
|
|
|
/**
|
|
|
|
* @return array|null
|
|
|
|
*/
|
|
|
|
public function getFrontendConfig(): ?array
|
|
|
|
{
|
|
|
|
return $this->frontend_config;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param $frontend_config
|
|
|
|
* @param bool $force_overwrite
|
|
|
|
*/
|
2017-08-04 11:46:30 +00:00
|
|
|
public function setFrontendConfig($frontend_config, $force_overwrite = false)
|
|
|
|
{
|
|
|
|
$config = ($force_overwrite) ? [] : (array)$this->frontend_config;
|
|
|
|
foreach((array)$frontend_config as $cfg_key => $cfg_val) {
|
|
|
|
$config[$cfg_key] = $cfg_val;
|
|
|
|
}
|
|
|
|
$this->frontend_config = $config;
|
|
|
|
}
|
|
|
|
|
2017-01-24 00:17:50 +00:00
|
|
|
/**
|
2017-08-17 18:28:48 +00:00
|
|
|
* @return null|string
|
2017-01-24 00:17:50 +00:00
|
|
|
*/
|
2017-08-17 18:28:48 +00:00
|
|
|
public function getBackendType(): ?string
|
2017-01-24 00:17:50 +00:00
|
|
|
{
|
2017-08-17 18:28:48 +00:00
|
|
|
return $this->backend_type;
|
2017-01-24 00:17:50 +00:00
|
|
|
}
|
|
|
|
|
2017-08-17 18:28:48 +00:00
|
|
|
/**
|
|
|
|
* @param null|string $backend_type
|
|
|
|
*/
|
|
|
|
public function setBackendType(string $backend_type = null)
|
|
|
|
{
|
|
|
|
$this->backend_type = $backend_type;
|
|
|
|
}
|
2015-02-17 12:23:21 +00:00
|
|
|
|
2017-08-17 18:28:48 +00:00
|
|
|
/**
|
|
|
|
* @return array|null
|
|
|
|
*/
|
|
|
|
public function getBackendConfig(): ?array
|
|
|
|
{
|
|
|
|
return $this->backend_config;
|
|
|
|
}
|
2016-05-19 14:56:21 +00:00
|
|
|
|
2017-08-17 18:28:48 +00:00
|
|
|
/**
|
|
|
|
* @param $backend_config
|
|
|
|
* @param bool $force_overwrite
|
|
|
|
*/
|
2017-08-04 11:46:30 +00:00
|
|
|
public function setBackendConfig($backend_config, $force_overwrite = false)
|
|
|
|
{
|
|
|
|
$config = ($force_overwrite) ? [] : (array)$this->backend_config;
|
|
|
|
foreach((array)$backend_config as $cfg_key => $cfg_val) {
|
|
|
|
$config[$cfg_key] = $cfg_val;
|
|
|
|
}
|
|
|
|
$this->backend_config = $config;
|
|
|
|
}
|
|
|
|
|
2017-09-07 03:53:25 +00:00
|
|
|
/**
|
|
|
|
* @return null|string
|
|
|
|
*/
|
|
|
|
public function getAdapterApiKey(): ?string
|
|
|
|
{
|
|
|
|
return $this->adapter_api_key;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generate a random new adapter API key.
|
|
|
|
*/
|
|
|
|
public function generateAdapterApiKey()
|
|
|
|
{
|
|
|
|
$this->adapter_api_key = bin2hex(random_bytes(50));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Authenticate the supplied adapter API key.
|
|
|
|
*
|
|
|
|
* @param $api_key
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function validateAdapterApiKey($api_key)
|
|
|
|
{
|
|
|
|
return hash_equals($api_key, $this->adapter_api_key);
|
|
|
|
}
|
|
|
|
|
2017-01-24 00:17:50 +00:00
|
|
|
/**
|
2017-08-17 18:28:48 +00:00
|
|
|
* @return null|string
|
2017-01-24 00:17:50 +00:00
|
|
|
*/
|
2017-08-17 18:28:48 +00:00
|
|
|
public function getDescription(): ?string
|
2017-01-24 00:17:50 +00:00
|
|
|
{
|
2017-08-17 18:28:48 +00:00
|
|
|
return $this->description;
|
|
|
|
}
|
2017-01-24 00:35:16 +00:00
|
|
|
|
2017-08-17 18:28:48 +00:00
|
|
|
/**
|
|
|
|
* @param null|string $description
|
|
|
|
*/
|
|
|
|
public function setDescription(string $description = null)
|
|
|
|
{
|
|
|
|
$this->description = $description;
|
2017-01-24 00:17:50 +00:00
|
|
|
}
|
|
|
|
|
2017-08-17 18:28:48 +00:00
|
|
|
/**
|
|
|
|
* @return null|string
|
|
|
|
*/
|
|
|
|
public function getUrl(): ?string
|
|
|
|
{
|
|
|
|
return $this->url;
|
|
|
|
}
|
2016-05-06 08:57:34 +00:00
|
|
|
|
2017-08-17 18:28:48 +00:00
|
|
|
/**
|
|
|
|
* @param null|string $url
|
|
|
|
*/
|
|
|
|
public function setUrl(string $url = null)
|
|
|
|
{
|
|
|
|
$this->url = $url;
|
|
|
|
}
|
2017-04-23 20:37:10 +00:00
|
|
|
|
2017-08-17 18:28:48 +00:00
|
|
|
/**
|
|
|
|
* @return null|string
|
|
|
|
*/
|
|
|
|
public function getRadioBaseDir(): ?string
|
|
|
|
{
|
|
|
|
return $this->radio_base_dir;
|
|
|
|
}
|
2017-01-24 00:17:50 +00:00
|
|
|
|
2017-08-17 18:28:48 +00:00
|
|
|
/**
|
|
|
|
* @param $new_dir
|
|
|
|
*/
|
2017-05-10 09:27:22 +00:00
|
|
|
public function setRadioBaseDir($new_dir)
|
2017-05-10 09:01:38 +00:00
|
|
|
{
|
2017-05-10 09:27:22 +00:00
|
|
|
if (strcmp($this->radio_base_dir, $new_dir) !== 0) {
|
|
|
|
$this->radio_base_dir = $new_dir;
|
|
|
|
|
|
|
|
$radio_dirs = [
|
|
|
|
$this->radio_base_dir,
|
|
|
|
$this->getRadioMediaDir(),
|
|
|
|
$this->getRadioPlaylistsDir(),
|
|
|
|
$this->getRadioConfigDir()
|
|
|
|
];
|
|
|
|
foreach ($radio_dirs as $radio_dir) {
|
|
|
|
if (!file_exists($radio_dir)) {
|
|
|
|
mkdir($radio_dir, 0777);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-05-10 09:01:38 +00:00
|
|
|
}
|
|
|
|
|
2017-08-17 18:28:48 +00:00
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getRadioMediaDir(): string
|
|
|
|
{
|
|
|
|
return (!empty($this->radio_media_dir))
|
|
|
|
? $this->radio_media_dir
|
|
|
|
: $this->radio_base_dir.'/media';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getRadioPlaylistsDir(): string
|
|
|
|
{
|
|
|
|
return $this->radio_base_dir.'/playlists';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getRadioConfigDir(): string
|
|
|
|
{
|
|
|
|
return $this->radio_base_dir.'/config';
|
|
|
|
}
|
2017-01-24 00:17:50 +00:00
|
|
|
|
2017-08-17 18:28:48 +00:00
|
|
|
/**
|
|
|
|
* @param $new_dir
|
|
|
|
*/
|
|
|
|
public function setRadioMediaDir(string $new_dir)
|
2017-01-24 00:17:50 +00:00
|
|
|
{
|
2017-05-10 09:27:22 +00:00
|
|
|
if ($new_dir !== $this->radio_media_dir) {
|
2017-05-10 09:01:38 +00:00
|
|
|
$new_dir = trim($new_dir);
|
|
|
|
|
2017-05-10 09:27:22 +00:00
|
|
|
if (!empty($new_dir) && !file_exists($new_dir)) {
|
2017-05-10 09:01:38 +00:00
|
|
|
mkdir($new_dir, 0777, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->radio_media_dir = $new_dir;
|
|
|
|
}
|
2017-01-24 00:17:50 +00:00
|
|
|
}
|
|
|
|
|
2017-08-17 18:28:48 +00:00
|
|
|
/**
|
|
|
|
* @return mixed|null
|
|
|
|
*/
|
|
|
|
public function getNowplaying()
|
2017-05-10 09:27:22 +00:00
|
|
|
{
|
2017-08-17 18:28:48 +00:00
|
|
|
return $this->nowplaying;
|
2017-05-10 09:27:22 +00:00
|
|
|
}
|
|
|
|
|
2017-08-17 18:28:48 +00:00
|
|
|
/**
|
|
|
|
* @param mixed|null $nowplaying
|
|
|
|
*/
|
|
|
|
public function setNowplaying($nowplaying = null)
|
2017-05-10 09:27:22 +00:00
|
|
|
{
|
2017-08-17 18:28:48 +00:00
|
|
|
$this->nowplaying = $nowplaying;
|
2017-09-07 03:53:25 +00:00
|
|
|
$this->nowplaying_timestamp = time();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
public function getNowplayingTimestamp(): int
|
|
|
|
{
|
|
|
|
return (int)$this->nowplaying_timestamp;
|
2017-05-10 09:27:22 +00:00
|
|
|
}
|
|
|
|
|
2017-08-17 18:28:48 +00:00
|
|
|
/**
|
|
|
|
* @return array|null
|
|
|
|
*/
|
|
|
|
public function getAutomationSettings(): ?array
|
2017-01-24 00:17:50 +00:00
|
|
|
{
|
2017-08-17 18:28:48 +00:00
|
|
|
return $this->automation_settings;
|
2017-01-24 00:17:50 +00:00
|
|
|
}
|
|
|
|
|
2017-08-17 18:28:48 +00:00
|
|
|
/**
|
|
|
|
* @param array|null $automation_settings
|
|
|
|
*/
|
|
|
|
public function setAutomationSettings(array $automation_settings = null)
|
|
|
|
{
|
|
|
|
$this->automation_settings = $automation_settings;
|
|
|
|
}
|
2016-05-19 14:56:21 +00:00
|
|
|
|
2017-08-17 18:28:48 +00:00
|
|
|
/**
|
|
|
|
* @return int|null
|
|
|
|
*/
|
|
|
|
public function getAutomationTimestamp(): ?int
|
|
|
|
{
|
|
|
|
return $this->automation_timestamp;
|
|
|
|
}
|
2016-08-30 06:28:56 +00:00
|
|
|
|
2017-08-17 18:28:48 +00:00
|
|
|
/**
|
|
|
|
* @param int|null $automation_timestamp
|
|
|
|
*/
|
|
|
|
public function setAutomationTimestamp(int $automation_timestamp = null)
|
|
|
|
{
|
|
|
|
$this->automation_timestamp = $automation_timestamp;
|
|
|
|
}
|
2016-08-30 06:28:56 +00:00
|
|
|
|
2017-08-17 18:28:48 +00:00
|
|
|
/**
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function getEnableRequests(): bool
|
|
|
|
{
|
|
|
|
return $this->enable_requests;
|
|
|
|
}
|
2016-09-01 18:22:23 +00:00
|
|
|
|
2017-08-17 18:28:48 +00:00
|
|
|
/**
|
|
|
|
* @param bool $enable_requests
|
|
|
|
*/
|
|
|
|
public function setEnableRequests(bool $enable_requests)
|
|
|
|
{
|
|
|
|
$this->enable_requests = $enable_requests;
|
|
|
|
}
|
2016-09-04 23:24:53 +00:00
|
|
|
|
2017-08-17 18:28:48 +00:00
|
|
|
/**
|
|
|
|
* @return int|null
|
|
|
|
*/
|
|
|
|
public function getRequestDelay(): ?int
|
|
|
|
{
|
|
|
|
return $this->request_delay;
|
|
|
|
}
|
2017-04-14 21:03:59 +00:00
|
|
|
|
2017-08-17 18:28:48 +00:00
|
|
|
/**
|
|
|
|
* @param int|null $request_delay
|
|
|
|
*/
|
|
|
|
public function setRequestDelay(int $request_delay = null)
|
|
|
|
{
|
|
|
|
$this->request_delay = $request_delay;
|
|
|
|
}
|
2016-09-01 18:22:23 +00:00
|
|
|
|
2017-08-17 18:28:48 +00:00
|
|
|
/**
|
|
|
|
* @return int|null
|
|
|
|
*/
|
|
|
|
public function getRequestThreshold()
|
|
|
|
{
|
|
|
|
return $this->request_threshold;
|
|
|
|
}
|
2016-11-20 04:00:25 +00:00
|
|
|
|
2017-08-17 18:28:48 +00:00
|
|
|
/**
|
|
|
|
* @param int|null $request_threshold
|
|
|
|
*/
|
|
|
|
public function setRequestThreshold(int $request_threshold = null)
|
|
|
|
{
|
|
|
|
$this->request_threshold = $request_threshold;
|
|
|
|
}
|
2017-06-06 18:07:18 +00:00
|
|
|
|
2015-01-02 08:16:54 +00:00
|
|
|
/**
|
2017-08-17 18:28:48 +00:00
|
|
|
* @return bool
|
2015-01-02 08:16:54 +00:00
|
|
|
*/
|
2017-08-17 18:28:48 +00:00
|
|
|
public function getEnableStreamers(): bool
|
|
|
|
{
|
|
|
|
return $this->enable_streamers;
|
|
|
|
}
|
2015-01-02 08:16:54 +00:00
|
|
|
|
|
|
|
/**
|
2017-08-17 18:28:48 +00:00
|
|
|
* @param bool $enable_streamers
|
2015-01-02 08:16:54 +00:00
|
|
|
*/
|
2017-08-17 18:28:48 +00:00
|
|
|
public function setEnableStreamers(bool $enable_streamers)
|
|
|
|
{
|
|
|
|
$this->enable_streamers = $enable_streamers;
|
|
|
|
}
|
2015-01-02 08:16:54 +00:00
|
|
|
|
2017-09-18 03:27:32 +00:00
|
|
|
/**
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function isEnablePublicPage(): bool
|
|
|
|
{
|
|
|
|
return (bool)$this->enable_public_page;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param bool $enable_public_page
|
|
|
|
*/
|
|
|
|
public function setEnablePublicPage(bool $enable_public_page)
|
|
|
|
{
|
|
|
|
$this->enable_public_page = $enable_public_page;
|
|
|
|
}
|
|
|
|
|
2016-09-02 00:34:08 +00:00
|
|
|
/**
|
2017-08-17 18:28:48 +00:00
|
|
|
* @return bool
|
2016-09-02 00:34:08 +00:00
|
|
|
*/
|
2017-08-17 18:28:48 +00:00
|
|
|
public function getNeedsRestart(): bool
|
|
|
|
{
|
|
|
|
return $this->needs_restart;
|
|
|
|
}
|
2016-09-02 00:34:08 +00:00
|
|
|
|
2017-05-11 05:48:38 +00:00
|
|
|
/**
|
2017-08-17 18:28:48 +00:00
|
|
|
* @param bool $needs_restart
|
2017-05-11 05:48:38 +00:00
|
|
|
*/
|
2017-08-17 18:28:48 +00:00
|
|
|
public function setNeedsRestart(bool $needs_restart)
|
|
|
|
{
|
|
|
|
$this->needs_restart = $needs_restart;
|
|
|
|
}
|
2017-05-11 05:48:38 +00:00
|
|
|
|
2016-05-04 00:03:28 +00:00
|
|
|
/**
|
2017-08-17 18:28:48 +00:00
|
|
|
* @return bool
|
2016-05-04 00:03:28 +00:00
|
|
|
*/
|
2017-08-17 18:28:48 +00:00
|
|
|
public function getHasStarted(): bool
|
|
|
|
{
|
|
|
|
return $this->has_started;
|
|
|
|
}
|
2015-01-02 08:16:54 +00:00
|
|
|
|
2016-11-17 03:15:34 +00:00
|
|
|
/**
|
2017-08-17 18:28:48 +00:00
|
|
|
* @param bool $has_started
|
2016-11-17 03:15:34 +00:00
|
|
|
*/
|
2017-08-17 18:28:48 +00:00
|
|
|
public function setHasStarted(bool $has_started)
|
|
|
|
{
|
|
|
|
$this->has_started = $has_started;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return Collection
|
|
|
|
*/
|
|
|
|
public function getHistory(): Collection
|
|
|
|
{
|
|
|
|
return $this->history;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return Collection
|
|
|
|
*/
|
|
|
|
public function getMedia(): Collection
|
|
|
|
{
|
|
|
|
return $this->media;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return Collection
|
|
|
|
*/
|
|
|
|
public function getStreamers(): Collection
|
|
|
|
{
|
|
|
|
return $this->streamers;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return Collection
|
|
|
|
*/
|
|
|
|
public function getPermissions(): Collection
|
|
|
|
{
|
|
|
|
return $this->permissions;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return Collection
|
|
|
|
*/
|
|
|
|
public function getPlaylists(): Collection
|
|
|
|
{
|
|
|
|
return $this->playlists;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return Collection
|
|
|
|
*/
|
|
|
|
public function getMounts(): Collection
|
|
|
|
{
|
|
|
|
return $this->mounts;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return \AzuraCast\Radio\Frontend\FrontendAbstract
|
|
|
|
* @throws \Exception
|
|
|
|
*/
|
|
|
|
public function getFrontendAdapter(ContainerInterface $di)
|
|
|
|
{
|
|
|
|
$adapters = self::getFrontendAdapters();
|
|
|
|
|
|
|
|
if (!isset($adapters['adapters'][$this->frontend_type])) {
|
|
|
|
throw new \Exception('Adapter not found: ' . $this->frontend_type);
|
|
|
|
}
|
|
|
|
|
|
|
|
$class_name = $adapters['adapters'][$this->frontend_type]['class'];
|
|
|
|
|
|
|
|
return new $class_name($di, $this);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return \AzuraCast\Radio\Backend\BackendAbstract
|
|
|
|
* @throws \Exception
|
|
|
|
*/
|
|
|
|
public function getBackendAdapter(ContainerInterface $di)
|
|
|
|
{
|
|
|
|
$adapters = self::getBackendAdapters();
|
|
|
|
|
|
|
|
if (!isset($adapters['adapters'][$this->backend_type])) {
|
|
|
|
throw new \Exception('Adapter not found: ' . $this->backend_type);
|
|
|
|
}
|
|
|
|
|
|
|
|
$class_name = $adapters['adapters'][$this->backend_type]['class'];
|
|
|
|
|
|
|
|
return new $class_name($di, $this);
|
|
|
|
}
|
2016-11-17 03:15:34 +00:00
|
|
|
|
2016-12-12 23:01:28 +00:00
|
|
|
/**
|
|
|
|
* Write all configuration changes to the filesystem and reload supervisord.
|
|
|
|
*
|
|
|
|
* @param ContainerInterface $di
|
2017-09-18 03:27:32 +00:00
|
|
|
* @param bool $regen_auth_key Regenerate the API authorization key (will trigger a full reset of processes).
|
2016-12-12 23:01:28 +00:00
|
|
|
*/
|
2017-09-18 03:27:32 +00:00
|
|
|
public function writeConfiguration(ContainerInterface $di, $regen_auth_key = false)
|
2016-12-12 23:01:28 +00:00
|
|
|
{
|
2017-01-24 00:35:16 +00:00
|
|
|
if (APP_TESTING_MODE) {
|
2016-12-13 04:02:15 +00:00
|
|
|
return;
|
2017-01-24 00:35:16 +00:00
|
|
|
}
|
2016-12-13 04:02:15 +00:00
|
|
|
|
2017-09-07 03:53:25 +00:00
|
|
|
/** @var EntityManager $em */
|
2018-01-22 16:28:41 +00:00
|
|
|
$em = $di[EntityManager::class];
|
2017-09-07 03:53:25 +00:00
|
|
|
|
2017-09-18 03:27:32 +00:00
|
|
|
if ($regen_auth_key || empty($this->getAdapterApiKey())) {
|
|
|
|
$this->generateAdapterApiKey();
|
|
|
|
$em->persist($this);
|
|
|
|
$em->flush();
|
|
|
|
}
|
2017-09-07 03:53:25 +00:00
|
|
|
|
|
|
|
// Initialize adapters.
|
2016-12-12 23:01:28 +00:00
|
|
|
$config_path = $this->getRadioConfigDir();
|
|
|
|
$supervisor_config = [];
|
2017-01-24 00:35:16 +00:00
|
|
|
$supervisor_config_path = $config_path . '/supervisord.conf';
|
2016-12-12 23:01:28 +00:00
|
|
|
|
|
|
|
$frontend = $this->getFrontendAdapter($di);
|
|
|
|
$backend = $this->getBackendAdapter($di);
|
|
|
|
|
|
|
|
// If no processes need to be managed, remove any existing config.
|
2017-01-24 00:35:16 +00:00
|
|
|
if (!$frontend->hasCommand() && !$backend->hasCommand()) {
|
2016-12-12 23:01:28 +00:00
|
|
|
@unlink($supervisor_config_path);
|
2018-01-22 16:28:41 +00:00
|
|
|
$this->_reloadSupervisor($di[\Supervisor\Supervisor::class]);
|
2016-12-12 23:01:28 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Write config files for both backend and frontend.
|
|
|
|
$frontend->write();
|
|
|
|
$backend->write();
|
|
|
|
|
|
|
|
// Get group information
|
|
|
|
$backend_name = $backend->getProgramName();
|
|
|
|
list($backend_group, $backend_program) = explode(':', $backend_name);
|
|
|
|
|
|
|
|
$frontend_name = $frontend->getProgramName();
|
2017-09-07 03:53:25 +00:00
|
|
|
list(,$frontend_program) = explode(':', $frontend_name);
|
|
|
|
|
|
|
|
$frontend_watch_name = $frontend->getWatchProgramName();
|
|
|
|
list(,$frontend_watch_program) = explode(':', $frontend_watch_name);
|
2016-12-12 23:01:28 +00:00
|
|
|
|
|
|
|
// Write group section of config
|
|
|
|
$programs = [];
|
2017-01-24 00:35:16 +00:00
|
|
|
if ($backend->hasCommand()) {
|
2016-12-12 23:01:28 +00:00
|
|
|
$programs[] = $backend_program;
|
2017-01-24 00:35:16 +00:00
|
|
|
}
|
|
|
|
if ($frontend->hasCommand()) {
|
2016-12-12 23:01:28 +00:00
|
|
|
$programs[] = $frontend_program;
|
2017-01-24 00:35:16 +00:00
|
|
|
}
|
2017-09-07 03:53:25 +00:00
|
|
|
if ($frontend->hasWatchCommand()) {
|
|
|
|
$programs[] = $frontend_watch_program;
|
|
|
|
}
|
2016-12-12 23:01:28 +00:00
|
|
|
|
2017-01-24 00:35:16 +00:00
|
|
|
$supervisor_config[] = '[group:' . $backend_group . ']';
|
|
|
|
$supervisor_config[] = 'programs=' . implode(',', $programs);
|
2016-12-12 23:01:28 +00:00
|
|
|
$supervisor_config[] = '';
|
|
|
|
|
|
|
|
// Write frontend
|
2017-01-24 00:35:16 +00:00
|
|
|
if ($frontend->hasCommand()) {
|
|
|
|
$supervisor_config[] = '[program:' . $frontend_program . ']';
|
|
|
|
$supervisor_config[] = 'directory=' . $config_path;
|
|
|
|
$supervisor_config[] = 'command=' . $frontend->getCommand();
|
2016-12-12 23:01:28 +00:00
|
|
|
$supervisor_config[] = 'user=azuracast';
|
|
|
|
$supervisor_config[] = 'priority=90';
|
2017-06-04 10:56:20 +00:00
|
|
|
|
|
|
|
if (APP_INSIDE_DOCKER) {
|
|
|
|
$supervisor_config[] = 'stdout_logfile=/dev/stdout';
|
|
|
|
$supervisor_config[] = 'stdout_logfile_maxbytes=0';
|
2017-09-07 03:53:25 +00:00
|
|
|
$supervisor_config[] = 'stderr_logfile=/dev/stderr';
|
|
|
|
$supervisor_config[] = 'stderr_logfile_maxbytes=0';
|
|
|
|
}
|
|
|
|
|
|
|
|
$supervisor_config[] = '';
|
|
|
|
}
|
|
|
|
|
|
|
|
// Write frontend watcher program
|
|
|
|
if ($frontend->hasWatchCommand()) {
|
|
|
|
$supervisor_config[] = '[program:' . $frontend_watch_program . ']';
|
2017-09-27 04:33:00 +00:00
|
|
|
$supervisor_config[] = 'directory=/var/azuracast/servers/station-watcher';
|
2017-09-07 03:53:25 +00:00
|
|
|
$supervisor_config[] = 'command=' . $frontend->getWatchCommand();
|
|
|
|
$supervisor_config[] = 'user=azuracast';
|
|
|
|
$supervisor_config[] = 'priority=95';
|
|
|
|
|
|
|
|
if (APP_INSIDE_DOCKER) {
|
|
|
|
$supervisor_config[] = 'stdout_logfile=/dev/stdout';
|
|
|
|
$supervisor_config[] = 'stdout_logfile_maxbytes=0';
|
2017-06-04 10:56:20 +00:00
|
|
|
$supervisor_config[] = 'stderr_logfile=/dev/stderr';
|
|
|
|
$supervisor_config[] = 'stderr_logfile_maxbytes=0';
|
|
|
|
}
|
|
|
|
|
2016-12-12 23:01:28 +00:00
|
|
|
$supervisor_config[] = '';
|
|
|
|
}
|
|
|
|
|
|
|
|
// Write backend
|
2017-01-24 00:35:16 +00:00
|
|
|
if ($backend->hasCommand()) {
|
|
|
|
$supervisor_config[] = '[program:' . $backend_program . ']';
|
|
|
|
$supervisor_config[] = 'directory=' . $config_path;
|
|
|
|
$supervisor_config[] = 'command=' . $backend->getCommand();
|
2016-12-12 23:01:28 +00:00
|
|
|
$supervisor_config[] = 'user=azuracast';
|
|
|
|
$supervisor_config[] = 'priority=100';
|
2017-06-04 10:56:20 +00:00
|
|
|
|
|
|
|
if (APP_INSIDE_DOCKER) {
|
|
|
|
$supervisor_config[] = 'stdout_logfile=/dev/stdout';
|
|
|
|
$supervisor_config[] = 'stdout_logfile_maxbytes=0';
|
|
|
|
$supervisor_config[] = 'stderr_logfile=/dev/stderr';
|
|
|
|
$supervisor_config[] = 'stderr_logfile_maxbytes=0';
|
|
|
|
}
|
|
|
|
|
2016-12-12 23:01:28 +00:00
|
|
|
$supervisor_config[] = '';
|
|
|
|
}
|
|
|
|
|
|
|
|
// Write config contents
|
|
|
|
$supervisor_config_data = implode("\n", $supervisor_config);
|
|
|
|
file_put_contents($supervisor_config_path, $supervisor_config_data);
|
|
|
|
|
2018-01-22 16:28:41 +00:00
|
|
|
$this->_reloadSupervisor($di[\Supervisor\Supervisor::class]);
|
2017-04-08 19:34:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove configuration (i.e. prior to station removal) and trigger a Supervisor refresh.
|
|
|
|
* @param ContainerInterface $di
|
|
|
|
*/
|
|
|
|
public function removeConfiguration(ContainerInterface $di)
|
|
|
|
{
|
|
|
|
if (APP_TESTING_MODE) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$config_path = $this->getRadioConfigDir();
|
|
|
|
$supervisor_config_path = $config_path . '/supervisord.conf';
|
|
|
|
|
|
|
|
@unlink($supervisor_config_path);
|
|
|
|
|
2018-01-23 11:32:01 +00:00
|
|
|
$this->_reloadSupervisor($di[\Supervisor\Supervisor::class]);
|
2017-04-08 19:34:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Trigger a supervisord reload and restart all relevant services.
|
|
|
|
* @param \Supervisor\Supervisor $supervisor
|
|
|
|
*/
|
|
|
|
protected function _reloadSupervisor(\Supervisor\Supervisor $supervisor)
|
|
|
|
{
|
2016-12-12 23:01:28 +00:00
|
|
|
$reload_result = $supervisor->reloadConfig();
|
|
|
|
|
|
|
|
$reload_added = $reload_result[0][0];
|
|
|
|
$reload_changed = $reload_result[0][1];
|
|
|
|
$reload_removed = $reload_result[0][2];
|
|
|
|
|
2017-01-24 00:35:16 +00:00
|
|
|
foreach ($reload_removed as $group) {
|
2016-12-12 23:01:28 +00:00
|
|
|
$supervisor->stopProcessGroup($group);
|
|
|
|
$supervisor->removeProcessGroup($group);
|
|
|
|
}
|
|
|
|
|
2017-01-24 00:35:16 +00:00
|
|
|
foreach ($reload_changed as $group) {
|
2016-12-12 23:01:28 +00:00
|
|
|
$supervisor->stopProcessGroup($group);
|
|
|
|
$supervisor->removeProcessGroup($group);
|
|
|
|
$supervisor->addProcessGroup($group);
|
|
|
|
}
|
|
|
|
|
2017-01-24 00:35:16 +00:00
|
|
|
foreach ($reload_added as $group) {
|
2016-12-12 23:01:28 +00:00
|
|
|
$supervisor->addProcessGroup($group);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-24 00:17:50 +00:00
|
|
|
/**
|
|
|
|
* @param $name
|
|
|
|
* @return string
|
|
|
|
*/
|
2017-08-17 18:28:48 +00:00
|
|
|
public static function getStationShortName($name): string
|
2015-01-02 08:16:54 +00:00
|
|
|
{
|
2017-01-24 00:17:50 +00:00
|
|
|
return strtolower(preg_replace("/[^A-Za-z0-9_]/", '', str_replace(' ', '_', trim($name))));
|
|
|
|
}
|
2016-09-06 06:25:41 +00:00
|
|
|
|
2017-01-24 00:17:50 +00:00
|
|
|
/**
|
|
|
|
* @param $name
|
2017-08-17 18:28:48 +00:00
|
|
|
* @return string
|
2017-01-24 00:17:50 +00:00
|
|
|
*/
|
2017-08-17 18:28:48 +00:00
|
|
|
public static function getStationClassName($name): string
|
2017-01-24 00:17:50 +00:00
|
|
|
{
|
|
|
|
$name = preg_replace("/[^A-Za-z0-9_ ]/", '', $name);
|
|
|
|
$name = str_replace('_', ' ', $name);
|
|
|
|
$name = str_replace(' ', '', $name);
|
2017-01-24 00:35:16 +00:00
|
|
|
|
2017-01-24 00:17:50 +00:00
|
|
|
return $name;
|
|
|
|
}
|
2016-05-06 08:57:34 +00:00
|
|
|
|
2017-01-24 00:17:50 +00:00
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
*/
|
2017-08-17 18:28:48 +00:00
|
|
|
public static function getFrontendAdapters(): array
|
2017-01-24 00:17:50 +00:00
|
|
|
{
|
2017-05-19 09:29:22 +00:00
|
|
|
static $adapters;
|
|
|
|
|
|
|
|
if ($adapters === null) {
|
|
|
|
$adapters = [
|
|
|
|
'icecast' => [
|
2017-10-21 07:57:02 +00:00
|
|
|
'name' => sprintf(_('Use <b>%s</b> on this server'), 'Icecast 2.4'),
|
2017-05-19 09:29:22 +00:00
|
|
|
'class' => '\AzuraCast\Radio\Frontend\IceCast',
|
|
|
|
],
|
|
|
|
'shoutcast2' => [
|
2017-10-21 07:57:02 +00:00
|
|
|
'name' => sprintf(_('Use <b>%s</b> on this server'), 'Shoutcast 2'),
|
2017-05-19 09:29:22 +00:00
|
|
|
'class' => '\AzuraCast\Radio\Frontend\ShoutCast2',
|
|
|
|
],
|
|
|
|
'remote' => [
|
2017-10-21 07:57:02 +00:00
|
|
|
'name' => _('Connect to a <b>remote radio server</b>'),
|
2017-05-19 09:29:22 +00:00
|
|
|
'class' => '\AzuraCast\Radio\Frontend\Remote',
|
|
|
|
],
|
|
|
|
];
|
2017-05-19 06:38:17 +00:00
|
|
|
|
2017-05-19 09:29:22 +00:00
|
|
|
$adapters = array_filter($adapters, function($adapter_info) {
|
|
|
|
/** @var \AzuraCast\Radio\AdapterAbstract $adapter_class */
|
|
|
|
$adapter_class = $adapter_info['class'];
|
|
|
|
return $adapter_class::isInstalled();
|
|
|
|
});
|
|
|
|
}
|
2017-05-19 06:38:17 +00:00
|
|
|
|
2017-01-24 00:17:50 +00:00
|
|
|
return [
|
|
|
|
'default' => 'icecast',
|
2017-05-19 06:38:17 +00:00
|
|
|
'adapters' => $adapters,
|
2017-01-24 00:17:50 +00:00
|
|
|
];
|
2016-05-06 08:57:34 +00:00
|
|
|
}
|
|
|
|
|
2016-09-27 20:39:54 +00:00
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
*/
|
2017-08-17 18:28:48 +00:00
|
|
|
public static function getBackendAdapters(): array
|
2016-05-06 08:57:34 +00:00
|
|
|
{
|
2017-05-19 09:29:22 +00:00
|
|
|
static $adapters;
|
|
|
|
|
|
|
|
if ($adapters === null) {
|
|
|
|
$adapters = [
|
|
|
|
'liquidsoap' => [
|
2017-10-21 07:57:02 +00:00
|
|
|
'name' => sprintf(_('Use <b>%s</b> on this server'), 'LiquidSoap'),
|
2017-05-19 09:29:22 +00:00
|
|
|
'class' => '\AzuraCast\Radio\Backend\LiquidSoap',
|
|
|
|
],
|
|
|
|
'none' => [
|
2017-10-21 07:57:02 +00:00
|
|
|
'name' => _('<b>Do not use</b> an AutoDJ service'),
|
2017-05-19 09:29:22 +00:00
|
|
|
'class' => '\AzuraCast\Radio\Backend\None',
|
|
|
|
],
|
|
|
|
];
|
2017-05-19 06:38:17 +00:00
|
|
|
|
2017-05-19 09:29:22 +00:00
|
|
|
$adapters = array_filter($adapters, function ($adapter_info) {
|
|
|
|
/** @var \AzuraCast\Radio\AdapterAbstract $adapter_class */
|
|
|
|
$adapter_class = $adapter_info['class'];
|
|
|
|
return $adapter_class::isInstalled();
|
|
|
|
});
|
|
|
|
}
|
2017-05-19 06:38:17 +00:00
|
|
|
|
|
|
|
return [
|
2017-05-19 08:58:44 +00:00
|
|
|
'default' => 'liquidsoap',
|
2017-05-19 06:38:17 +00:00
|
|
|
'adapters' => $adapters,
|
|
|
|
];
|
2016-05-06 08:57:34 +00:00
|
|
|
}
|
2017-01-24 00:17:50 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve the API version of the object/array.
|
|
|
|
*
|
2017-05-29 10:47:22 +00:00
|
|
|
* @param FrontendAbstract $fa
|
2017-06-17 00:19:42 +00:00
|
|
|
* @return Api\Station
|
2017-01-24 00:17:50 +00:00
|
|
|
*/
|
2017-08-17 18:28:48 +00:00
|
|
|
public function api(FrontendAbstract $fa): Api\Station
|
2017-01-24 00:17:50 +00:00
|
|
|
{
|
2017-06-17 00:19:42 +00:00
|
|
|
$response = new Api\Station;
|
|
|
|
$response->id = (int)$this->id;
|
|
|
|
$response->name = (string)$this->name;
|
|
|
|
$response->shortcode = (string)$this->getShortName();
|
|
|
|
$response->description = (string)$this->description;
|
|
|
|
$response->frontend = (string)$this->frontend_type;
|
|
|
|
$response->backend = (string)$this->backend_type;
|
|
|
|
$response->listen_url = (string)$fa->getStreamUrl();
|
2017-10-08 22:27:47 +00:00
|
|
|
$response->is_public = (bool)$this->enable_public_page;
|
2017-06-17 00:19:42 +00:00
|
|
|
|
|
|
|
$mounts = [];
|
2017-05-29 10:47:22 +00:00
|
|
|
if ($fa->supportsMounts() && $this->mounts->count() > 0) {
|
|
|
|
foreach ($this->mounts as $mount) {
|
2017-06-17 00:19:42 +00:00
|
|
|
$mounts[] = $mount->api($fa);
|
2017-01-24 00:17:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-17 00:19:42 +00:00
|
|
|
$response->mounts = $mounts;
|
|
|
|
return $response;
|
2017-01-24 00:17:50 +00:00
|
|
|
}
|
2014-02-21 09:25:10 +00:00
|
|
|
}
|