fix: handle raw preset JSON files and infer audio/title automatically

This commit is contained in:
Jannik committed 2026-09-06 00:50:25 +02:00
1 parent 49888bda10
commit 2aba611906
1 file changed
+36 -6
+36 -6
View File
@@ -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...');