![]() Server : Apache/2 System : Linux server-15-235-50-60 5.15.0-164-generic #174-Ubuntu SMP Fri Nov 14 20:25:16 UTC 2025 x86_64 User : gositeme ( 1004) PHP Version : 8.2.29 Disable Function : exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname Directory : /home/gositeme/.cursor-server/data/User/History/-7159fd/ |
<?php
/**
* Log a radio play
* POST /api/radio/v1/plays
*/
$data = json_decode(file_get_contents('php://input'), true);
// Validate required fields
if (!isset($data['track_id']) || !isset($data['played_at'])) {
http_response_code(400);
echo json_encode(['error' => 'Missing required fields: track_id, played_at']);
exit;
}
$track_id = (int)$data['track_id'];
$played_at = $data['played_at'];
// Validate track exists
$pdo = getDBConnection();
$stmt = $pdo->prepare("SELECT id, radio_enabled FROM music_tracks WHERE id = ?");
$stmt->execute([$track_id]);
$track = $stmt->fetch(PDO::FETCH_ASSOC);
if (!$track) {
http_response_code(404);
echo json_encode(['error' => 'Track not found']);
exit;
}
if (!$track['radio_enabled']) {
http_response_code(403);
echo json_encode(['error' => 'Track is not available for radio play']);
exit;
}
// Log the play
$play_id = logRadioPlay($station['id'], $track_id, [
'played_at' => $played_at,
'duration_played' => $data['duration_played'] ?? null,
'play_type' => $data['play_type'] ?? 'full',
'playlist_id' => $data['playlist_id'] ?? null,
'listener_count' => $data['listener_count'] ?? null,
'source' => 'api'
]);
if ($play_id) {
// Get updated station info
$station = getRadioStation($station['id']);
echo json_encode([
'success' => true,
'play_id' => $play_id,
'logged' => true,
'monthly_plays_remaining' => $station['monthly_play_limit'] - $station['current_month_plays']
]);
} else {
http_response_code(500);
echo json_encode(['error' => 'Failed to log play']);
}