Return fallback file instead of error message for LS to avoid constant pinging of the AutoDJ.

This commit is contained in:
Buster "Silver Eagle" Neece 2022-04-06 01:41:22 -05:00
parent 1956a60e84
commit 1e10aaac6d
No known key found for this signature in database
GPG Key ID: 9FC8B9E008872109
7 changed files with 60 additions and 23 deletions

View File

@ -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(

View File

@ -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);

View File

@ -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);

View File

@ -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);
}
}

View File

@ -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

View File

@ -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';
}
}

View File

@ -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.');