-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
68 lines (60 loc) · 2.09 KB
/
app.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
63
64
65
66
67
68
const fs = require('fs');
const _ = require("lodash/fp");
const debug = require('./debug');
const m4aFile = require('./m4aFile');
const makePath = require('./makePath');
const startTime = new Date();
// const readDir = "n:/zzzTag/temp";
// const readDir = "n:/zzzTag/allfiles";
const readDir = "C:/Users/dan/Desktop/iPlayer Recordings";
const writeDir = "n:/zzzTag/output";
// const writeDir = "C:/Users/dan/Desktop/iPlayer Recordings/tagged";
const completeDir = makePath([readDir, "complete"]);
const failDir = makePath([readDir, "failed"]);
const filesToMatch = /\.m(4a|p3)$/;
m4aFile.setDefaults({
readDir,
writeDir,
completeDir,
failDir
})
let chain = Promise.resolve();
let filesProcessed = 0;
let filesFailed = 0;
let filesSkipped = 0;
const errors = [];
fs.readdir(readDir, function (err, files) {
_.forEach(function (filename) {
if (filesToMatch.exec(filename)) {
chain = chain.then(function () {
filesProcessed++;
return m4aFile
.processFile(filename)
.then(function (error) {
if (error) {
errors.push(error);
filesFailed++;
}
})
});
} else {
filesSkipped++;
debug("Skipping: " + filename);
}
}, files);
chain = chain.then(function () {
const endTime = new Date();
let timeDiff = (endTime - startTime) / 1000;
const seconds = Math.round(timeDiff % 60);
timeDiff = Math.floor(timeDiff / 60);
const minutes = Math.round(timeDiff % 60);
timeDiff = Math.floor(timeDiff / 60);
const hours = Math.round(timeDiff % 24);
timeDiff = Math.floor(timeDiff / 24);
const days = timeDiff;
if (errors.length) {
debug("Errors encountered: ", errors);
}
debug(`Processed ${filesProcessed} files of which ${filesFailed} failed. Skipped ${filesSkipped} files/directories.`, `In ${days} days, ${hours}:${minutes}:${seconds}`);
})
});