-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
237 lines (217 loc) · 13.1 KB
/
main.js
File metadata and controls
237 lines (217 loc) · 13.1 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
const { sys } = require('./Side_Functions/System');
const prompt = require('prompt-sync')({sigint: true});
const {validate} = require('./Side_Functions/validate');
const {lobby} = require('./Side_Functions/lobby');
const {Downloader} = require('./Downloader');
const fs = require('fs');
const {speedtester} = require('./Side_Functions/speedtest');
const {Timeout} = require('./Side_Functions/Timeout')
const prompts = require('prompts');
prompts.override(require('yargs').argv);
var jsonop = fs.readFileSync(__dirname + '/Option.json')
const {fileformatin, qualityprop} = require('./loader')
var Optionobj = JSON.parse(jsonop);
var path;
var verify;
var link;
var sidechoices
var quality
var choice;
var pathv
var count = 0;
var property = {
format: "",
quality: ""
}
var turnpath = __dirname + '/Side_Functions/downlog.txt'
fs.truncate(turnpath, 0, function(){console.log('')})
async function checkInternet(cb) {
require('dns').lookup('google.com', async function(err) {
if (err && err.code == "ENOTFOUND") {
cb(false);
} else {
cb(true);
}
})
}
console.clear()
sleep(1500)
lobby(false)
checkInternet(function(isConnected) {
if (isConnected) {
do{
if(verify === 0){
console.clear();
sleep(500)
lobby()
console.log('╭───────────────────────────────────────────────────────────────────────────╮');
console.log('│ |');
console.log('│ ❌ ENTRY ERROR: INVALID YOUTUBE MEDIA URL! ❌ │');
console.log('│ |');
console.log('│ Please make sure you entered a valid YouTube media URL and try again. │');
console.log('│ |');
console.log('╰───────────────────────────────────────────────────────────────────────────╯');
}
link = phase1(link);
verify = validate(link, verify)
}while(verify !== 1 && verify !== 2)
/*async function fileformatprop(){
do{
if(!fileformat) sleep(700); lobby();
if(count !== 0){
sleep(700);
lobby();
console.log('╭───────────────────────────────────────────────────────────────────────────╮');
console.log('│ |');
console.log('│ ❌ PROMPT ERROR: INVALID FILE FORMAT VALUE! ❌ │');
console.log('│ |');
console.log('│ Please enter a correct format value │');
console.log('│ (Possible values) |');
console.log('│ .mp3, .mp4, .mkv, .aac, .flac, .wav |');
console.log('╰───────────────────────────────────────────────────────────────────────────╯');
}
count = 0;
/*console.log('─────────────────────────────────────────────────────────────────────────────────╮');
console.log(' Please choose the file format in which you want the file to be saved │');
console.log('─────────────────────────────────────────────────────────────────────────────────╯');
//fileformat = prompt(':> '); console.log('\n')
fileformat = await fileformatin()
console.log(fileformat)
fileformat = fileformat.toLowerCase()
count++
}while( fileformat !== '.mp3' && fileformat !== 'mp3' && fileformat !== '.aac' && fileformat !== '.mp4' && fileformat !== 'mp4' && fileformat !== 'aac' && fileformat !== 'mkv' && fileformat !== '.mkv' && fileformat !== '.flac' && fileformat !== 'flac'&& fileformat !== '.wav' && fileformat !== 'wav')
}*/
fileformatin().then( fileformat => {
if(fileformat === 'mkv' || fileformat === 'aac' || fileformat === 'flac' || fileformat === 'wav' ){
fileformat = '.' + fileformat
if(fileformat === 'aac') sidechoices = 'enable-AAC';
if(fileformat === 'flac') sidechoices = 'enable-FLAC'
if(fileformat === 'wav') {sidechoices = 'enable-WAV';}
exception = true
}
sleep(700)
lobby()
var pathf = 0
if(fileformat === '.mkv' || fileformat === '.aac' || fileformat === '.flac' || fileformat === '.wav' ){
pathf = 1
quality = 'greatest'
nextphase(fileformat, quality)
}
else{
pathf = 0
qualityprop(pathf).then(quality => {
nextphase(fileformat, quality)
/*var code = 0
process.exit (code)*/
})
}
/*do{
if(qualityver === 0){
sleep(700)
lobby()
console.log('╭───────────────────────────────────────────────────────────────────────────╮');
console.log('│ |');
console.log('│ ❌ PROMPT ERROR: INVALID QUALITY VALUE! ❌ │');
console.log('│ |');
console.log('│ Please enter a correct quality value │');
console.log('│ (Possibilities: low, high, greatest (AAC/MKV/FLAC/WAV)) |');
console.log('╰───────────────────────────────────────────────────────────────────────────╯');
}
console.log('─────────────────────────────────────────────────────────────────────────────────╮');
console.log(' Please insert the quality of which you want the file to be saved │');
console.log('─────────────────────────────────────────────────────────────────────────────────╯');
quality = prompt(':> '); console.log('\n')
quality = quality.toLowerCase()
qualityver = 0;
if(exception && quality !== 'greatest') quality = ''
else if(exception && quality === 'high') quality = 'greatest'
}while(quality !== 'low' && quality !== 'lowest' && quality !== 'high' && quality !== 'highest' && quality !== 'greatest')
*/
function nextphase(fileformat, quality){
lobby();
switch (fileformat) {
case '.mp4':
case 'mp4':
if (quality === 'high' || quality === 'highest') {
quality = 'highestvideo';
} else {
quality = 'lowestvideo';
}
choice = 'videoandaudio';
fileformat = '.mp4';
break;
case '.mp3':
case 'mp3':
if (quality === 'high' || quality === 'highest') {
quality = 'highestaudio';
} else {
quality = 'lowestaudio';
}
choice = 'audioonly';
fileformat = '.mp3';
break;
}
if(Optionobj.speedtester === "true"){
console.log('OverPrompt will measure your connection integrity while you are using the application ')
Timeout(speedtester, 5000)
}
if(fileformat === ".mp3"){path = './Output/MP3/'}
else if (fileformat === '.mp4'){path = './Output/MP4'}
else if(fileformat === '.mkv') {path = './Output/MKV'}
else if(fileformat === '.aac') {path = './Output/AAC'}
else if(fileformat === '.flac') {path = './Output/FLAC'}
else if(fileformat === '.wav') {path = './Output/WAV'}
pathv = path + '/'
if(verify === 2){
sys(link).then(() => {
lobby()
const filePath = './playlist.json'
var jsontemp = fs.readFileSync(filePath)
var object = JSON.parse(jsontemp)
let loops = object.entities;
let abspath
abspath = pathv += object.pname
pathv = abspath + '/'
console.log('Starting to download the playlist named ', object.pname)
for(let i = 0; i<loops; i++){
console.log(abspath, pathv)
if(object.index[i]){
let link = object.index[i].url;
Downloader(pathv, link, fileformat, quality, choice, verify, abspath, sidechoices)
}
else{loops = loops - 1;
console.error('Unable to proceed to download media number \u001b[31m', (loops + 1))}
lobby()
}
});
}
else if(verify === 1){
if(fileformat === '.mkv') {pathv = './Output/MKV/'}
else if(fileformat === '.aac') {pathv = './Output/AAC/'}
else if(fileformat === '.flac') {pathv = './Output/FLAC/'}
else if(fileformat === '.wav') {pathv = './Output/WAV/'}
Downloader(pathv, link, fileformat, quality, choice, verify, path, sidechoices)
}
}
})
} else {
console.log('╭───────────────────────────────────────────────────────────────────────────╮');
console.log('│ |');
console.log('│ 🌐 ❌ CONNECTION ERROR: NO HOST INTERNET INTEGRITY! ❌ 🌐 │');
console.log('│ |');
console.log('│ Please make sure to be connected to │');
console.log('│ internet or try again later. |');
console.log('│ |');
console.log('╰───────────────────────────────────────────────────────────────────────────╯');
}
});
function phase1(link){
console.log('──────────────────────────────────────────────────────────────────╮');
console.log(' Insert the media link that you want to download │');
console.log('──────────────────────────────────────────────────────────────────╯');
link = prompt(':> ');
console.log('\n')
return link}
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}