-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
62 lines (53 loc) · 1.59 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
54
55
56
57
58
59
60
61
62
const electron = require('electron')
const ffmpeg = require('fluent-ffmpeg')
const _ = require('lodash')
const {
app,
BrowserWindow,
ipcMain,
shell
} = electron
let mainWindow
app.on('ready', ()=>{
mainWindow = new BrowserWindow({
width: 800,
height: 600,
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 outputDir = video.path.split(video.name)[0]
const outputName = video.name.split('.')[0]
const outputPath = `${outputDir}/${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, path)=>{
shell.showItemInFolder(path)
})