forked from Ivshti/node-subtitles-grouping
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·34 lines (27 loc) · 954 Bytes
/
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
#!/usr/bin/env node
var retriever = require("./lib/retriever");
var getHeatmap = require("./lib/heatmap");
var srt = require("./lib/srt");
var grouping = require("./lib/grouping");
var async = require("async");
module.exports = function grouper(subs, callback, options) {
subs = subs.map(function(x, i) {
if (typeof(x) == "string") return { uri: x, id: i };
return x;
});
async.map(subs, function(x, cb) { retriever.retrieveSrt(x.uri, cb, options) }, function(err, srts) {
if (err) return callback(err);
srts.forEach(function(b, i) {
subs[i].heatmap = getHeatmap(srt.parseString(b));
});
var groups = grouping.group(subs, options && options.sensitivity);
callback(null, groups);
});
};
// CLI use
if (!module.parent) {
module.exports(process.argv.slice(2), function(err, res) {
if (res) res.forEach(function(g) { g.forEach(function(s) { delete s.heatmap }) });
console.log(err || JSON.stringify(res, null, 4))
})
}