From 1e8b45803a7eff1c8a7f156cbba7ec9191ca98a2 Mon Sep 17 00:00:00 2001 From: "Buster \"Silver Eagle\" Neece" Date: Thu, 30 Jun 2022 15:23:20 -0500 Subject: [PATCH] Fixes #5553 -- Fix bugs with live streamer and NowPlaying API responses. --- src/Entity/ApiGenerator/NowPlayingApiGenerator.php | 14 ++++++++------ src/Entity/ApiGenerator/SongApiGenerator.php | 2 +- src/Entity/Repository/SongHistoryRepository.php | 6 ++++++ .../Backend/Liquidsoap/Command/FeedbackCommand.php | 14 ++++++++++---- src/Radio/Backend/Liquidsoap/ConfigWriter.php | 2 +- 5 files changed, 26 insertions(+), 12 deletions(-) diff --git a/src/Entity/ApiGenerator/NowPlayingApiGenerator.php b/src/Entity/ApiGenerator/NowPlayingApiGenerator.php index 2ea34e35b..653760245 100644 --- a/src/Entity/ApiGenerator/NowPlayingApiGenerator.php +++ b/src/Entity/ApiGenerator/NowPlayingApiGenerator.php @@ -6,7 +6,7 @@ namespace App\Entity\ApiGenerator; use App\Entity; use App\Http\Router; -use App\Radio\Enums\BackendAdapters; +use App\Utilities\Logger; use Exception; use GuzzleHttp\Psr7\Uri; use NowPlaying\Result\CurrentSong; @@ -35,7 +35,9 @@ class NowPlayingApiGenerator ): Entity\Api\NowPlaying\NowPlaying { $baseUri = new Uri(''); - if (empty($npResult->currentSong->text)) { + $updateSongFromNowPlaying = !$station->getBackendTypeEnum()->isEnabled(); + + if ($updateSongFromNowPlaying && empty($npResult->currentSong->text)) { return $this->offlineApi($station, $baseUri); } @@ -49,8 +51,6 @@ class NowPlayingApiGenerator unique: $npResult->listeners->unique ); - $updateSongFromNowPlaying = (BackendAdapters::Liquidsoap !== $station->getBackendTypeEnum()); - try { $sh_obj = $this->historyRepo->updateFromNowPlaying( $station, @@ -59,7 +59,9 @@ class NowPlayingApiGenerator ? Entity\Song::createFromNowPlayingSong($npResult->currentSong) : null ); - } catch (Exception) { + } catch (Exception $e) { + Logger::getInstance()->error($e->getMessage(), ['exception' => $e]); + return $this->offlineApi($station, $baseUri); } @@ -96,7 +98,7 @@ class NowPlayingApiGenerator route_name: 'api:stations:streamer:art', route_params: [ 'station_id' => $station->getIdRequired(), - 'streamer_id' => $currentStreamer->getIdRequired() . '|' . $currentStreamer->getArtUpdatedAt(), + 'id' => $currentStreamer->getIdRequired() . '|' . $currentStreamer->getArtUpdatedAt(), ], ); } diff --git a/src/Entity/ApiGenerator/SongApiGenerator.php b/src/Entity/ApiGenerator/SongApiGenerator.php index e45c56dbe..7f0072c51 100644 --- a/src/Entity/ApiGenerator/SongApiGenerator.php +++ b/src/Entity/ApiGenerator/SongApiGenerator.php @@ -88,7 +88,7 @@ class SongApiGenerator route_name: 'api:stations:streamer:art', route_params: [ 'station_id' => $station->getIdRequired(), - 'streamer_id' => $currentStreamer->getIdRequired() . '|' . $currentStreamer->getArtUpdatedAt(), + 'id' => $currentStreamer->getIdRequired() . '|' . $currentStreamer->getArtUpdatedAt(), ], ); } diff --git a/src/Entity/Repository/SongHistoryRepository.php b/src/Entity/Repository/SongHistoryRepository.php index 628497e88..c1702549d 100644 --- a/src/Entity/Repository/SongHistoryRepository.php +++ b/src/Entity/Repository/SongHistoryRepository.php @@ -118,6 +118,12 @@ final class SongHistoryRepository extends AbstractStationBasedRepository } $newCurrentSong->setTimestampStart(time()); + + $currentStreamer = $station->getCurrentStreamer(); + if (null !== $currentStreamer) { + $newCurrentSong->setStreamer($currentStreamer); + } + $this->em->persist($newCurrentSong); $station->setCurrentSong($newCurrentSong); diff --git a/src/Radio/Backend/Liquidsoap/Command/FeedbackCommand.php b/src/Radio/Backend/Liquidsoap/Command/FeedbackCommand.php index 1bf067788..bd380f75b 100644 --- a/src/Radio/Backend/Liquidsoap/Command/FeedbackCommand.php +++ b/src/Radio/Backend/Liquidsoap/Command/FeedbackCommand.php @@ -51,12 +51,18 @@ class FeedbackCommand extends AbstractCommand array $payload ): Entity\SongHistory { if (isset($payload['artist'])) { + $newSong = Entity\Song::createFromArray([ + 'artist' => $payload['artist'] ?? '', + 'title' => $payload['title'] ?? '', + ]); + + if (!$this->historyRepo->isDifferentFromCurrentSong($station, $newSong)) { + throw new RuntimeException('Song is not different from current song.'); + } + return new Entity\SongHistory( $station, - Entity\Song::createFromArray([ - 'artist' => $payload['artist'] ?? '', - 'title' => $payload['title'] ?? '', - ]) + $newSong ); } diff --git a/src/Radio/Backend/Liquidsoap/ConfigWriter.php b/src/Radio/Backend/Liquidsoap/ConfigWriter.php index 787c67d3f..1e211154e 100644 --- a/src/Radio/Backend/Liquidsoap/ConfigWriter.php +++ b/src/Radio/Backend/Liquidsoap/ConfigWriter.php @@ -1024,7 +1024,7 @@ class ConfigWriter implements EventSubscriberInterface def metadata_updated(m) = def f() = - if (m["title"] != !last_title and m["artist"] != !last_artist) then + if (m["title"] != !last_title or m["artist"] != !last_artist) then last_title := m["title"] last_artist := m["artist"]