AzuraCast/src/Radio/StereoTool.php

61 lines
1.4 KiB
PHP
Raw Permalink Normal View History

<?php
declare(strict_types=1);
namespace App\Radio;
use App\Entity;
use App\Environment;
2022-07-01 07:41:04 +00:00
use RuntimeException;
use Symfony\Component\Process\Process;
2022-05-23 07:50:52 +00:00
final class StereoTool
{
2022-05-23 07:50:52 +00:00
public static function isInstalled(): bool
{
2022-05-23 07:50:52 +00:00
return file_exists(self::getBinaryPath());
}
2022-05-23 07:50:52 +00:00
public static function getBinaryPath(): string
{
2022-05-23 07:50:52 +00:00
$environment = Environment::getInstance();
return $environment->getParentDirectory() . '/servers/stereo_tool/stereo_tool';
}
2022-05-23 07:50:52 +00:00
public static function isReady(Entity\Station $station): bool
{
2022-05-23 07:50:52 +00:00
if (!self::isInstalled()) {
return false;
}
$backendConfig = $station->getBackendConfig();
return !empty($backendConfig->getStereoToolConfigurationPath());
}
2022-05-23 07:50:52 +00:00
public static function getVersion(): ?string
{
2022-05-23 07:50:52 +00:00
if (!self::isInstalled()) {
return null;
}
2022-05-23 07:50:52 +00:00
$binaryPath = self::getBinaryPath();
$process = new Process([$binaryPath, '--help']);
$process->setWorkingDirectory(dirname($binaryPath));
$process->setTimeout(5.0);
try {
$process->run();
2022-07-01 07:41:04 +00:00
} catch (RuntimeException) {
return null;
}
if (!$process->isSuccessful()) {
return null;
}
preg_match('/STEREO TOOL ([.\d]+) CONSOLE APPLICATION/i', $process->getErrorOutput(), $matches);
return $matches[1] ?? null;
}
}