-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
executable file
·79 lines (68 loc) · 1.66 KB
/
app.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
77
78
79
#!/usr/bin/env node
// NPM modulues
const figlet = require('figlet');
const yargs = require('yargs');
const chalk = require('chalk');
// Intro
console.clear();
console.log(
chalk.blue(figlet.textSync('YouTube-Cli', { horizontalLayout: 'full' }))
);
// Check '-v' or '--verbose' has been passend in the cli input
const _arguments = process.argv;
if (_arguments.includes('-v') || _arguments.includes('--verbose')) {
process.env.YOUTUBECLI_DEBUG = 'debug';
}
// Custom modules
const init = require('./lib/init');
const youtube = require('./lib/youtube');
const Configstore = require('configstore');
const { cliConfigFile } = require('./lib/constants');
const config = new Configstore(cliConfigFile);
// Basics
yargs.version('1.0.0');
yargs.scriptName('youtube-cli');
yargs.usage('Usage: $0 <cmd> [options]');
// Download the audio stream
yargs.command({
command: 'download',
describe: 'Download the audio stream from a YouTube URL',
builder: {
url: {
describe: 'Youtube URL',
demandOption: true,
type: 'string',
},
},
handler: (argv) => {
const url = argv.url.replace(/\\/g, '');
youtube.main(url);
},
});
// Setup up the configuration file
yargs.command({
command: 'config',
describe: 'Create the folders for audio',
builder: {
audio: {
describe: 'Path for storing audio files',
demandOption: true,
type: 'string',
},
},
handler: (argv) => {
init.createConfig(argv.audio);
},
});
// Enable verbose mode
yargs.option('verbose', {
alias: 'v',
type: 'boolean',
description: 'Run with verbose logging',
}).argv;
// Require one command
yargs.demandCommand(1);
// Parse all commands
yargs.parse();
// Validate config
init.validateConfig(config.path);