feat: autostart local viz server on port 3001
This commit is contained in:
1 parent
916bb4f49e
commit
39451db99b
1 file changed
+37
-6
+37
-6
@@ -3,9 +3,15 @@ import path from 'path';
|
|||||||
import puppeteer from 'puppeteer';
|
import puppeteer from 'puppeteer';
|
||||||
import fetch from 'node-fetch';
|
import fetch from 'node-fetch';
|
||||||
import { pipeline } from 'stream/promises';
|
import { pipeline } from 'stream/promises';
|
||||||
|
import { spawn } from 'child_process';
|
||||||
|
import { fileURLToPath } from 'url';
|
||||||
|
|
||||||
|
const __filename = fileURLToPath(import.meta.url);
|
||||||
|
const __dirname = path.dirname(__filename);
|
||||||
|
|
||||||
const BASE_DIR = 'D:/Google Drive/Videos/AIWentNonsense';
|
const BASE_DIR = 'D:/Google Drive/Videos/AIWentNonsense';
|
||||||
const VIZ_URL = 'http://localhost:3000';
|
const VIZ_PORT = 3001;
|
||||||
|
const VIZ_URL = `http://localhost:${VIZ_PORT}`;
|
||||||
const NTFY_URL = 'https://ntfy.orfel.de/viz_errors';
|
const NTFY_URL = 'https://ntfy.orfel.de/viz_errors';
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
@@ -34,16 +40,12 @@ async function main() {
|
|||||||
try {
|
try {
|
||||||
const job = JSON.parse(fs.readFileSync(jsonPath, 'utf8'));
|
const job = JSON.parse(fs.readFileSync(jsonPath, 'utf8'));
|
||||||
|
|
||||||
// Zieldateiname bestimmen
|
|
||||||
const targetFormat = job.format === 'prores4444' ? 'prores' : (job.format || 'prores');
|
const targetFormat = job.format === 'prores4444' ? 'prores' : (job.format || 'prores');
|
||||||
const outExt = (targetFormat === 'prores' || targetFormat === 'qtrle') ? '.mov' : (targetFormat === 'webm_alpha' ? '.webm' : '.mp4');
|
const outExt = (targetFormat === 'prores' || targetFormat === 'qtrle') ? '.mov' : (targetFormat === 'webm_alpha' ? '.webm' : '.mp4');
|
||||||
|
|
||||||
// Prüfen, ob bereits irgendeine Datei mit dieser Endung (z.B. .mov) im Ordner liegt
|
|
||||||
const hasVideoAlready = files.some(f => f.toLowerCase().endsWith(outExt));
|
const hasVideoAlready = files.some(f => f.toLowerCase().endsWith(outExt));
|
||||||
|
|
||||||
// Job nur vormerken, wenn NOCH KEIN solches Video existiert
|
|
||||||
if (!hasVideoAlready) {
|
if (!hasVideoAlready) {
|
||||||
// Wir definieren dennoch einen finalen Dateinamen für den neuen Render
|
|
||||||
const finalTitle = job.title ? job.title.replace(/[^a-zA-Z0-9_-]/g, '_') : 'Output';
|
const finalTitle = job.title ? job.title.replace(/[^a-zA-Z0-9_-]/g, '_') : 'Output';
|
||||||
const expectedVideoPath = path.join(vizDir, `${finalTitle}${outExt}`);
|
const expectedVideoPath = path.join(vizDir, `${finalTitle}${outExt}`);
|
||||||
pendingJobs.push({ jsonPath, job, expectedVideoPath, targetFormat });
|
pendingJobs.push({ jsonPath, job, expectedVideoPath, targetFormat });
|
||||||
@@ -61,12 +63,41 @@ async function main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
console.log(`🚀 ${pendingJobs.length} anstehende(r) Job(s) gefunden.`);
|
console.log(`🚀 ${pendingJobs.length} anstehende(r) Job(s) gefunden.`);
|
||||||
|
console.log(`⚙️ Starte temporären lokalen Viz Server auf Port ${VIZ_PORT}...`);
|
||||||
|
|
||||||
|
const serverProcess = spawn('node', ['server.mjs'], {
|
||||||
|
env: { ...process.env, PORT: VIZ_PORT.toString() },
|
||||||
|
cwd: __dirname,
|
||||||
|
stdio: 'inherit'
|
||||||
|
});
|
||||||
|
|
||||||
|
// Warte bis der Server erreichbar ist
|
||||||
|
let serverReady = false;
|
||||||
|
for (let i = 0; i < 20; i++) {
|
||||||
|
await new Promise(r => setTimeout(r, 1000));
|
||||||
|
try {
|
||||||
|
const res = await fetch(VIZ_URL);
|
||||||
|
if (res.ok) {
|
||||||
|
serverReady = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (e) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!serverReady) {
|
||||||
|
console.error('❌ Temporärer Server konnte nicht gestartet werden. Beende.');
|
||||||
|
serverProcess.kill();
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(`✅ Server ist online! Starte Verarbeitung...\n`);
|
||||||
|
|
||||||
for (const jobItem of pendingJobs) {
|
for (const jobItem of pendingJobs) {
|
||||||
await processJob(jobItem);
|
await processJob(jobItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('\n🎉 Alle Jobs abgearbeitet!');
|
console.log('\n🎉 Alle Jobs abgearbeitet! Schalte temporären Server ab...');
|
||||||
|
serverProcess.kill();
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user