-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathevent.js
More file actions
96 lines (73 loc) · 2.17 KB
/
event.js
File metadata and controls
96 lines (73 loc) · 2.17 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
const { execSync, exec } = require("child_process");
const fs = require('fs-extra')
module.exports = (ipcMain, win) => {
ipcMain.handle('sendCommand', async (event, r) => {
// return {"received": someArgument}
let res = execSync(r.command);
//console.info('res.error', res.error);
console.info('res', res.toString());
return {back: "ok"};
})
ipcMain.handle('folderInfo', async (event, path) => {
let isDir = false,
listFiles = [];
if(fs.lstatSync(path).isDirectory()){
isDir = true;
if(fs.pathExistsSync(path)){
let files = fs.readdirSync(path);
files.forEach(file => {
if(!fs.lstatSync(path + "/" + file).isDirectory()){
console.info('file', file);
listFiles.push(file)
}
});
}
}else{
}
return {
"isDir": isDir,
"files": listFiles
};
})
ipcMain.handle('triggerMetaCopy', async (event, r) => {
/**
* r => {
* files: [{}, {}]
*
* }
*/
fs.ensureDir(`${r.dir}/${r.outputDir}`).then(() => {
r.files.forEach((o, pos) => {
let ext = o.original.substr(o.original.lastIndexOf('.')),
oriName = o.original.substr(0, o.original.lastIndexOf('.'))
if(fs.existsSync(`${r.dir}/${r.outputDir}/${oriName+ext}`)){
win.webContents.send("fileStatus", {
"error": null, // if null, it means success
"stderr": null,
"stdout": "This file already exist in the destination folder.",
"index": pos,
});
}else{
// let newNameWhenCopied = o.original.replace(ext, "-metaAdded")
let command = `ffmpeg -i "${r.dir}/${o.original}" -i "${r.dir}/${o.compressed}" -movflags use_metadata_tags -map 1 -map_metadata 0 -c copy "${r.dir}/${r.outputDir}/${oriName+ext}"`
console.info("command", command);
exec(command, (error, stdout, stderr) => {
console.info({
"error": error, // if null, it means success
"stderr": stderr,
"stdout": stdout,
"index": pos,
});
win.webContents.send("fileStatus", {
"error": error, // if null, it means success
"stderr": stderr,
"stdout": stdout,
"index": pos,
});
});
}
})
})
return true;
})
}