![]() 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/-69bd013c/ |
<?php
session_start();
header('Content-Type: application/json');
require_once '../config/database.php';
try {
$pdo = getDBConnection();
$artist_id = $_GET['artist_id'] ?? null;
$type = $_GET['type'] ?? 'all';
if (!$artist_id) {
throw new Exception('Artist ID is required');
}
// Build query based on type
$where_clause = "WHERE mt.user_id = ?";
if ($type === 'completed') {
$where_clause .= " AND mt.status = 'complete'";
} elseif ($type === 'tracks') {
// All tracks (including processing, failed, etc.)
}
$stmt = $pdo->prepare("
SELECT
mt.id,
mt.title,
mt.prompt,
mt.duration,
mt.audio_url,
mt.status,
mt.created_at,
mt.music_type,
mt.metadata
FROM music_tracks mt
$where_clause
ORDER BY mt.created_at DESC
");
$stmt->execute([$artist_id]);
$tracks = $stmt->fetchAll(PDO::FETCH_ASSOC);
// Process tracks for display
$processed_tracks = [];
foreach ($tracks as $track) {
// Only include tracks with audio URLs
if ($track['audio_url']) {
// Parse metadata for additional info
$metadata = json_decode($track['metadata'] ?: '{}', true);
$processed_tracks[] = [
'id' => $track['id'],
'title' => $track['title'] ?: 'Untitled Track',
'duration' => $track['duration'] ?: 0,
'audio_url' => $track['audio_url'],
'status' => $track['status'],
'created_at' => $track['created_at'],
'music_type' => $track['music_type'] ?: 'music',
'genre' => $metadata['genre'] ?? 'Unknown',
'description' => $track['prompt'] ?: ''
];
}
}
echo json_encode([
'success' => true,
'tracks' => $processed_tracks,
'count' => count($processed_tracks)
]);
} catch (Exception $e) {
http_response_code(500);
echo json_encode([
'success' => false,
'error' => $e->getMessage()
]);
}
?>