mirror of
https://gitlab.rlp.net/proj-wise2526-video2document/video2document.git
synced 2026-06-15 18:01:52 +02:00
146 lines
4.6 KiB
JavaScript
146 lines
4.6 KiB
JavaScript
// Loading required packages
|
|
require("./requires.js")
|
|
console.log(start);
|
|
|
|
|
|
// Initialising map to be used to store the functionality later on for reloadability
|
|
mapFunctions = new Map()
|
|
|
|
|
|
// Loading the Function Map
|
|
var path = `${mainDir}/services/modules`
|
|
var folders = fs.readdirSync(path).filter(function (file) {
|
|
return fs.statSync(path+'/'+file).isDirectory();
|
|
});
|
|
folders.forEach(element => {
|
|
var commandFiles = fs.readdirSync(`${path}/${element}`).filter(file => file.endsWith('.js') && !file.startsWith("index"));
|
|
for (const file of commandFiles) {
|
|
delete require.cache[require.resolve(`${path}/${element}/${file}`)];
|
|
const command = require(`${path}/${element}/${file}`);
|
|
mapFunctions.set(command.name, command);
|
|
}
|
|
});
|
|
|
|
|
|
|
|
// The startup information for the project, here you can add stuff that might be nice to see when the app starts
|
|
mapFunctions.get("Startup_function").function()
|
|
console.log("------------------------------------ Status ------------------------------------");
|
|
console.log(__dirname);
|
|
console.log(platform);
|
|
console.log(`The Startup took ${new Date() - start}ms`)
|
|
console.log(`${mapFunctions.size} Function modules loaded`);
|
|
console.log("--------------------------------------------------------------------------------");
|
|
|
|
|
|
// ======================== S3-06 : PIPELINE ORCHESTRATOR ========================
|
|
// Get audioEvents from ffmpegExtractor module
|
|
const ffmpegExtractor = mapFunctions.get("extraction-video-to-audio");
|
|
const audioEvents = ffmpegExtractor.audioEvents;
|
|
|
|
console.log('🎯 [S3-06] Pipeline Orchestrator ready. Listening for audio_ready events...');
|
|
|
|
audioEvents.on('audio_ready', async (data) => {
|
|
const { audioPath, sessionId } = data;
|
|
|
|
console.log(`✅ [Pipeline] Audio ready: ${sessionId}`);
|
|
console.log(`📁 Audio path: ${audioPath}`);
|
|
|
|
// Send status to UI
|
|
if (mainWindow) {
|
|
mainWindow.webContents.send('pipeline-status', {
|
|
sessionId,
|
|
status: 'audio_ready',
|
|
message: 'Audio bereit'
|
|
});
|
|
}
|
|
|
|
try {
|
|
console.log(`🚀 [Pipeline] Starting transcription: ${sessionId}`);
|
|
|
|
if (mainWindow) {
|
|
mainWindow.webContents.send('pipeline-status', {
|
|
sessionId,
|
|
status: 'transcription_started',
|
|
message: 'Transkription gestartet'
|
|
});
|
|
}
|
|
|
|
// Get transcription module
|
|
const assemblyModule = mapFunctions.get("assembly");
|
|
|
|
if (assemblyModule && assemblyModule.run) {
|
|
await assemblyModule.run(audioPath);
|
|
} else {
|
|
console.warn('⚠️ Assembly module not found or missing run function');
|
|
}
|
|
|
|
console.log(`✅ [Pipeline] Transcription completed: ${sessionId}`);
|
|
|
|
if (mainWindow) {
|
|
mainWindow.webContents.send('pipeline-status', {
|
|
sessionId,
|
|
status: 'transcription_completed',
|
|
message: 'Transkription abgeschlossen'
|
|
});
|
|
}
|
|
|
|
} catch (error) {
|
|
console.error(`❌ [Pipeline] Transcription failed: ${sessionId}`);
|
|
console.error(` Error:`, error.message);
|
|
|
|
if (mainWindow) {
|
|
mainWindow.webContents.send('pipeline-status', {
|
|
sessionId,
|
|
status: 'failed_transcription_start',
|
|
message: 'Fehler beim Transkriptionsstart',
|
|
error: error.message
|
|
});
|
|
}
|
|
}
|
|
});
|
|
// ===============================================================================
|
|
|
|
|
|
// --------------------------------------------------------- CLI COMMANDS --------------------------------------------------------- //
|
|
|
|
const rl = readline.createInterface({
|
|
input: process.stdin,
|
|
output: process.stdout
|
|
});
|
|
|
|
|
|
rl.on("line", data =>{
|
|
const args = data.trim().split(" ");
|
|
const command = args.shift().toLowerCase();
|
|
mapFunctions.get("cliCommands").function(command, args)
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
// ----------------------------------------------------------- ELECTRON ----------------------------------------------------------- //
|
|
|
|
let mainWindow;
|
|
|
|
function createWindow() {
|
|
mainWindow = new electron.BrowserWindow({
|
|
width: 800,
|
|
height: 600,
|
|
webPreferences: {
|
|
nodeIntegration: false,
|
|
contextIsolation: true,
|
|
preload: `${mainDir}/electron/main/preload.js`
|
|
}
|
|
});
|
|
|
|
mainWindow.loadFile('./electron/main/index.html');
|
|
}
|
|
|
|
electron.app.whenReady().then(createWindow);
|
|
|
|
|
|
electron.ipcMain.on("extract", (event, args) => {
|
|
mapFunctions.get("extraction-video-to-audio").function(args)
|
|
}) |