Return fallback file instead of error message for LS to avoid constant pinging of the AutoDJ.
This commit is contained in:
parent
1956a60e84
commit
1e10aaac6d
|
@ -154,11 +154,12 @@ class DebugController extends AbstractLogViewerController
|
|||
$this->logger->pushHandler($this->testHandler);
|
||||
|
||||
$nextSongAnnotated = $annotations->annotateNextSong(
|
||||
$request->getStation(),
|
||||
false
|
||||
$request->getStation()
|
||||
);
|
||||
|
||||
$this->logger->info('Annotated next song: ' . $nextSongAnnotated);
|
||||
$this->logger->info('Annotated next song', [
|
||||
'annotation' => $nextSongAnnotated,
|
||||
]);
|
||||
$this->logger->popHandler();
|
||||
|
||||
return $request->getView()->renderToResponse(
|
||||
|
|
|
@ -73,10 +73,10 @@ class AnnotateNextSong extends Event
|
|||
/**
|
||||
* Compile the resulting annotations into one string for Liquidsoap to consume.
|
||||
*/
|
||||
public function buildAnnotations(): string
|
||||
public function buildAnnotations(): ?string
|
||||
{
|
||||
if (empty($this->songPath)) {
|
||||
return '';
|
||||
return null;
|
||||
}
|
||||
|
||||
$this->annotations = array_filter($this->annotations);
|
||||
|
|
|
@ -27,7 +27,7 @@ class Annotations implements EventSubscriberInterface
|
|||
}
|
||||
|
||||
/**
|
||||
* @return mixed[]
|
||||
* @inheritDoc
|
||||
*/
|
||||
public static function getSubscribedEvents(): array
|
||||
{
|
||||
|
@ -50,7 +50,7 @@ class Annotations implements EventSubscriberInterface
|
|||
public function annotateNextSong(
|
||||
Entity\Station $station,
|
||||
bool $asAutoDj = false,
|
||||
): string {
|
||||
): ?string {
|
||||
$queueRow = $this->queueRepo->getNextToSendToAutoDj($station);
|
||||
|
||||
// Try to rebuild the queue if it's empty.
|
||||
|
@ -64,7 +64,8 @@ class Annotations implements EventSubscriberInterface
|
|||
],
|
||||
]
|
||||
);
|
||||
return '';
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
$event = new AnnotateNextSong($queueRow, $asAutoDj);
|
||||
|
|
|
@ -6,13 +6,15 @@ namespace App\Radio\Backend\Liquidsoap\Command;
|
|||
|
||||
use App\Entity;
|
||||
use App\Radio\AutoDJ\Annotations;
|
||||
use App\Radio\FallbackFile;
|
||||
use Monolog\Logger;
|
||||
|
||||
class NextSongCommand extends AbstractCommand
|
||||
{
|
||||
public function __construct(
|
||||
Logger $logger,
|
||||
protected Annotations $annotations
|
||||
protected Annotations $annotations,
|
||||
protected FallbackFile $fallbackFile
|
||||
) {
|
||||
parent::__construct($logger);
|
||||
}
|
||||
|
@ -25,6 +27,6 @@ class NextSongCommand extends AbstractCommand
|
|||
return $this->annotations->annotateNextSong(
|
||||
$station,
|
||||
$asAutoDj
|
||||
);
|
||||
) ?? $this->fallbackFile->getFallbackPathForStation($station);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ use App\Radio\Backend\Liquidsoap;
|
|||
use App\Radio\Enums\FrontendAdapters;
|
||||
use App\Radio\Enums\StreamFormats;
|
||||
use App\Radio\Enums\StreamProtocols;
|
||||
use App\Radio\FallbackFile;
|
||||
use Carbon\CarbonImmutable;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use League\Flysystem\StorageAttributes;
|
||||
|
@ -34,7 +35,8 @@ class ConfigWriter implements EventSubscriberInterface
|
|||
protected Entity\Repository\SettingsRepository $settingsRepo,
|
||||
protected Liquidsoap $liquidsoap,
|
||||
protected Environment $environment,
|
||||
protected LoggerInterface $logger
|
||||
protected LoggerInterface $logger,
|
||||
protected FallbackFile $fallbackFile
|
||||
) {
|
||||
}
|
||||
|
||||
|
@ -998,18 +1000,7 @@ class ConfigWriter implements EventSubscriberInterface
|
|||
}
|
||||
|
||||
// Write fallback to safety file to ensure infallible source for the broadcast outputs.
|
||||
$errorFile = $this->environment->isDocker()
|
||||
? '/usr/local/share/icecast/web/error.mp3'
|
||||
: $this->environment->getBaseDirectory() . '/resources/error.mp3';
|
||||
|
||||
// Check for a custom station fallback file.
|
||||
$stationFallback = $station->getFallbackPath();
|
||||
if (!empty($stationFallback)) {
|
||||
$fsConfig = (new StationFilesystems($station))->getConfigFilesystem();
|
||||
if ($fsConfig->fileExists($stationFallback)) {
|
||||
$errorFile = $fsConfig->getLocalPath($stationFallback);
|
||||
}
|
||||
}
|
||||
$errorFile = $this->fallbackFile->getFallbackPathForStation($station);
|
||||
|
||||
$event->appendBlock(
|
||||
<<<EOF
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Radio;
|
||||
|
||||
use App\Entity;
|
||||
use App\Environment;
|
||||
use App\Flysystem\StationFilesystems;
|
||||
|
||||
class FallbackFile
|
||||
{
|
||||
public function __construct(
|
||||
protected Environment $environment
|
||||
) {
|
||||
}
|
||||
|
||||
public function getFallbackPathForStation(Entity\Station $station): string
|
||||
{
|
||||
$stationFallback = $station->getFallbackPath();
|
||||
if (!empty($stationFallback)) {
|
||||
$fsConfig = (new StationFilesystems($station))->getConfigFilesystem();
|
||||
if ($fsConfig->fileExists($stationFallback)) {
|
||||
return $fsConfig->getLocalPath($stationFallback);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->getDefaultFallbackPath();
|
||||
}
|
||||
|
||||
public function getDefaultFallbackPath(): string
|
||||
{
|
||||
return $this->environment->isDocker()
|
||||
? '/usr/local/share/icecast/web/error.mp3'
|
||||
: $this->environment->getBaseDirectory() . '/resources/error.mp3';
|
||||
}
|
||||
}
|
|
@ -83,6 +83,11 @@ class CheckRequestsTask extends AbstractTask
|
|||
|
||||
$track = $event->buildAnnotations();
|
||||
|
||||
if (null === $track) {
|
||||
$this->logger->error('Error building annotation.');
|
||||
return false;
|
||||
}
|
||||
|
||||
// Queue request with Liquidsoap.
|
||||
if (!$backend->isQueueEmpty($station)) {
|
||||
$this->logger->error('Skipping submitting request to Liquidsoap; current queue is occupied.');
|
||||
|
|
Loading…
Reference in New Issue