![]() 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/domains/soundstudiopro.com/private_html/utils/ |
<?php
require_once 'config/database.php';
$pdo = getDBConnection();
echo "<h2>Checking Failed Tracks</h2>";
// Get all failed tracks
$stmt = $pdo->query("
SELECT id, user_id, task_id, title, status, audio_url, created_at, metadata
FROM music_tracks
WHERE status = 'failed'
ORDER BY created_at DESC
");
$failed_tracks = $stmt->fetchAll();
echo "<h3>Failed Tracks (" . count($failed_tracks) . " found)</h3>";
if (empty($failed_tracks)) {
echo "<p style='color: green;'>✅ No failed tracks found!</p>";
} else {
echo "<table border='1' style='border-collapse: collapse; width: 100%;'>";
echo "<tr><th>ID</th><th>User</th><th>Task ID</th><th>Title</th><th>Status</th><th>Created</th><th>Action</th></tr>";
foreach ($failed_tracks as $track) {
echo "<tr>";
echo "<td>" . $track['id'] . "</td>";
echo "<td>" . $track['user_id'] . "</td>";
echo "<td>" . substr($track['task_id'], 0, 20) . "...</td>";
echo "<td>" . htmlspecialchars($track['title']) . "</td>";
echo "<td style='color: red;'>" . $track['status'] . "</td>";
echo "<td>" . $track['created_at'] . "</td>";
echo "<td><a href='?fix_track=" . $track['id'] . "'>Fix Track</a></td>";
echo "</tr>";
}
echo "</table>";
}
// Check if we need to fix a specific track
if (isset($_GET['fix_track'])) {
$track_id = $_GET['fix_track'];
echo "<h3>Fixing Track ID: $track_id</h3>";
// Get the track details
$stmt = $pdo->prepare("SELECT * FROM music_tracks WHERE id = ?");
$stmt->execute([$track_id]);
$track = $stmt->fetch();
if ($track) {
echo "<p>Track found: " . htmlspecialchars($track['title']) . "</p>";
echo "<p>Current status: " . $track['status'] . "</p>";
echo "<p>Task ID: " . $track['task_id'] . "</p>";
// Check if this task exists in API.Box
$api_key = '63edba40620216c5aa2c04240ac41dbd';
$task_id = $track['task_id'];
// Try to check task status
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.api.box/api/v1/status/$task_id");
curl_setopt($ch, CURLOPT_HTTPGET, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: Bearer ' . $api_key,
'Content-Type: application/json'
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
echo "<p>API.Box Status Check: HTTP $http_code</p>";
echo "<p>Response: " . htmlspecialchars($response) . "</p>";
// Check if there's a result file
$result_file = "task_results/{$task_id}.json";
if (file_exists($result_file)) {
echo "<p style='color: green;'>✅ Found result file!</p>";
$result_data = json_decode(file_get_contents($result_file), true);
if ($result_data && isset($result_data['data']['callbackType']) && $result_data['data']['callbackType'] === 'complete') {
echo "<p style='color: green;'>✅ Task was actually completed!</p>";
// Get the first audio URL
$audio_data = $result_data['data']['data'][0] ?? null;
if ($audio_data && isset($audio_data['audio_url'])) {
$audio_url = $audio_data['audio_url'];
// Update the track to complete
$stmt = $pdo->prepare("
UPDATE music_tracks
SET status = 'complete', audio_url = ?, metadata = ?
WHERE id = ?
");
$stmt->execute([$audio_url, json_encode($result_data), $track_id]);
echo "<p style='color: green;'>✅ Track updated to complete!</p>";
echo "<p>Audio URL: $audio_url</p>";
}
}
} else {
echo "<p style='color: orange;'>⚠️ No result file found</p>";
// Try to regenerate the track
echo "<p><a href='?regenerate_track=" . $track_id . "'>Regenerate Track</a></p>";
}
} else {
echo "<p style='color: red;'>❌ Track not found</p>";
}
}
// Handle track regeneration
if (isset($_GET['regenerate_track'])) {
$track_id = $_GET['regenerate_track'];
echo "<h3>Regenerating Track ID: $track_id</h3>";
// Get the track details
$stmt = $pdo->prepare("SELECT * FROM music_tracks WHERE id = ?");
$stmt->execute([$track_id]);
$track = $stmt->fetch();
if ($track) {
// Create a new task with the same parameters
$api_url = 'https://api.api.box/api/v1/generate';
$api_key = '63edba40620216c5aa2c04240ac41dbd';
$api_data = [
'prompt' => $track['prompt'],
'model' => 'V3_5',
'style' => 'Pop',
'title' => $track['title'],
'customMode' => false,
'instrumental' => false,
'duration' => 30,
'callBackUrl' => 'https://soundstudiopro.com/callback.php'
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $api_url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($api_data));
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: Bearer ' . $api_key,
'Content-Type: application/json'
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
$api_result = json_decode($response, true);
if ($http_code === 200 && isset($api_result['code']) && $api_result['code'] === 200) {
$new_task_id = $api_result['data']['taskId'];
// Update the track with new task ID
$stmt = $pdo->prepare("UPDATE music_tracks SET task_id = ?, status = 'processing' WHERE id = ?");
$stmt->execute([$new_task_id, $track_id]);
echo "<p style='color: green;'>✅ Track regenerated!</p>";
echo "<p>New Task ID: $new_task_id</p>";
} else {
echo "<p style='color: red;'>❌ Failed to regenerate track</p>";
echo "<p>Response: " . htmlspecialchars($response) . "</p>";
}
}
}
echo "<h3>Quick Actions</h3>";
echo "<p><a href='?check_all=1'>Check All Tracks</a></p>";
echo "<p><a href='?fix_all_failed=1'>Fix All Failed Tracks</a></p>";
?>