![]() 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
// Comprehensive fix for variation audio URLs - handles both MD5 and base64 formats
session_start();
echo "<h2>Comprehensive Fix for Variation Audio URLs</h2>";
require_once 'config/database.php';
$pdo = getDBConnection();
if (!$pdo) {
echo "Database connection failed";
exit;
}
// Get all variations that still have 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>";
$main_url = $variation['main_track_url'];
$local_path = null;
// Try to extract hash from different URL formats
if (preg_match('/\/([a-f0-9]{32})\.mp3$/', $main_url, $matches)) {
// MD5 hash format
$hash = $matches[1];
$local_path = "/audio_files/{$hash}_variation_{$variation['variation_index']}.mp3";
echo "<p>🔍 Found MD5 hash: {$hash}</p>";
} elseif (preg_match('/\/([A-Za-z0-9+\/]{20,})\.mp3$/', $main_url, $matches)) {
// Base64 encoded format
$base64_filename = $matches[1];
echo "<p>🔍 Found base64 filename: {$base64_filename}</p>";
// Try to find matching local files by looking for variations with this track ID
$local_files = glob(__DIR__ . "/audio_files/*_variation_{$variation['variation_index']}.mp3");
if (!empty($local_files)) {
// Find the file that belongs to this track by checking the track's main audio file
$track_stmt = $pdo->prepare("SELECT audio_url FROM music_tracks WHERE id = ?");
$track_stmt->execute([$variation['track_id']]);
$track = $track_stmt->fetch();
if ($track && $track['audio_url']) {
// Extract the hash from the track's main audio URL
if (preg_match('/\/([a-f0-9]{32})\.mp3$/', $track['audio_url'], $track_matches)) {
$track_hash = $track_matches[1];
$local_path = "/audio_files/{$track_hash}_variation_{$variation['variation_index']}.mp3";
echo "<p>🔍 Found track hash: {$track_hash}</p>";
}
}
}
if (!$local_path) {
echo "<p>⚠️ Could not determine local path for base64 format</p>";
}
}
if ($local_path) {
// 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>";
// Try to find any variation file for this track
$any_variation_files = glob(__DIR__ . "/audio_files/*_variation_{$variation['variation_index']}.mp3");
if (!empty($any_variation_files)) {
echo "<p>🔍 Found variation files: " . implode(', ', array_map('basename', $any_variation_files)) . "</p>";
}
$errors++;
}
} else {
echo "<p>❌ Could not determine local path for 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>";
}
// Show remaining variations that still need fixing
if ($errors > 0) {
echo "<h3>Remaining Variations to Fix:</h3>";
$remaining_stmt = $pdo->query("
SELECT
av.id,
av.track_id,
av.variation_index,
av.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
LIMIT 10
");
$remaining = $remaining_stmt->fetchAll();
foreach ($remaining as $var) {
echo "<p>Track {$var['track_id']}, Variation {$var['variation_index']}: {$var['audio_url']}</p>";
}
if (count($remaining) >= 10) {
echo "<p>... and " . ($errors - 10) . " more</p>";
}
}
?>