-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
53 lines (45 loc) · 1.48 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
const electron = require('electron');
const ffmpeg = require('fluent-ffmpeg');
const { app, BrowserWindow, ipcMain, shell } = electron;
const _ = require('lodash');
let mainWindow;
app.on('ready', () => {
mainWindow = new BrowserWindow({
height: 600,
width: 800,
webPreferences: { backgroundThrottling: false}
});
mainWindow.loadURL(`file://${__dirname}/src/index.html`);
});
ipcMain.on('videos:added', (event, videos) => {
const promises = _.map(videos, video => {
return new Promise((resolve, reject) => {
ffmpeg.ffprobe(video.path, (err, metadata) => {
video.duration = metadata.format.duration;
video.format = 'avi';
resolve(video);
});
});
});
Promise.all(promises)
.then((results) => {
mainWindow.webContents.send('metadata:complete', results);
});
});
ipcMain.on('conversion:start', (event, videos) => {
_.each(videos, video => {
const outputName = video.name.split('.')[0];
const outputDirectory = video.path.split(video.name)[0];
const outputPath = `${outputDirectory}${outputName}.${video.format}`;
ffmpeg(video.path)
.output(outputPath)
.on('progress', ({ timemark }) => {
mainWindow.webContents.send('conversion:progress', { video, timemark });
})
.on('end', () => mainWindow.webContents.send('conversion:end', { video, outputPath }))
.run();
});
});
ipcMain.on('folder:open', (event, outputPath) => {
shell.showItemInFolder(outputPath);
});