Skip to content

Commit 10435b7

Browse files
committed
Define some logics on main entry
When users give the input, it will detects whether the given input is valid URL or a path to batch file.
1 parent c13aa89 commit 10435b7

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

index.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ function batchDownload(inputFile) {
279279

280280
outStream
281281
.on('finish', () => {
282-
console.log(`\n[DONE] Written successfully.\n`);
282+
console.log(`[DONE] Written successfully.\n`);
283283
downloadFiles.push(outFile);
284284

285285
// Return all downloaded audio files
@@ -305,5 +305,13 @@ function batchDownload(inputFile) {
305305
}
306306

307307
if (require.main === module) {
308-
batchDownload(argumentParser(process.argv.slice(2)));
308+
let input = argumentParser(process.argv.slice(2));
309+
try {
310+
// This will throw URIError if the input URL are invalid
311+
input = (new URL(input)).href; // Simple URL validation
312+
console.log('[INFO] URL input detected!');
313+
singleDownload(input);
314+
} catch (error) {
315+
batchDownload(input);
316+
}
309317
}

0 commit comments

Comments
 (0)