-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocess.php
More file actions
138 lines (113 loc) · 4.3 KB
/
process.php
File metadata and controls
138 lines (113 loc) · 4.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<?php
ini_set('max_execution_time', 0); // No time limit
ignore_user_abort(true);
function isWindows() {
return strtoupper(substr(PHP_OS, 0, 3)) === 'WIN';
}
function startBackgroundProcess($filename = null) {
$logFile = 'process.log';
// Reset log file
if ($filename) {
file_put_contents($logFile, "🚀 Memulai proses untuk file: $filename - " . date('Y-m-d H:i:s') . "\n");
// SIMPAN FILENAME KE FILE dengan format yang jelas
file_put_contents('current_filename.txt', $filename);
file_put_contents($logFile, "✅ Filename disimpan: $filename\n", FILE_APPEND);
} else {
file_put_contents($logFile, "🚀 Memulai proses background... " . date('Y-m-d H:i:s') . "\n");
}
if (isWindows()) {
// Windows background process
$cmd = 'start /B php-cgi -f background_processor.php > nul 2>&1';
pclose(popen($cmd, 'r'));
} else {
// Linux background process
$cmd = 'php background_processor.php > /dev/null 2>&1 &';
shell_exec($cmd);
}
file_put_contents($logFile, "✅ Proses background dimulai\n", FILE_APPEND);
return true;
}
function extractAudio($filename = null) {
// HARUS ada filename
if ($filename === null) {
$filename = $_SESSION['current_video'] ?? '';
if (empty($filename)) {
file_put_contents('process.log', "❌ ERROR: Tidak ada filename yang provided\n");
return false;
}
}
// SIMPAN KE SESSION juga untuk backup
$_SESSION['current_video'] = $filename;
return startBackgroundProcess($filename);
}
function getProcessStatus() {
$logFile = 'process.log';
$doneFile = 'process_done';
$errorFile = 'process_error';
if (file_exists($errorFile)) {
$error = file_get_contents($errorFile);
@unlink($errorFile);
return ['status' => 'error', 'message' => $error];
}
if (file_exists($doneFile)) {
@unlink($doneFile);
return ['status' => 'completed', 'message' => 'Proses selesai'];
}
if (file_exists($logFile)) {
$logContent = file_get_contents($logFile);
// Cek berbagai indikator selesai
if (strpos($logContent, '🎉 PROSES SELESAI') !== false ||
strpos($logContent, '✅ PROSES SELESAI') !== false ||
strpos($logContent, '✅ Video berhasil: output/') !== false) {
return ['status' => 'completed', 'message' => 'Proses selesai'];
}
// Cek jika ada error dalam log
if (strpos($logContent, '❌ ERROR') !== false) {
return ['status' => 'error', 'message' => 'Error dalam proses - lihat log untuk detail'];
}
return ['status' => 'processing', 'message' => 'Sedang diproses', 'log' => $logContent];
}
return ['status' => 'ready', 'message' => 'Siap memulai'];
}
function stopProcess() {
if (isWindows()) {
shell_exec('taskkill /F /IM ffmpeg.exe 2>&1');
shell_exec('taskkill /F /IM python.exe 2>&1');
shell_exec('taskkill /F /IM php-cgi.exe 2>&1');
} else {
shell_exec('pkill -f ffmpeg');
shell_exec('pkill -f python');
shell_exec('pkill -f php');
}
// Cleanup files
@unlink('process.log');
@unlink('process_done');
@unlink('process_error');
return true;
}
// Fungsi untuk cek dependencies
function checkDependencies() {
if (isWindows()) {
$ffmpegPath = '"C:\\ProgramData\\chocolatey\\bin\\ffmpeg.exe"';
$pythonPath = '"C:\\Program Files\\PhpWebStudy-Data\\app\\python-3.13.3\\python.exe"';
} else {
$ffmpegPath = '/usr/bin/ffmpeg';
$pythonPath = '/usr/bin/python3';
}
echo "<pre>";
echo "=== SYSTEM INFORMATION ===\n";
echo "OS: " . PHP_OS . "\n";
echo "Working Dir: " . getcwd() . "\n\n";
echo "=== FFMPEG CHECK ===\n";
echo shell_exec("$ffmpegPath -version 2>&1");
echo "=== PYTHON CHECK ===\n";
echo shell_exec("$pythonPath --version 2>&1");
echo "=== VOSK MODEL CHECK ===\n";
$modelDir = "vosk-model/vosk-model-en-us-0.22";
echo "Model exists: " . (is_dir($modelDir) ? 'Yes' : 'No') . "\n";
echo "=== FILE CHECK ===\n";
echo "transcribe.py: " . (file_exists('transcribe.py') ? 'Yes' : 'No') . "\n";
echo "upload/0512.mp4: " . (file_exists('upload/0512.mp4') ? 'Yes' : 'No') . "\n";
echo "</pre>";
}
?>