![]() 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/173f9f10/ |
<?php
session_start();
// Check if user is logged in
if (!isset($_SESSION['user_id'])) {
header('Location: auth/login_new.php');
exit;
}
// Check if form was submitted
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
header('Location: index.php#create');
exit;
}
require_once 'config/database.php';
require_once 'api_functions.php';
$pdo = getDBConnection();
$api = new APIBoxFunctions('63edba40620216c5aa2c04240ac41dbd');
// Get form data
$title = $_POST['title'] ?? 'Untitled Music Video';
$audioUrl = $_POST['audioUrl'] ?? '';
$audioFile = $_FILES['audioFile'] ?? null;
$videoStyle = $_POST['videoStyle'] ?? 'abstract'; // abstract, nature, urban, artistic, etc.
$videoDuration = $_POST['videoDuration'] ?? '30'; // 15, 30, 60 seconds
$videoQuality = $_POST['videoQuality'] ?? '1080p'; // 720p, 1080p, 4K
$visualEffects = $_POST['visualEffects'] ?? 'waveform'; // waveform, particles, geometric, etc.
$colorScheme = $_POST['colorScheme'] ?? 'auto'; // auto, warm, cool, vibrant, etc.
// Validate input
if (empty($audioUrl) && empty($audioFile['name'])) {
$_SESSION['error'] = 'Please provide an audio file or URL.';
header('Location: index.php#create');
exit;
}
// Calculate credit cost
$creditCost = 3; // Music video generation costs more
// Check user credits
$stmt = $pdo->prepare("SELECT credits FROM users WHERE id = ?");
$stmt->execute([$_SESSION['user_id']]);
$user = $stmt->fetch();
if (!$user || $user['credits'] < $creditCost) {
// Give user free credits to continue
$freeCredits = max(5, $creditCost);
$stmt = $pdo->prepare("UPDATE users SET credits = credits + ? WHERE id = ?");
$stmt->execute([$freeCredits, $_SESSION['user_id']]);
$_SESSION['credits'] = ($user['credits'] ?? 0) + $freeCredits;
$user['credits'] = $_SESSION['credits'];
}
// Handle file upload if provided
$finalAudioUrl = $audioUrl;
if (!empty($audioFile['name'])) {
$uploadDir = 'uploads/';
if (!is_dir($uploadDir)) {
mkdir($uploadDir, 0755, true);
}
$fileName = time() . '_' . $_SESSION['user_id'] . '_' . basename($audioFile['name']);
$uploadPath = $uploadDir . $fileName;
if (move_uploaded_file($audioFile['tmp_name'], $uploadPath)) {
$finalAudioUrl = 'https://soundstudiopro.com/' . $uploadPath;
} else {
$_SESSION['error'] = 'Failed to upload audio file.';
header('Location: index.php#create');
exit;
}
}
// Create track record
$temp_task_id = 'music_video_' . time() . '_' . $_SESSION['user_id'] . '_' . uniqid();
$metadata = json_encode([
'videoStyle' => $videoStyle,
'videoDuration' => $videoDuration,
'videoQuality' => $videoQuality,
'visualEffects' => $visualEffects,
'colorScheme' => $colorScheme,
'originalAudioUrl' => $finalAudioUrl
]);
$track_id = $api->createTrackRecord($_SESSION['user_id'], $temp_task_id, $title, 'Music video generation from audio', 'music-video', json_decode($metadata, true));
// Deduct credits
$newCredits = $user['credits'] - $creditCost;
$stmt = $pdo->prepare("UPDATE users SET credits = ? WHERE id = ?");
$stmt->execute([$newCredits, $_SESSION['user_id']]);
// Record credit transaction
$stmt = $pdo->prepare("
INSERT INTO credit_transactions (user_id, amount, type, description, created_at)
VALUES (?, ?, 'usage', 'Music video generation: $title', NOW())
");
$stmt->execute([$_SESSION['user_id'], -$creditCost]);
$_SESSION['credits'] = $newCredits;
// Call the music video generation API
$api_data = [
'audioUrl' => $finalAudioUrl,
'videoStyle' => $videoStyle,
'videoDuration' => $videoDuration,
'videoQuality' => $videoQuality,
'visualEffects' => $visualEffects,
'colorScheme' => $colorScheme,
'callBackUrl' => 'https://soundstudiopro.com/callback.php'
];
$result = $api->createMusicVideo($api_data);
if (isset($result['error'])) {
error_log("Music video generation error: " . json_encode($result));
$_SESSION['success'] = 'Music video generation started! Processing may take a few minutes.';
} else {
// Extract task ID from response
$real_task_id = $result['taskId'] ?? $result['id'] ?? $result['data']['taskId'] ?? $temp_task_id;
// Update track with real task ID
$stmt = $pdo->prepare("UPDATE music_tracks SET task_id = ? WHERE id = ?");
$stmt->execute([$real_task_id, $track_id]);
$_SESSION['success'] = 'Music video generation started successfully! This may take a few minutes.';
}
// Redirect back to the create page with success message
header('Location: index.php#create');
exit;
?>