Spaces:
Paused
Paused
Download api/extract.php from josephrw/videoapp-compiler: direct link, hf CLI and curl.
- Browser
- Download file 1.45 kB
-
https://huggingface.co/spaces/josephrw/videoapp-compiler/resolve/main/api/extract.php
- Command line
-
hf download hf://spaces/josephrw/videoapp-compiler/api/extract.php
-
curl -L -o extract.php https://huggingface.co/spaces/josephrw/videoapp-compiler/resolve/main/api/extract.php
1.45 kB
| require_once __DIR__ . '/config.php'; | |
| ensure_dirs(); | |
| $id = $_POST['id'] ?? $_GET['id'] ?? null; | |
| if (!$id || !preg_match('/^[a-f0-9]{16}$/', $id)) { | |
| fail_json('Invalid id'); | |
| } | |
| $jobPath = RECEIPT_DIR . "/$id.job.json"; | |
| $job = read_json_file($jobPath); | |
| if (!$job) { | |
| fail_json('Job not found', 404); | |
| } | |
| $video = $job['upload_path']; | |
| if (!file_exists($video)) { | |
| fail_json('Uploaded video missing'); | |
| } | |
| $outDir = RECEIPT_DIR . "/$id"; | |
| if (!is_dir($outDir)) { | |
| mkdir($outDir, 0775, true); | |
| } | |
| $cmd = BIN_EXTRACT . ' extract ' . shell_arg($video) . ' ' . shell_arg($outDir) . ' 2>&1'; | |
| $output = []; | |
| $code = 0; | |
| exec($cmd, $output, $code); | |
| $receiptPath = "$outDir/receipt.json"; | |
| $receipt = read_json_file($receiptPath); | |
| // Inject videoId and videoName into receipt | |
| if ($receipt) { | |
| $receipt['videoId'] = $id; | |
| $receipt['videoName'] = $job['original_name']; | |
| write_json_file($receiptPath, $receipt); | |
| } | |
| $job['status'] = $code === 0 ? 'extracted' : 'extract_failed'; | |
| $job['extract_exit_code'] = $code; | |
| $job['extract_log'] = implode("\n", array_slice($output, -80)); | |
| $job['receipt_path'] = $receiptPath; | |
| $job['updated_at'] = time(); | |
| write_json_file($jobPath, $job); | |
| if ($code !== 0 || !$receipt) { | |
| fail_json('Extraction failed', 500, [ | |
| 'exit_code' => $code, | |
| 'log' => $job['extract_log'] | |
| ]); | |
| } | |
| json_response([ | |
| 'ok' => true, | |
| 'id' => $id, | |
| 'receipt' => $receipt, | |
| 'log' => $job['extract_log'] | |
| ]); | |