Remove unneeded Logger utility class.

This commit is contained in:
Buster "Silver Eagle" Neece 2020-12-19 20:17:49 -06:00
parent bc247a7257
commit d955d63151
No known key found for this signature in database
GPG Key ID: 6D9E12FF03411F4E
10 changed files with 247 additions and 210 deletions

View File

@ -6,6 +6,7 @@ use App\Http\Factory\ServerRequestFactory;
use DI;
use Doctrine\Common\Annotations\AnnotationRegistry;
use Invoker;
use Monolog\Registry;
use Psr\Container\ContainerInterface;
use Psr\Http\Message\ResponseFactoryInterface;
use Psr\Log\LoggerInterface;
@ -47,7 +48,7 @@ class AppFactory
$di = self::buildContainer($environment, $diDefinitions);
Logger::setInstance($di->get(LoggerInterface::class));
Registry::addLogger($di->get(LoggerInterface::class), 'app', true);
ServerRequestCreatorFactory::setSlimHttpDecoratorsAutomaticDetection(false);
ServerRequestCreatorFactory::setServerRequestCreator(new ServerRequestFactory());

View File

@ -1,20 +0,0 @@
<?php
namespace App;
use Psr\Log\LoggerInterface;
class Logger
{
protected static LoggerInterface $instance;
public static function getInstance(): LoggerInterface
{
return self::$instance;
}
public static function setInstance(LoggerInterface $instance): void
{
self::$instance = $instance;
}
}

View File

