Fixes #5553 -- Fix bugs with live streamer and NowPlaying API responses.

This commit is contained in:
Buster "Silver Eagle" Neece 2022-06-30 15:23:20 -05:00
parent 3716eef54a
commit 1e8b45803a
No known key found for this signature in database
GPG Key ID: F1D2E64A0005E80E
5 changed files with 26 additions and 12 deletions

View File

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

View File

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

View File

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

View File

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

View File

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