![]() 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/public_html/ |
<?php
// Quick fix for Adagio for Strings
require_once 'config/database.php';
$pdo = getDBConnection();
if (!$pdo) {
die("ā Database connection failed\n");
}
// Get the track
$stmt = $pdo->prepare("SELECT id, task_id, title, audio_url FROM music_tracks WHERE task_id = '9bf0fc77de4c62243425086e8ff1763e'");
$stmt->execute();
$track = $stmt->fetch(PDO::FETCH_ASSOC);
if (!$track) {
die("ā Track not found!\n");
}
echo "š Found track: {$track['title']}\n";
echo "š Current URL: {$track['audio_url']}\n\n";
$audioUrl = $track['audio_url'];
$taskId = $track['task_id'];
// Use the download function from callback.php
function downloadAndStoreAudio($audioUrl, $taskId, $type = 'main', $variationIndex = null) {
if (empty($audioUrl) || !filter_var($audioUrl, FILTER_VALIDATE_URL)) {
return null;
}
$audioDir = 'audio_files/';
if (!is_dir($audioDir)) {
mkdir($audioDir, 0755, true);
}
$extension = pathinfo(parse_url($audioUrl, PHP_URL_PATH), PATHINFO_EXTENSION) ?: 'mp3';
if ($type === 'variation' && $variationIndex !== null) {
$filename = "{$taskId}_variation_{$variationIndex}.{$extension}";
} else {
$filename = "{$taskId}.{$extension}";
}
$localPath = $audioDir . $filename;
$webPath = '/audio_files/' . $filename;
if (file_exists($localPath)) {
echo "ā
File already exists: $webPath\n";
return $webPath;
}
// Use cURL for better reliability
if (function_exists('curl_init')) {
$ch = curl_init($audioUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 300); // 5 minutes
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60);
curl_setopt($ch, CURLOPT_BUFFERSIZE, 16384); // 16KB buffer
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
echo "š„ Downloading from: $audioUrl\n";
$audioContent = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$error = curl_error($ch);
curl_close($ch);
if ($audioContent === false || $httpCode !== 200 || !empty($error)) {
echo "ā Download failed: HTTP $httpCode, Error: $error\n";
return null;
}
} else {
$context = stream_context_create([
'http' => [
'timeout' => 120,
'user_agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36'
]
]);
echo "š„ Downloading from: $audioUrl\n";
$audioContent = @file_get_contents($audioUrl, false, $context);
if ($audioContent === false) {
echo "ā Download failed\n";
return null;
}
}
if (empty($audioContent)) {
echo "ā Downloaded content is empty\n";
return null;
}
echo "ā
Downloaded " . number_format(strlen($audioContent)) . " bytes\n";
if (file_put_contents($localPath, $audioContent, LOCK_EX)) {
chmod($localPath, 0644);
echo "ā
Saved to: $localPath\n";
return $webPath;
}
return null;
}
// Download the file
$localUrl = downloadAndStoreAudio($audioUrl, $taskId, 'main');
if ($localUrl) {
// Update database
$updateStmt = $pdo->prepare("UPDATE music_tracks SET audio_url = ? WHERE id = ?");
if ($updateStmt->execute([$localUrl, $track['id']])) {
echo "\nā
SUCCESS! Database updated with local URL: $localUrl\n";
echo "šµ Adagio for Strings should now play correctly!\n";
} else {
echo "\nā Failed to update database\n";
}
} else {
echo "\nā Failed to download audio file\n";
}
?>