![]() 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/3180573f/ |
<?php
// Fix variation audio URLs to use local server paths
session_start();
echo "<h2>Fixing Variation Audio URLs</h2>";
require_once 'config/database.php';
$pdo = getDBConnection();
if (!$pdo) {
echo "Database connection failed";
exit;
}
// Get all variations with external URLs
$stmt = $pdo->query("
SELECT
av.id,
av.track_id,
av.variation_index,
av.audio_url,
av.source_audio_url,
mt.audio_url as main_track_url
FROM audio_variations av
JOIN music_tracks mt ON av.track_id = mt.id
WHERE av.audio_url LIKE '%cdn1.suno.ai%'
OR av.audio_url LIKE '%apiboxfiles.erweima.ai%'
OR av.audio_url LIKE '%mfile.erweima.ai%'
ORDER BY av.track_id, av.variation_index
");
$variations = $stmt->fetchAll();
if (empty($variations)) {
echo "<p>No variations with external URLs found.</p>";
exit;
}
echo "<p>Found " . count($variations) . " variations with external URLs that need fixing.</p>";
$updated = 0;
$errors = 0;
foreach ($variations as $variation) {
echo "<h3>Variation ID: {$variation['id']} (Track: {$variation['track_id']}, Index: {$variation['variation_index']})</h3>";
// Extract the hash from the main track URL
$main_url = $variation['main_track_url'];
if (preg_match('/\/([a-f0-9]{32})\.mp3$/', $main_url, $matches)) {
$hash = $matches[1];
// Construct the local variation path
$local_path = "/audio_files/{$hash}_variation_{$variation['variation_index']}.mp3";
// Check if the local file exists
$local_file_path = __DIR__ . $local_path;
if (file_exists($local_file_path)) {
echo "<p>✅ Local file exists: {$local_path}</p>";
// Update the database
try {
$update_stmt = $pdo->prepare("
UPDATE audio_variations
SET audio_url = ?, source_audio_url = ?
WHERE id = ?
");
$result = $update_stmt->execute([$local_path, $local_path, $variation['id']]);
if ($result) {
echo "<p>✅ Updated variation {$variation['id']} to use local path: {$local_path}</p>";
$updated++;
} else {
echo "<p>❌ Failed to update variation {$variation['id']}</p>";
$errors++;
}
} catch (Exception $e) {
echo "<p>❌ Error updating variation {$variation['id']}: " . htmlspecialchars($e->getMessage()) . "</p>";
$errors++;
}
} else {
echo "<p>❌ Local file not found: {$local_file_path}</p>";
$errors++;
}
} else {
echo "<p>❌ Could not extract hash from main track URL: {$main_url}</p>";
$errors++;
}
echo "<hr>";
}
echo "<h2>Summary</h2>";
echo "<p>✅ Successfully updated: {$updated} variations</p>";
echo "<p>❌ Errors: {$errors} variations</p>";
if ($updated > 0) {
echo "<p><strong>Variation audio URLs have been fixed! They should now play from your local server.</strong></p>";
}
?>