![]() 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/api/ |
<?php
/**
* Get Audio Analysis Status
* Returns count of tracks needing analysis
*/
require_once '../config/database.php';
header('Content-Type: application/json');
try {
$pdo = getDBConnection();
// Count tracks needing analysis (using single source of truth: bpm + analysis_source)
$stmt = $pdo->prepare("
SELECT
COUNT(*) as total,
COUNT(CASE WHEN JSON_EXTRACT(metadata, '$.bpm') IS NOT NULL
AND JSON_EXTRACT(metadata, '$.analysis_source') IS NOT NULL
THEN 1 END) as total_analyzed
FROM music_tracks
WHERE status = 'complete'
AND audio_url IS NOT NULL
AND audio_url != ''
");
$stmt->execute();
$stats = $stmt->fetch(PDO::FETCH_ASSOC);
$totalNeedingAnalysis = (int)$stats['total'] - (int)$stats['total_analyzed'];
// Get user's tracks needing analysis (if user_id provided)
$user_id = $_GET['user_id'] ?? null;
$whereClause = "mt.status = 'complete'
AND mt.audio_url IS NOT NULL
AND mt.audio_url != ''
AND (
JSON_EXTRACT(mt.metadata, '$.bpm') IS NULL
OR JSON_EXTRACT(mt.metadata, '$.bpm') = ''
OR JSON_EXTRACT(mt.metadata, '$.analysis_source') IS NULL
OR JSON_EXTRACT(mt.metadata, '$.analysis_source') = ''
)";
if ($user_id) {
$whereClause .= " AND mt.user_id = " . intval($user_id);
}
$stmt = $pdo->prepare("
SELECT
mt.id,
mt.title,
mt.audio_url,
u.name as artist_name,
mt.user_id
FROM music_tracks mt
JOIN users u ON mt.user_id = u.id
WHERE $whereClause
ORDER BY mt.created_at DESC
LIMIT 50
");
$stmt->execute();
$sample = $stmt->fetchAll(PDO::FETCH_ASSOC);
echo json_encode([
'success' => true,
'stats' => [
'needing_analysis' => $totalNeedingAnalysis,
'already_analyzed' => (int)$stats['total_analyzed'],
'total' => (int)$stats['total']
],
'tracks' => $sample
]);
} catch (Exception $e) {
echo json_encode([
'success' => false,
'error' => $e->getMessage()
]);
}