forked from anidl/multi-downloader-nx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
100 lines (96 loc) · 3.49 KB
/
index.ts
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
96
97
98
99
100
import { console } from './modules/log';
import { ServiceClass } from './@types/serviceClassInterface';
import { appArgv, overrideArguments } from './modules/module.app-args';
import * as yamlCfg from './modules/module.cfg-loader';
import { makeCommand, addToArchive } from './modules/module.downloadArchive';
import update from './modules/module.updater';
(async () => {
const cfg = yamlCfg.loadCfg();
const argv = appArgv(cfg.cli);
if (!argv.skipUpdate)
await update(argv.update);
if (argv.all && argv.but) {
console.error('--all and --but exclude each other!');
return;
}
if (argv.addArchive) {
if (argv.service === 'crunchy') {
if (argv.s === undefined && argv.series === undefined)
return console.error('`-s` or `--srz` not found');
if (argv.s && argv.series)
return console.error('Both `-s` and `--srz` found');
addToArchive({
service: 'crunchy',
type: argv.s === undefined ? 'srz' : 's'
}, (argv.s === undefined ? argv.series : argv.s) as string);
console.info('Added %s to the downloadArchive list', (argv.s === undefined ? argv.series : argv.s));
} else if (argv.service === 'hidive') {
if (argv.s === undefined)
return console.error('`-s` not found');
addToArchive({
service: 'hidive',
//type: argv.s === undefined ? 'srz' : 's'
type: 's'
}, (argv.s === undefined ? argv.series : argv.s) as string);
console.info('Added %s to the downloadArchive list', (argv.s === undefined ? argv.series : argv.s));
} else if (argv.service === 'ao') {
if (argv.s === undefined)
return console.error('`-s` not found');
addToArchive({
service: 'hidive',
//type: argv.s === undefined ? 'srz' : 's'
type: 's'
}, (argv.s === undefined ? argv.series : argv.s) as string);
console.info('Added %s to the downloadArchive list', (argv.s === undefined ? argv.series : argv.s));
}
} else if (argv.downloadArchive) {
const ids = makeCommand(argv.service);
for (const id of ids) {
overrideArguments(cfg.cli, id);
/* Reimport module to override appArgv */
Object.keys(require.cache).forEach(key => {
if (key.endsWith('crunchy.js') || key.endsWith('hidive.js') || key.endsWith('ao.js'))
delete require.cache[key];
});
let service: ServiceClass;
switch(argv.service) {
case 'crunchy':
service = new (await import('./crunchy')).default;
break;
case 'hidive':
service = new (await import('./hidive')).default;
break;
case 'ao':
service = new (await import('./ao')).default;
break;
case 'adn':
service = new (await import('./adn')).default;
break;
default:
service = new (await import(`./${argv.service}`)).default;
break;
}
await service.cli();
}
} else {
let service: ServiceClass;
switch(argv.service) {
case 'crunchy':
service = new (await import('./crunchy')).default;
break;
case 'hidive':
service = new (await import('./hidive')).default;
break;
case 'ao':
service = new (await import('./ao')).default;
break;
case 'adn':
service = new (await import('./adn')).default;
break;
default:
service = new (await import(`./${argv.service}`)).default;
break;
}
await service.cli();
}
})();