Add streamer avatar to NP API.
This commit is contained in:
parent
0bd53a65a3
commit
18fe4060e7
4 changed files with 47 additions and 40 deletions
|
@ -4,13 +4,16 @@ declare(strict_types=1);
|
|||
|
||||
namespace App\Entity\Api\NowPlaying;
|
||||
|
||||
use App\Entity\Api\ResolvableUrlInterface;
|
||||
use App\Http\Router;
|
||||
use OpenApi\Attributes as OA;
|
||||
use Psr\Http\Message\UriInterface;
|
||||
|
||||
#[OA\Schema(
|
||||
schema: 'Api_NowPlaying_Live',
|
||||
type: 'object'
|
||||
)]
|
||||
class Live
|
||||
class Live implements ResolvableUrlInterface
|
||||
{
|
||||
#[OA\Property(
|
||||
description: 'Whether the stream is known to currently have a live DJ.',
|
||||
|
@ -21,8 +24,7 @@ class Live
|
|||
#[OA\Property(
|
||||
description: 'The current active streamer/DJ, if one is available.',
|
||||
example: 'DJ Jazzy Jeff'
|
||||
)
|
||||
]
|
||||
)]
|
||||
public string $streamer_name = '';
|
||||
|
||||
#[OA\Property(
|
||||
|
@ -31,13 +33,17 @@ class Live
|
|||
)]
|
||||
public ?int $broadcast_start = null;
|
||||
|
||||
public function __construct(
|
||||
bool $is_live = false,
|
||||
string $streamer_name = '',
|
||||
?int $broadcast_start = null
|
||||
) {
|
||||
$this->is_live = $is_live;
|
||||
$this->streamer_name = $streamer_name;
|
||||
$this->broadcast_start = $broadcast_start;
|
||||
/** @var string|UriInterface|null */
|
||||
#[OA\Property(
|
||||
description: 'URL to the streamer artwork (if available).',
|
||||
example: 'https://picsum.photos/1200/1200'
|
||||
)]
|
||||
public $art = null;
|
||||
|
||||
public function resolveUrls(UriInterface $base): void
|
||||
{
|
||||
$this->art = (null !== $this->art)
|
||||
? (string)Router::resolveUri($base, $this->art, true)
|
||||
: null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -69,6 +69,8 @@ class NowPlaying implements ResolvableUrlInterface
|
|||
{
|
||||
$this->station->resolveUrls($base);
|
||||
|
||||
$this->live->resolveUrls($base);
|
||||
|
||||
if ($this->now_playing instanceof ResolvableUrlInterface) {
|
||||
$this->now_playing->resolveUrls($base);
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ declare(strict_types=1);
|
|||
namespace App\Entity\ApiGenerator;
|
||||
|
||||
use App\Entity;
|
||||
use App\Http\Router;
|
||||
use GuzzleHttp\Psr7\Uri;
|
||||
use NowPlaying\Result\CurrentSong;
|
||||
use NowPlaying\Result\Result;
|
||||
|
@ -21,7 +22,8 @@ class NowPlayingApiGenerator
|
|||
protected Entity\Repository\SongHistoryRepository $historyRepo,
|
||||
protected Entity\Repository\StationQueueRepository $queueRepo,
|
||||
protected Entity\Repository\StationStreamerBroadcastRepository $broadcastRepo,
|
||||
protected EventDispatcherInterface $eventDispatcher
|
||||
protected EventDispatcherInterface $eventDispatcher,
|
||||
protected Router $router,
|
||||
) {
|
||||
}
|
||||
|
||||
|
@ -89,17 +91,29 @@ class NowPlayingApiGenerator
|
|||
}
|
||||
|
||||
// Detect and report live DJ status
|
||||
if ($station->getIsStreamerLive()) {
|
||||
$current_streamer = $station->getCurrentStreamer();
|
||||
$streamer_name = ($current_streamer instanceof Entity\StationStreamer)
|
||||
? $current_streamer->getDisplayName()
|
||||
: 'Live DJ';
|
||||
$currentStreamer = $station->getCurrentStreamer();
|
||||
|
||||
if (null !== $currentStreamer) {
|
||||
$broadcastStart = $this->broadcastRepo->getLatestBroadcast($station)?->getTimestampStart();
|
||||
|
||||
$np->live = new Entity\Api\NowPlaying\Live(true, $streamer_name, $broadcastStart);
|
||||
$live = new Entity\Api\NowPlaying\Live();
|
||||
$live->is_live = true;
|
||||
$live->streamer_name = $currentStreamer->getDisplayName();
|
||||
$live->broadcast_start = $broadcastStart;
|
||||
|
||||
if (0 !== $currentStreamer->getArtUpdatedAt()) {
|
||||
$live->art = $this->router->named(
|
||||
route_name: 'api:stations:streamer:art',
|
||||
route_params: [
|
||||
'station_id' => $station->getIdRequired(),
|
||||
'streamer_id' => $currentStreamer->getIdRequired() . '|' . $currentStreamer->getArtUpdatedAt(),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
$np->live = $live;
|
||||
} else {
|
||||
$np->live = new Entity\Api\NowPlaying\Live(false);
|
||||
$np->live = new Entity\Api\NowPlaying\Live();
|
||||
}
|
||||
|
||||
$apiSongHistory = ($this->songHistoryApiGenerator)(
|
||||
|
@ -169,7 +183,7 @@ class NowPlayingApiGenerator
|
|||
);
|
||||
}
|
||||
|
||||
$np->live = new Entity\Api\NowPlaying\Live(false);
|
||||
$np->live = new Entity\Api\NowPlaying\Live();
|
||||
|
||||
$np->update();
|
||||
return $np;
|
||||
|
|
|
@ -14,28 +14,13 @@ use Psr\Http\Message\UriInterface;
|
|||
|
||||
class SongApiGenerator
|
||||
{
|
||||
protected EntityManagerInterface $em;
|
||||
|
||||
protected Router $router;
|
||||
|
||||
protected Entity\Repository\StationRepository $stationRepo;
|
||||
|
||||
protected Entity\Repository\CustomFieldRepository $customFieldRepo;
|
||||
|
||||
protected RemoteAlbumArt $remoteAlbumArt;
|
||||
|
||||
public function __construct(
|
||||
EntityManagerInterface $em,
|
||||
Router $router,
|
||||
Entity\Repository\StationRepository $stationRepo,
|
||||
Entity\Repository\CustomFieldRepository $customFieldRepo,
|
||||
RemoteAlbumArt $remoteAlbumArt
|
||||
protected EntityManagerInterface $em,
|
||||
protected Router $router,
|
||||
protected Entity\Repository\StationRepository $stationRepo,
|
||||
protected Entity\Repository\CustomFieldRepository $customFieldRepo,
|
||||
protected RemoteAlbumArt $remoteAlbumArt
|
||||
) {
|
||||
$this->em = $em;
|
||||
$this->router = $router;
|
||||
$this->stationRepo = $stationRepo;
|
||||
$this->customFieldRepo = $customFieldRepo;
|
||||
$this->remoteAlbumArt = $remoteAlbumArt;
|
||||
}
|
||||
|
||||
public function __invoke(
|
||||
|
|
Loading…
Reference in a new issue