-
Notifications
You must be signed in to change notification settings - Fork 18
/
index.js
executable file
·67 lines (61 loc) · 2.33 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
63
64
65
66
67
#!/usr/bin/env node
var ffmpeg = require('fluent-ffmpeg');
var nsg = require('node-sprite-generator');
var Jimp = require('jimp');
var rm = require('rimraf');
var Spinner = require('cli-spinner').Spinner;
var program = require('commander');
var os = require('os');
var spinner;
function startSpinner (string, step) {
spinner = new Spinner(`[${step}/3] %s ${string}...`);
spinner.setSpinnerString('|/-\\');
spinner.start();
}
var startTime = +new Date();
var tmp = os.tmpdir() + '/dplayer-thumbnails'
program
.version('0.0.5')
.usage('[options] <file>')
.option('-o, --output <path>', 'thumbnails path, default: ./thumbnails.jpg', './thumbnails.jpg')
.option('-q, --quality <n>', 'thumbnails quality, default: 60', 60)
.description('🎉 Generate thumbnails for DPlayer')
.action(function (file) {
startSpinner('Screenshots generating', 1);
ffmpeg(file)
.screenshots({
count: 100,
folder: tmp,
filename: 'screenshot%00i.png',
size: '160x?'
})
.on('end', function () {
spinner.stop(true);
console.log('[1/3] Screenshots generated!');
startSpinner('Sprite generating', 2);
nsg({
src: [
tmp + '/*.png'
],
spritePath: tmp + '/sprite.png',
stylesheetPath: tmp + '/sprite.css',
layout: 'horizontal',
compositor: 'jimp'
}, function (err) {
spinner.stop(true);
console.log('[2/3] Sprite generated!');
startSpinner('Compressing', 3);
Jimp.read(tmp + '/sprite.png', function (err, lenna) {
if (err) throw err;
lenna.quality(parseInt(program.quality))
.write(program.output);
rm(tmp, function () {
spinner.stop(true);
console.log('[3/3] Compressing complete!');
console.log(`✨ Done in ${(+new Date() - startTime) / 1000}s.`);
});
});
});
});
});
program.parse(process.argv);