Skip to content

Commit 89b27d6

Browse files
committed
few checks
removed functions, better error handling
1 parent d0ca980 commit 89b27d6

File tree

1 file changed

+5
-17
lines changed

1 file changed

+5
-17
lines changed

cli.js

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -46,20 +46,6 @@ if (fallArg === '-f' || fallArg === '--fun') {
4646
process.exit(1);
4747
}
4848

49-
// Functions, because I'm planning to add few more features.
50-
51-
const detectFile = arg => {
52-
return arg.split(`twitter:player:stream:content_type" content="`)[1].split('">')[0].replace('/mp4', '');
53-
};
54-
55-
const detectMediaSource = arg => {
56-
return arg.split(`twitter:player:stream" content="`)[1].split('">')[0];
57-
};
58-
59-
const decodeMediaScript = source => {
60-
return source.replace(/amp;/g, '');
61-
};
62-
6349
const songName = arg => {
6450
return arg.split('/')[4];
6551
};
@@ -75,9 +61,9 @@ if (isURL(fallArg) === true) {
7561
spinner.start();
7662
got(fallArg).then(res => {
7763
const $ = res.body;
78-
const mediaType = detectFile($);
79-
const mediaSource = detectMediaSource($);
80-
const fetchMainSource = decodeMediaScript(mediaSource);
64+
const mediaType = $.split(`twitter:player:stream:content_type" content="`)[1].split('">')[0].replace('/mp4', '');
65+
const mediaSource = $.split(`twitter:player:stream" content="`)[1].split('">')[0];
66+
const fetchMainSource = mediaSource.replace(/amp;/g, '');
8167
logUpdate();
8268
spinner.text = chalk.dim('Fetching downloadable link');
8369

@@ -107,6 +93,8 @@ if (isURL(fallArg) === true) {
10793
});
10894
}).catch(err => {
10995
if (err) {
96+
logUpdate(`\n ${pre} ${chalk.dim('Broken link or maybe the song has been removed!')}\n`);
97+
spinner.stop();
11098
process.exit(1);
11199
}
112100
});

0 commit comments

Comments
 (0)