You've already forked Atomcms-edit
Add radio embed widget, SSE real-time, song history, moderation panel, and Auto DJ
- Embed widget: standalone iframe player with dark/light/transparent themes, copy-paste embed code admin page - Real-time SSE: streaming now-playing/listeners/dj events, replaces polling in radio-player and embed - Song history: auto-records song changes to radio_song_plays table, Filament resource to view - DJ moderation: unified panel for shouts approval, song request queue, DJ applications - Auto DJ: playlist management with round-robin playback when no DJ is live - Refactored radio-player Alpine component to use EventSource API with auto-reconnect
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\Miscellaneous\WebsiteSetting;
|
||||
use App\Models\RadioAutoDjTrack;
|
||||
use App\Services\Community\RadioScheduleService;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Symfony\Component\Console\Attribute\AsCommand;
|
||||
|
||||
#[AsCommand(name: 'radio:auto-dj')]
|
||||
final class AutoDjPlayback extends Command
|
||||
{
|
||||
#[\Override]
|
||||
protected $signature = 'radio:auto-dj {--force : Update now-playing even if track has not changed}';
|
||||
|
||||
#[\Override]
|
||||
protected $description = 'Auto DJ fallback: updates now-playing from playlist when no DJ is live';
|
||||
|
||||
public function handle(RadioScheduleService $scheduleService): int
|
||||
{
|
||||
$enabled = $this->getSetting('radio_auto_dj_detection', '0');
|
||||
|
||||
if ($enabled !== '1' && ! $this->option('force')) {
|
||||
$this->info('Auto DJ is uitgeschakeld. Gebruik --force om toch te draaien.');
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
|
||||
$currentDjId = $this->getSetting('radio_current_dj_id', '');
|
||||
$currentDj = $scheduleService->getCurrentDJ($currentDjId ?: null);
|
||||
|
||||
$track = RadioAutoDjTrack::getNextTrack();
|
||||
|
||||
if (! $track) {
|
||||
$this->info('Geen Auto DJ tracks in de playlist.');
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
|
||||
if ($currentDj !== null) {
|
||||
Cache::forget('radio_auto_dj_active');
|
||||
$this->info('DJ is live. Auto DJ niet actief.');
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
|
||||
Cache::forever('radio_auto_dj_active', [
|
||||
'title' => $track->title,
|
||||
'artist' => $track->artist,
|
||||
'is_auto_dj' => true,
|
||||
]);
|
||||
|
||||
$track->markPlayed();
|
||||
|
||||
$this->info("Auto DJ speelt: {$track->title}" . ($track->artist ? " by {$track->artist}" : ''));
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
|
||||
private function getSetting(string $key, string $default = ''): string
|
||||
{
|
||||
$setting = WebsiteSetting::where('key', $key)->first();
|
||||
|
||||
return $setting !== null && isset($setting->value) ? (string) $setting->value : $default;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\Miscellaneous\WebsiteSetting;
|
||||
use App\Models\RadioSongPlay;
|
||||
use App\Services\Community\RadioStreamService;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Symfony\Component\Console\Attribute\AsCommand;
|
||||
|
||||
#[AsCommand(name: 'radio:record-songs')]
|
||||
final class RecordSongPlays extends Command
|
||||
{
|
||||
#[\Override]
|
||||
protected $signature = 'radio:record-songs
|
||||
{--daemon : Run continuously as a daemon}
|
||||
{--interval=15 : Polling interval in seconds (daemon mode)}';
|
||||
|
||||
#[\Override]
|
||||
protected $description = 'Poll the now-playing API and record song changes to radio_song_plays';
|
||||
|
||||
public function handle(RadioStreamService $streamService): int
|
||||
{
|
||||
if (! $this->option('daemon')) {
|
||||
$this->recordOnce($streamService);
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
|
||||
$interval = max(5, (int) $this->option('interval'));
|
||||
$this->info("Starting daemon mode (interval: {$interval}s)...");
|
||||
|
||||
while (true) {
|
||||
$this->recordOnce($streamService);
|
||||
sleep($interval);
|
||||
}
|
||||
}
|
||||
|
||||
private function recordOnce(RadioStreamService $streamService): void
|
||||
{
|
||||
$enabled = Cache::remember('setting_radio_enabled', 60, function () {
|
||||
return WebsiteSetting::where('key', 'radio_enabled')->first()?->value;
|
||||
});
|
||||
|
||||
if ($enabled !== '1') {
|
||||
return;
|
||||
}
|
||||
|
||||
$apiUrl = $this->getNowPlayingApiUrl();
|
||||
|
||||
if (! $apiUrl) {
|
||||
return;
|
||||
}
|
||||
|
||||
$nowPlaying = $streamService->getNowPlaying($apiUrl);
|
||||
|
||||
if (! $nowPlaying || empty($nowPlaying['song'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
$title = $nowPlaying['song'];
|
||||
$artist = $nowPlaying['artist'] ?? null;
|
||||
|
||||
$recorded = RadioSongPlay::recordNowPlaying($title, $artist, [
|
||||
'artwork_url' => $nowPlaying['artwork'] ?? null,
|
||||
]);
|
||||
|
||||
if ($recorded) {
|
||||
$this->info("Recorded: {$title}" . ($artist ? " by {$artist}" : ''));
|
||||
}
|
||||
}
|
||||
|
||||
private function getNowPlayingApiUrl(): ?string
|
||||
{
|
||||
$enabled = Cache::remember('setting_radio_now_playing_enabled', 60, function () {
|
||||
return WebsiteSetting::where('key', 'radio_now_playing_enabled')->first()?->value;
|
||||
});
|
||||
|
||||
if ($enabled !== '1') {
|
||||
return null;
|
||||
}
|
||||
|
||||
$apiUrl = Cache::remember('setting_radio_now_playing_api_url', 60, function () {
|
||||
return WebsiteSetting::where('key', 'radio_now_playing_api_url')->first()?->value;
|
||||
});
|
||||
|
||||
if ($apiUrl) {
|
||||
return $apiUrl;
|
||||
}
|
||||
|
||||
$azureCastUrl = Cache::remember('setting_radio_azurecast_base_url', 60, function () {
|
||||
return WebsiteSetting::where('key', 'radio_azurecast_base_url')->first()?->value;
|
||||
});
|
||||
|
||||
if ($azureCastUrl) {
|
||||
$stationId = Cache::remember('setting_radio_azurecast_station_id', 60, function () {
|
||||
return WebsiteSetting::where('key', 'radio_azurecast_station_id')->first()?->value ?? '1';
|
||||
});
|
||||
|
||||
return rtrim($azureCastUrl, '/') . '/api/nowplaying/' . $stationId;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user