-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.js
executable file
·76 lines (63 loc) · 1.86 KB
/
cli.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
69
70
71
72
73
74
75
76
#!/usr/bin/env node
'use strict';
const spawn = require('child_process').spawn;
const electron = require('electron');
const updateNotifier = require('update-notifier');
const Conf = require('conf');
const pixivDl = require('pixiv-dl');
const meow = require('meow');
const config = new Conf();
const cli = meow(`
Usage
$ pixiv-dl-preview [input]
Options
--uername, -u pixiv username (use cache)↲
--password, -p pixiv password (use cache)↲
--output, -o output directory [Default: curret dir]
--name, -n custom filename
--delay, -d delay time (ms) [Default: 5000]
ranking ranking mode
day | week | month | day_male | day_female | week_original | week_rookie | day_mang
day_r18 | day_male_r18 | day_female_r18 | week_r18 | week_r18g
Examples
$ pixiv-dl-preview リゼロ10000users入り --username hoge --password fuga
$ pixiv-dl-preview リゼロ10000users入り --output rezero --name user.account-title
$ pixiv-dl-preview ranking day --output rezero --name user.account-title
`, {
alias: {
output: 'o',
name: 'n',
username: 'u',
password: 'p',
delay: 'd'
},
default: {
output: process.cwd(),
delay: 5000
}
});
updateNotifier({pkg: cli.pkg}).notify();
if (!cli.input[0]) {
console.log('required word');
process.exit(1);
}
const opts = cli.flags;
if (cli.input[1]) {
opts.mode = cli.input[1];
}
opts.username = opts.username || config.get('username');
opts.password = opts.password || config.get('password');
if (!(opts.username && opts.password)) {
console.log('require username && password');
process.exit(1);
}
const ps = spawn(electron, [__dirname, opts.output], {stdio: 'inherit'});
pixivDl(cli.input[0], opts).then(() => {
ps.kill('SIGHUP');
process.exit(0);
}).catch(err => {
console.error(err);
process.exit(1);
});
config.set('username', opts.username);
config.set('password', opts.password);