-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathreactive.js
More file actions
95 lines (85 loc) · 2.3 KB
/
reactive.js
File metadata and controls
95 lines (85 loc) · 2.3 KB
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
#!/usr/bin/env node
const debug = require('debug')('ymr')
const chalk = require('chalk')
const figlet = require('figlet')
const inquirer = require('inquirer')
const display = require('./lib/display')
const markdown = require('./lib/markdown')
const log = console.log
const ASK_API_KEY = {
type: 'input',
name: 'GOOGLE_API_KEY',
message: "What's your Google API key?",
default: function() {
return process.env.GOOGLE_API_KEY
},
validate: function(value) {
if (process.env.GOOGLE_API_KEY) return true
var pass = value.length >= 20
if (pass) {
return true
}
return 'Please enter a valid Google API key.'
},
}
const ASK_TYPE = {
type: 'list',
name: 'typeText',
message: 'What things you like to do?',
choices: [
'only show the information',
'generate a playlist',
'generate all playlist',
],
}
const ASK_PLAYLIST_ID = {
type: 'input',
name: 'PLAYLIST_ID',
message: 'Input the Youtube playlist ID?',
validate: function(value) {
var pass = value.length >= 18
if (pass) return true
return 'Please enter a valid Youtube playlist ID.'
},
}
const ASK_CHANNEL_ID = {
type: 'input',
name: 'CHANNEL_ID',
message: 'Input the Youtube channel ID?',
validate: function(value) {
var pass = value.length >= 24
if (pass) return true
return 'Please enter a valid Youtube channel ID.'
},
}
function getType(val) {
if (val == 'only show the information') {
return 1
} else if (val == 'generate a playlist') {
return 2
} else if (val == 'generate all playlist') {
return 3
} else {
return 0
}
}
function displayWelcomeMessage() {
log(chalk.blue(figlet.textSync('Welcome!', { horizontalLayout: 'full' })))
}
async function main() {
displayWelcomeMessage()
const { GOOGLE_API_KEY } = await inquirer.prompt(ASK_API_KEY)
const config = { GOOGLE_API_KEY }
const { typeText } = await inquirer.prompt(ASK_TYPE)
const type = getType(typeText)
if (type == 1 || type == 2) {
let { PLAYLIST_ID } = await inquirer.prompt(ASK_PLAYLIST_ID)
console.log('\n\n')
if (type == 1) await display.playlistItem(config, PLAYLIST_ID)
if (type == 2) await markdown.generatorPlaylist(PLAYLIST_ID)
} else {
let { CHANNEL_ID } = await inquirer.prompt(ASK_CHANNEL_ID)
await markdown.generatorAll(CHANNEL_ID)
}
}
main()