-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
65 lines (55 loc) · 1.46 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
const cluster = require('cluster');
const os = require('os');
const fs = require('fs');
const inquirer = require('inquirer');
const getDateString = require('./utils/getDateFormat');
const { download } = require('./utils/downloadManager');
const questions = [
{
type: 'list',
name: 'inputType',
message: 'What are you going to download?',
choices: [
{ name: 'Single video', value: 'single' },
{ name: 'Playlist', value: 'playlist' },
],
},
{
type: 'input',
name: 'url',
message: "Url of the video/playlist you're going to download",
},
{
type: 'list',
name: 'outputType',
message: 'What do you want to download?',
choices: [
{ name: 'Only audio', value: 'audio' },
{ name: 'Audio and video', value: 'video' },
],
},
];
const cpuCount = os.cpus().length;
(async () => {
const downloadsFolder = `./downloads/${getDateString()}`;
fs.mkdirSync(downloadsFolder);
const { inputType, url, outputType } = await inquirer.prompt(questions);
if (inputType === 'playlist') {
cluster.settings = {
exec: './utils/multiThreadDownload.js',
};
for (let i = 1; i <= cpuCount; i++) {
const childProcess = cluster.fork({
processId: i,
inputType,
url,
outputType,
cpuCount,
downloadsFolder,
});
childProcess.disconnect();
}
} else {
await download(inputType, url, outputType, cpuCount, downloadsFolder);
}
})();