54 lines
2.1 KiB
PHP
54 lines
2.1 KiB
PHP
<?php
|
|
header('Content-Type: application/json');
|
|
require_once __DIR__ . '/../db/config.php';
|
|
|
|
try {
|
|
$db = db();
|
|
|
|
// Check for a "manual override" song that was recently marked as played
|
|
// We look for a song marked as 'played' in the last 4 minutes (typical song duration)
|
|
$stmt = $db->query("SELECT artist, song, requester, youtube_url FROM song_requests WHERE status = 'played' AND created_at > DATE_SUB(NOW(), INTERVAL 4 MINUTE) ORDER BY created_at DESC LIMIT 1");
|
|
$override = $stmt->fetch();
|
|
|
|
if ($override) {
|
|
echo json_encode([
|
|
'success' => true,
|
|
'source' => 'local_request',
|
|
'artist' => $override['artist'],
|
|
'title' => $override['song'],
|
|
'requester' => $override['requester'],
|
|
'youtube_url' => $override['youtube_url'],
|
|
'cover' => './assets/pasted-20260215-163754-def41f49.png'
|
|
]);
|
|
exit;
|
|
}
|
|
|
|
// Fallback: Proxy RadioKing metadata
|
|
$radioKingUrl = 'https://www.radioking.com/widgets/api/v1/radio/828046/track/current';
|
|
$ch = curl_init();
|
|
curl_setopt($ch, CURLOPT_URL, $radioKingUrl);
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
|
|
$resp = curl_exec($ch);
|
|
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
|
curl_close($ch);
|
|
|
|
if ($httpCode === 200 && $resp) {
|
|
$data = json_decode($resp, true);
|
|
echo json_encode([
|
|
'success' => true,
|
|
'source' => 'radioking',
|
|
'artist' => $data['artist'] ?? 'Lili Records',
|
|
'title' => $data['title'] ?? 'La mejor música',
|
|
'cover' => $data['cover'] ?? './assets/pasted-20260215-163754-def41f49.png',
|
|
'duration' => $data['duration'] ?? 0,
|
|
'end_at' => $data['end_at'] ?? null,
|
|
'next_track' => $data['next_track'] ?? null
|
|
]);
|
|
} else {
|
|
echo json_encode(['success' => false, 'error' => 'Failed to fetch RadioKing metadata']);
|
|
}
|
|
} catch (Exception $e) {
|
|
echo json_encode(['success' => false, 'error' => $e->getMessage()]);
|
|
}
|