@ -9,8 +9,8 @@ use App\Exception\Supervisor\AlreadyRunningException;
use App\Exception\Supervisor\BadNameException;
use App\Exception\Supervisor\NotRunningException;
use App\Exception\SupervisorException;
use App\Logger;
use Doctrine\ORM\EntityManagerInterface;
use Psr\Log\LoggerInterface;
use Supervisor\Exception\Fault;
use Supervisor\Exception\SupervisorException as SupervisorLibException;
use Supervisor\Process;
@ -26,16 +26,20 @@ abstract class AbstractAdapter
protected EventDispatcher $dispatcher;
protected LoggerInterface $logger;
public function __construct(
Environment $environment,
EntityManagerInterface $em,
Supervisor $supervisor,
EventDispatcher $dispatcher
EventDispatcher $dispatcher,
LoggerInterface $logger
) {
$this->environment = $environment;
$this->em = $em;
$this->supervisor = $supervisor;
$this->dispatcher = $dispatcher;
$this->logger = $logger;
}
/**
@ -143,7 +147,7 @@ abstract class AbstractAdapter
try {
$this->supervisor->stopProcess($program_name);
Logger::getInstance()->info(
$this->logger->info(
'Adapter "' . static::class . '" stopped.',
['station_id' => $station->getId(), 'station_name' => $station->getName()]
);
@ -168,7 +172,7 @@ abstract class AbstractAdapter
try {
$this->supervisor->startProcess($program_name);
Logger::getInstance()->info(
$this->logger->info(
'Adapter "' . static::class . '" started.',
['station_id' => $station->getId(), 'station_name' => $station->getName()]
);

View File

@ -10,6 +10,7 @@ use App\Exception;
use App\Radio\Backend\Liquidsoap\ConfigWriter;
use Doctrine\ORM\EntityManagerInterface;
use Psr\Http\Message\UriInterface;
use Psr\Log\LoggerInterface;
use Supervisor\Supervisor;
class Liquidsoap extends AbstractBackend
@ -21,9 +22,10 @@ class Liquidsoap extends AbstractBackend
EntityManagerInterface $em,
Supervisor $supervisor,
EventDispatcher $dispatcher,
LoggerInterface $logger,
Entity\Repository\StationStreamerRepository $streamerRepo
) {
parent::__construct($environment, $em, $supervisor, $dispatcher);
parent::__construct($environment, $em, $supervisor, $dispatcher, $logger);
$this->streamerRepo = $streamerRepo;
}

View File

@ -7,11 +7,11 @@ use App\Environment;
use App\Event\Radio\WriteLiquidsoapConfiguration;
use App\Exception;
use App\Flysystem\FilesystemManager;
use App\Logger;
use App\Message;
use App\Radio\Adapters;
use App\Radio\Backend\Liquidsoap;
use Doctrine\ORM\EntityManagerInterface;
use Psr\Log\LoggerInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class ConfigWriter implements EventSubscriberInterface
@ -34,16 +34,20 @@ class ConfigWriter implements EventSubscriberInterface
protected Environment $environment;
protected LoggerInterface $logger;
public function __construct(
EntityManagerInterface $em,
Liquidsoap $liquidsoap,
FilesystemManager $filesystem,
Environment $environment
Environment $environment,
LoggerInterface $logger
) {
$this->em = $em;
$this->liquidsoap = $liquidsoap;
$this->filesystem = $filesystem;
$this->environment = $environment;
$this->logger = $logger;
}
/**
@ -84,9 +88,11 @@ class ConfigWriter implements EventSubscriberInterface
{
if ($event->isForEditing()) {
$divider = self::getDividerString();
$event->appendLines([
$divider . $sectionName . $divider,
]);
$event->appendLines(
[
$divider . $sectionName . $divider,
]
);
return;
}
@ -97,10 +103,12 @@ class ConfigWriter implements EventSubscriberInterface
$station = $event->getStation();
$settings = $station->getBackendConfig();
if (!empty($settings[$sectionName])) {
$event->appendLines([
'# Custom Configuration (Specified in Station Profile)',
$settings[$sectionName],
]);
$event->appendLines(
[
'# Custom Configuration (Specified in Station Profile)',
$settings[$sectionName],
]
);
}
}
@ -112,16 +120,20 @@ class ConfigWriter implements EventSubscriberInterface
public function writeHeaderFunctions(WriteLiquidsoapConfiguration $event): void
{
if ($event->isForEditing()) {
$event->prependLines([
'# ' . __('Welcome to the AzuraCast Liquidsoap configuration editor.'),
'# ' . __('Using this page, you can customize several sections of the Liquidsoap configuration.'),
'# ' . __('The non-editable sections are automatically generated by AzuraCast.'),
]);
$event->prependLines(
[
'# ' . __('Welcome to the AzuraCast Liquidsoap configuration editor.'),
'# ' . __('Using this page, you can customize several sections of the Liquidsoap configuration.'),
'# ' . __('The non-editable sections are automatically generated by AzuraCast.'),
]
);
} else {
$event->prependLines([
'# WARNING! This file is automatically generated by AzuraCast.',
'# Do not update it directly!',
]);
$event->prependLines(
[
'# WARNING! This file is automatically generated by AzuraCast.',
'# Do not update it directly!',
]
);
}
$this->writeCustomConfigurationSection($event, self::CUSTOM_TOP);
@ -131,25 +143,27 @@ class ConfigWriter implements EventSubscriberInterface
$pidfile = $fs->getFullPath(FilesystemManager::PREFIX_CONFIG . '://liquidsoap.pid');
$event->appendLines([
'set("init.daemon", false)',
'set("init.daemon.pidfile.path","' . $pidfile . '")',
'set("log.stdout", true)',
'set("log.file", false)',
'set("server.telnet",true)',
'set("server.telnet.bind_addr","' . ($this->environment->isDocker() ? '0.0.0.0' : '127.0.0.1') . '")',
'set("server.telnet.port", ' . $this->liquidsoap->getTelnetPort($station) . ')',
'set("harbor.bind_addrs",["0.0.0.0"])',
'',
'set("tag.encodings",["UTF-8","ISO-8859-1"])',
'set("encoder.encoder.export",["artist","title","album","song"])',
'',
'setenv("TZ", "' . self::cleanUpString($station->getTimezone()) . '")',
'',
'azuracast_api_auth = ref "' . self::cleanUpString($station->getAdapterApiKey()) . '"',
'ignore(azuracast_api_auth)',
'',
]);
$event->appendLines(
[
'set("init.daemon", false)',
'set("init.daemon.pidfile.path","' . $pidfile . '")',
'set("log.stdout", true)',
'set("log.file", false)',
'set("server.telnet",true)',
'set("server.telnet.bind_addr","' . ($this->environment->isDocker() ? '0.0.0.0' : '127.0.0.1') . '")',
'set("server.telnet.port", ' . $this->liquidsoap->getTelnetPort($station) . ')',
'set("harbor.bind_addrs",["0.0.0.0"])',
'',
'set("tag.encodings",["UTF-8","ISO-8859-1"])',
'set("encoder.encoder.export",["artist","title","album","song"])',
'',
'setenv("TZ", "' . self::cleanUpString($station->getTimezone()) . '")',
'',
'azuracast_api_auth = ref "' . self::cleanUpString($station->getAdapterApiKey()) . '"',
'ignore(azuracast_api_auth)',
'',
]
);
}
public function writePlaylistConfiguration(WriteLiquidsoapConfiguration $event): void
@ -185,7 +199,7 @@ class ConfigWriter implements EventSubscriberInterface
// Create a new default playlist if one doesn't exist.
if (!$hasDefaultPlaylist) {
Logger::getInstance()->info(
$this->logger->info(
'No default playlist existed for this station; new one was automatically created.',
['station_id' => $station->getId(), 'station_name' => $station->getName()]
);
@ -286,7 +300,9 @@ class ConfigWriter implements EventSubscriberInterface
} else {
switch ($playlist->getRemoteType()) {
case Entity\StationPlaylist::REMOTE_TYPE_PLAYLIST:
$playlistFunc = $playlistFuncName . '("' . self::cleanUpString($playlist->getRemoteUrl()) . '")';
$playlistFunc = $playlistFuncName . '("' . self::cleanUpString(
$playlist->getRemoteUrl()
) . '")';
$playlistConfigLines[] = $playlistVarName . ' = ' . $playlistFunc;
break;
@ -299,7 +315,9 @@ class ConfigWriter implements EventSubscriberInterface
$buffer = $playlist->getRemoteBuffer();
$buffer = ($buffer < 1) ? Entity\StationPlaylist::DEFAULT_REMOTE_BUFFER : $buffer;
$playlistConfigLines[] = $playlistVarName . ' = mksafe(' . $remote_url_function . '(max=' . $buffer . '., "' . self::cleanUpString($remote_url) . '"))';
$playlistConfigLines[] = $playlistVarName . ' = mksafe(' . $remote_url_function . '(max=' . $buffer . '., "' . self::cleanUpString(
$remote_url
) . '"))';
break;
}
}
@ -308,8 +326,12 @@ class ConfigWriter implements EventSubscriberInterface
$playlistConfigLines[] = $playlistVarName . ' = drop_metadata(' . $playlistVarName . ')';
}
$playlistConfigLines[] = $playlistVarName . ' = audio_to_stereo(id="stereo_' . self::cleanUpString($playlistVarName) . '", ' . $playlistVarName . ')';
$playlistConfigLines[] = $playlistVarName . ' = cue_cut(id="cue_' . self::cleanUpString($playlistVarName) . '", ' . $playlistVarName . ')';
$playlistConfigLines[] = $playlistVarName . ' = audio_to_stereo(id="stereo_' . self::cleanUpString(
$playlistVarName
) . '", ' . $playlistVarName . ')';
$playlistConfigLines[] = $playlistVarName . ' = cue_cut(id="cue_' . self::cleanUpString(
$playlistVarName
) . '", ' . $playlistVarName . ')';
if (Entity\StationPlaylist::TYPE_ADVANCED === $playlist->getType()) {
$playlistConfigLines[] = 'ignore(' . $playlistVarName . ')';
@ -345,7 +367,8 @@ class ConfigWriter implements EventSubscriberInterface
case Entity\StationPlaylist::TYPE_ONCE_PER_X_SONGS:
case Entity\StationPlaylist::TYPE_ONCE_PER_X_MINUTES:
if (Entity\StationPlaylist::TYPE_ONCE_PER_X_SONGS === $playlist->getType()) {
$playlistScheduleVar = 'rotate(weights=[1,' . $playlist->getPlayPerSongs() . '], [' . $playlistVarName . ', radio])';
$playlistScheduleVar = 'rotate(weights=[1,' . $playlist->getPlayPerSongs(
) . '], [' . $playlistVarName . ', radio])';
} else {
$delaySeconds = $playlist->getPlayPerMinutes() * 60;
$delayTrackSensitive = $playlist->backendInterruptOtherSongs() ? 'false' : 'true';
@ -374,7 +397,9 @@ class ConfigWriter implements EventSubscriberInterface
if ($scheduleItems->count() > 0) {
foreach ($scheduleItems as $scheduleItem) {
$playTime = '(' . $minutePlayTime . ') and (' . $this->getScheduledPlaylistPlayTime($scheduleItem) . ')';
$playTime = '(' . $minutePlayTime . ') and (' . $this->getScheduledPlaylistPlayTime(
$scheduleItem
) . ')';
$schedule_timing = '({ ' . $playTime . ' }, ' . $playlistVarName . ')';
if ($playlist->backendInterruptOtherSongs()) {
@ -396,27 +421,31 @@ class ConfigWriter implements EventSubscriberInterface
}
// Build "default" type playlists.
$event->appendLines([
'# Standard Playlists',
sprintf(
'radio = random(id="%s", weights=[%s], [%s])',
self::getVarName($station, 'standard_playlists'),
implode(', ', $genPlaylistWeights),
implode(', ', $genPlaylistVars)
),
]);
$event->appendLines(
[
'# Standard Playlists',
sprintf(
'radio = random(id="%s", weights=[%s], [%s])',
self::getVarName($station, 'standard_playlists'),
implode(', ', $genPlaylistWeights),
implode(', ', $genPlaylistVars)
),
]
);
if (!empty($scheduleSwitches)) {
$scheduleSwitches[] = '({true}, radio)';
$event->appendLines([
'# Standard Schedule Switches',
sprintf(
'radio = switch(id="%s", track_sensitive=true, [ %s ])',
self::getVarName($station, 'schedule_switch'),
implode(', ', $scheduleSwitches)
),
]);
$event->appendLines(
[
'# Standard Schedule Switches',
sprintf(
'radio = switch(id="%s", track_sensitive=true, [ %s ])',
self::getVarName($station, 'schedule_switch'),
implode(', ', $scheduleSwitches)
),
]
);
}
// Add in special playlists if necessary.
@ -429,7 +458,8 @@ class ConfigWriter implements EventSubscriberInterface
if (!$station->useManualAutoDJ()) {
$nextsongCommand = $this->getApiUrlCommand($station, 'nextsong');
$event->appendBlock(<<< EOF
$event->appendBlock(
<<< EOF
# AutoDJ Next Song Script
def azuracast_next_song() =
uri = {$nextsongCommand}
@ -449,51 +479,57 @@ class ConfigWriter implements EventSubscriberInterface
EOF
);
$event->appendLines([
sprintf(
'dynamic = request.dynamic.list(id="%s", timeout=20., retry_delay=3., azuracast_next_song)',
self::getVarName($station, 'next_song')
),
sprintf(
'dynamic = audio_to_stereo(id="%s", dynamic)',
self::getVarName($station, 'stereo_next_song')
),
sprintf(
'dynamic = cue_cut(id="%s", dynamic)',
self::getVarName($station, 'cue_next_song')
),
sprintf(
'radio = fallback(id="%s", track_sensitive = true, [dynamic, radio])',
self::getVarName($station, 'autodj_fallback')
),
]);
$event->appendLines(
[
sprintf(
'dynamic = request.dynamic.list(id="%s", timeout=20., retry_delay=3., azuracast_next_song)',
self::getVarName($station, 'next_song')
),
sprintf(
'dynamic = audio_to_stereo(id="%s", dynamic)',
self::getVarName($station, 'stereo_next_song')
),
sprintf(
'dynamic = cue_cut(id="%s", dynamic)',
self::getVarName($station, 'cue_next_song')
),
sprintf(
'radio = fallback(id="%s", track_sensitive = true, [dynamic, radio])',
self::getVarName($station, 'autodj_fallback')
),
]
);
}
if (!empty($scheduleSwitchesInterrupting)) {
$scheduleSwitchesInterrupting[] = '({true}, radio)';
$event->appendLines([
'# Interrupting Schedule Switches',
sprintf(
'radio = switch(id="%s", track_sensitive=false, [ %s ])',
self::getVarName($station, 'interrupt_switch'),
implode(', ', $scheduleSwitchesInterrupting)
),
]);
$event->appendLines(
[
'# Interrupting Schedule Switches',
sprintf(
'radio = switch(id="%s", track_sensitive=false, [ %s ])',
self::getVarName($station, 'interrupt_switch'),
implode(', ', $scheduleSwitchesInterrupting)
),
]
);
}
$event->appendLines([
'requests = request.queue(id="' . self::getVarName($station, 'requests') . '")',
'requests = audio_to_stereo(id="' . self::getVarName($station, 'stereo_requests') . '", requests)',
'requests = cue_cut(id="' . self::getVarName($station, 'cue_requests') . '", requests)',
sprintf(
'radio = fallback(id="%s", track_sensitive = true, [requests, radio])',
self::getVarName($station, 'requests_fallback')
),
'',
'add_skip_command(radio)',
'',
]);
$event->appendLines(
[
'requests = request.queue(id="' . self::getVarName($station, 'requests') . '")',
'requests = audio_to_stereo(id="' . self::getVarName($station, 'stereo_requests') . '", requests)',
'requests = cue_cut(id="' . self::getVarName($station, 'cue_requests') . '", requests)',
sprintf(
'radio = fallback(id="%s", track_sensitive = true, [requests, radio])',
self::getVarName($station, 'requests_fallback')
),
'',
'add_skip_command(radio)',
'',
]
);
}
/**
@ -517,11 +553,13 @@ class ConfigWriter implements EventSubscriberInterface
$playlistPath = $station->getRadioPlaylistsDir();
$playlistVarName = 'playlist_' . $playlist->getShortName();
$logger = Logger::getInstance();
$logger->info('Writing playlist file to disk...', [
'station' => $station->getName(),
'playlist' => $playlist->getName(),
]);
$this->logger->info(
'Writing playlist file to disk...',
[
'station' => $station->getName(),
'playlist' => $playlist->getName(),
]
);
$mediaBaseDir = $mediaStorage->getPath() . '/';
$playlistFile = [];
@ -532,7 +570,7 @@ class ConfigWriter implements EventSubscriberInterface
FROM App\Entity\StationMedia sm
JOIN sm.playlists spm
WHERE spm.playlist = :playlist
ORDER BY spm.weight ASC
ORDER BY spm.weight ASC
DQL
)->setParameter('playlist', $playlist);
@ -571,11 +609,14 @@ class ConfigWriter implements EventSubscriberInterface
try {
$this->liquidsoap->command($station, $playlistVarName . '.reload');
} catch (Exception $e) {
Logger::getInstance()->error('Could not reload playlist with AutoDJ.', [
'message' => $e->getMessage(),
'playlist' => $playlistVarName,
'station' => $station->getId(),
]);
$this->logger->error(
'Could not reload playlist with AutoDJ.',
[
'message' => $e->getMessage(),
'playlist' => $playlistVarName,
'station' => $station->getId(),
]
);
}
}
@ -704,9 +745,13 @@ class ConfigWriter implements EventSubscriberInterface
$crossDuration = $settings->getCrossfadeDuration();
if ($crossDuration > 0) {
$crossfadeIsSmart = (Entity\StationBackendConfiguration::CROSSFADE_SMART === $crossfade_type) ? 'true' : 'false';
$event->appendLines([
'radio = crossfade(smart=' . $crossfadeIsSmart . ', duration=' . self::toFloat($crossDuration) . ',fade_out=' . self::toFloat($crossfade) . ',fade_in=' . self::toFloat($crossfade) . ',radio)',
]);
$event->appendLines(
[
'radio = crossfade(smart=' . $crossfadeIsSmart . ', duration=' . self::toFloat(
$crossDuration
) . ',fade_out=' . self::toFloat($crossfade) . ',fade_in=' . self::toFloat($crossfade) . ',radio)',
]
);
}
}
@ -729,7 +774,8 @@ class ConfigWriter implements EventSubscriberInterface
$djonCommand = $this->getApiUrlCommand($station, 'djon', ['dj-user' => 'dj']);
$djoffCommand = $this->getApiUrlCommand($station, 'djoff', ['dj-user' => 'dj']);
$event->appendBlock(<<< EOF
$event->appendBlock(
<<< EOF
# DJ Authentication
live_enabled = ref false
last_authenticated_dj = ref ""
@ -806,20 +852,22 @@ class ConfigWriter implements EventSubscriberInterface
$harbor_params[] = 'max = ' . self::toFloat(max($djBuffer + 5, 10));
}
$event->appendLines([
'# A Pre-DJ source of radio that can be broadcast if needed',
'radio_without_live = radio',
'ignore(radio_without_live)',
'',
'# Live Broadcasting',
'live = audio_to_stereo(input.harbor(' . implode(', ', $harbor_params) . '))',
'ignore(output.dummy(live, fallible=true))',
'',
sprintf(
'radio = fallback(id="%s", replay_metadata=false, track_sensitive=false, [live, radio])',
self::getVarName($station, 'live_fallback')
),
]);
$event->appendLines(
[
'# A Pre-DJ source of radio that can be broadcast if needed',
'radio_without_live = radio',
'ignore(radio_without_live)',
'',
'# Live Broadcasting',
'live = audio_to_stereo(input.harbor(' . implode(', ', $harbor_params) . '))',
'ignore(output.dummy(live, fallible=true))',
'',
sprintf(
'radio = fallback(id="%s", replay_metadata=false, track_sensitive=false, [live, radio])',
self::getVarName($station, 'live_fallback')
),
]
);
if ($recordLiveStreams) {
$recordLiveStreamsFormat = $settings['record_streams_format'] ?? Entity\StationMountInterface::FORMAT_MP3;
@ -827,7 +875,8 @@ class ConfigWriter implements EventSubscriberInterface
$formatString = $this->getOutputFormatString($recordLiveStreamsFormat, $recordLiveStreamsBitrate);
$event->appendBlock(<<< EOF
$event->appendBlock(
<<< EOF
# Record Live Broadcasts
stop_recording_f = ref (fun () -> ())
@ -855,29 +904,35 @@ class ConfigWriter implements EventSubscriberInterface
$station = $event->getStation();
$settings = $station->getBackendConfig();
$event->appendLines([
'# Allow for Telnet-driven insertion of custom metadata.',
'radio = server.insert_metadata(id="custom_metadata", radio)',
'',
'# Apply amplification metadata (if supplied)',
'radio = amplify(override="liq_amplify", 1., radio)',
]);
$event->appendLines(
[
'# Allow for Telnet-driven insertion of custom metadata.',
'radio = server.insert_metadata(id="custom_metadata", radio)',
'',
'# Apply amplification metadata (if supplied)',
'radio = amplify(override="liq_amplify", 1., radio)',
]
);
// NRJ normalization
if ($settings->useNormalizer()) {
$event->appendLines([
'# Normalization and Compression',
'radio = normalize(target = 0., window = 0.03, gain_min = -16., gain_max = 0., radio)',
'radio = compress.exponential(radio, mu = 1.0)',
]);
$event->appendLines(
[
'# Normalization and Compression',
'radio = normalize(target = 0., window = 0.03, gain_min = -16., gain_max = 0., radio)',
'radio = compress.exponential(radio, mu = 1.0)',
]
);
}
// Replaygain metadata
if ($settings->useReplayGain()) {
$event->appendLines([
'# Replaygain Metadata',
'enable_replaygain_metadata()',
]);
$event->appendLines(
[
'# Replaygain Metadata',
'enable_replaygain_metadata()',
]
);
}
// Write fallback to safety file to ensure infallible source for the broadcast outputs.
@ -885,13 +940,15 @@ class ConfigWriter implements EventSubscriberInterface
? '/usr/local/share/icecast/web/error.mp3'
: $this->environment->getBaseDirectory() . '/resources/error.mp3';
$event->appendLines([
sprintf(
'radio = fallback(id="%s", track_sensitive = false, [radio, single(id="error_jingle", "%s")])',
self::getVarName($station, 'safe_fallback'),
$error_file
),
]);
$event->appendLines(
[
sprintf(
'radio = fallback(id="%s", track_sensitive = false, [radio, single(id="error_jingle", "%s")])',
self::getVarName($station, 'safe_fallback'),
$error_file
),
]
);
// Custom configuration
$this->writeCustomConfigurationSection($event, self::CUSTOM_PRE_BROADCAST);
@ -902,7 +959,8 @@ class ConfigWriter implements EventSubscriberInterface
['song' => 'm["song_id"]', 'media' => 'm["media_id"]', 'playlist' => 'm["playlist_id"]']
);
$event->appendBlock(<<<EOF
$event->appendBlock(
<<<EOF
# Send metadata changes back to AzuraCast
def metadata_updated(m) =
def f() =

View File

@ -3,7 +3,6 @@
namespace App\Radio\Backend;
use App\Entity;
use App\Logger;
class None extends AbstractBackend
{
@ -39,7 +38,7 @@ class None extends AbstractBackend
public function start(Entity\Station $station): void
{
Logger::getInstance()->error(
$this->logger->error(
'Cannot start process; AutoDJ is currently disabled.',
['station_id' => $station->getId(), 'station_name' => $station->getName()]
);

View File

@ -17,6 +17,7 @@ use NowPlaying\Result\Result;
use PhpIP\IP;
use PhpIP\IPBlock;
use Psr\Http\Message\UriInterface;
use Psr\Log\LoggerInterface;
use Supervisor\Supervisor;
abstract class AbstractFrontend extends AbstractAdapter
@ -36,13 +37,14 @@ abstract class AbstractFrontend extends AbstractAdapter
EntityManagerInterface $em,
Supervisor $supervisor,
EventDispatcher $dispatcher,
LoggerInterface $logger,
AdapterFactory $adapterFactory,
Client $client,
Router $router,
Entity\Repository\SettingsRepository $settingsRepo,
Entity\Repository\StationMountRepository $stationMountRepo
) {
parent::__construct($environment, $em, $supervisor, $dispatcher);
parent::__construct($environment, $em, $supervisor, $dispatcher, $logger);
$this->adapterFactory = $adapterFactory;
$this->http_client = $client;

View File

@ -4,7 +4,6 @@ namespace App\Radio\Frontend;
use App\Entity;
use App\Environment;
use App\Logger;
use App\Radio\CertificateLocator;
use App\Utilities;
use App\Xml\Reader;
@ -61,7 +60,7 @@ class Icecast extends AbstractFrontend
$defaultResult = $defaultResult->merge($otherResult);
}
} catch (Exception $e) {
Logger::getInstance()->error(sprintf('NowPlaying adapter error: %s', $e->getMessage()));
$this->logger->error(sprintf('NowPlaying adapter error: %s', $e->getMessage()));
}
return $defaultResult;

View File

@ -4,7 +4,6 @@ namespace App\Radio\Frontend;
use App\Entity;
use App\Environment;
use App\Logger;
use App\Utilities;
use Exception;
use NowPlaying\Adapter\AdapterFactory;
@ -90,7 +89,7 @@ class SHOUTcast extends AbstractFrontend
$defaultResult = $defaultResult->merge($otherResult);
}
} catch (Exception $e) {
Logger::getInstance()->error(sprintf('NowPlaying adapter error: %s', $e->getMessage()));
$this->logger->error(sprintf('NowPlaying adapter error: %s', $e->getMessage()));
}
return $defaultResult;

View File

@ -2,8 +2,6 @@
namespace App\Service;
use App\Logger;
use Exception;
use InvalidArgumentException;
use RuntimeException;
use Symfony\Component\Process\Process;
@ -21,31 +19,26 @@ class AudioWaveform
$jsonOutPath = tempnam(sys_get_temp_dir(), 'awf') . '.json';
$process = new Process([
'audiowaveform',
'-i',
$path,
'-o',
$jsonOutPath,
'--pixels-per-second',
'20',
'--bits',
'8',
]);
$process = new Process(
[
'audiowaveform',
'-i',
$path,
'-o',
$jsonOutPath,
'--pixels-per-second',
'20',
'--bits',
'8',
]
);
$process->setTimeout(60);
$process->setIdleTimeout(3600);
try {
$process->mustRun();
$process->mustRun();
if (!file_exists($jsonOutPath)) {
throw new RuntimeException('Audio waveform JSON was not generated.');
}
} catch (Exception $e) {
$logger = Logger::getInstance();
$logger->error('Audiowaveform exception: ' . $e->getMessage());
return [];
if (!file_exists($jsonOutPath)) {
throw new RuntimeException('Audio waveform JSON was not generated.');
}
$inputRaw = file_get_contents($jsonOutPath);