From 2aba611906b7ab96ff4dfa3520efe6d4de05896a Mon Sep 17 00:00:00 2001 From: orfelorfel23 Date: Sun, 6 Sep 2026 00:50:25 +0200 Subject: [PATCH] fix: handle raw preset JSON files and infer audio/title automatically --- worker.mjs | 42 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/worker.mjs b/worker.mjs index f55d1d7..a0d7e67 100644 --- a/worker.mjs +++ b/worker.mjs @@ -73,17 +73,40 @@ async function main() { async function processJob({ jsonPath, job, expectedVideoPath, targetFormat }) { const fileName = path.basename(jsonPath); console.log(`\n---------------------------------------------------`); - console.log(`🎬 Starte Render-Job für: ${job.title} (${job.id})`); + console.log(`🎬 Starte Render-Job aus Datei: ${fileName}`); - const audioFileAbs = path.resolve(path.dirname(jsonPath), job.audio); - if (!fs.existsSync(audioFileAbs)) { - console.error(`❌ Audiodatei nicht gefunden: ${audioFileAbs}`); - await sendError(fileName, `Audiodatei nicht gefunden: ${audioFileAbs}`); + const parentDir = path.resolve(path.dirname(jsonPath), '..'); + let audioFileAbs = null; + + if (job.audio) { + audioFileAbs = path.resolve(path.dirname(jsonPath), job.audio); + } else { + // Versuche automatisch ein Audio-File im Parent-Ordner zu finden + const parentFiles = fs.readdirSync(parentDir); + const audioFileName = parentFiles.find(f => f.toLowerCase().endsWith('.wav') || f.toLowerCase().endsWith('.mp3') || f.toLowerCase().endsWith('.flac')); + if (audioFileName) { + audioFileAbs = path.join(parentDir, audioFileName); + } + } + + if (!audioFileAbs || !fs.existsSync(audioFileAbs)) { + console.error(`❌ Audiodatei nicht gefunden für ${fileName}`); + await sendError(fileName, `Audiodatei nicht gefunden für ${fileName}`); return; } console.log(`🎵 Audio geladen: ${audioFileAbs}`); + // Bestimme Titel aus Parent-Ordner falls nicht gesetzt (z.B. "999 - Catch the Fire" -> "Catch the Fire") + let autoTitle = job.title; + if (!autoTitle) { + const folderName = path.basename(parentDir); + const match = folderName.match(/^\d+\s*-\s*(.+)$/); + autoTitle = match ? match[1] : folderName; + } + + const autoArtist = job.artist || ''; + let browser; try { browser = await puppeteer.launch({ @@ -105,6 +128,7 @@ async function processJob({ jsonPath, job, expectedVideoPath, targetFormat }) { await page.goto(VIZ_URL, { waitUntil: 'networkidle2' }); // 1. Audio Upload auslösen + await page.waitForSelector('#audioFileInput', { timeout: 10000 }); const audioInput = await page.$('#audioFileInput'); await audioInput.uploadFile(audioFileAbs); @@ -122,6 +146,12 @@ async function processJob({ jsonPath, job, expectedVideoPath, targetFormat }) { } }, job.preset); console.log(`🎨 Preset "${job.preset}" angewendet.`); + } else if (job.name !== undefined) { + // JSON is a direct preset config object + await page.evaluate((presetObj) => { + window.VIZ_API.applyPreset(presetObj); + }, job); + console.log(`🎨 Direct Preset Config "${job.name}" angewendet.`); } // 3. Titel, Artist, Aspect @@ -143,7 +173,7 @@ async function processJob({ jsonPath, job, expectedVideoPath, targetFormat }) { } window.VIZ_API.updateConfigFromUI(); - }, job.title, job.artist, job.aspect, targetFormat); + }, autoTitle, autoArtist, job.aspect, targetFormat); // 4. Render-Knopf drücken console.log('🚀 Starte Export-Prozess...');