-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
28 lines (25 loc) · 843 Bytes
/
index.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
const axios = require("axios");
const cheerio = require('cheerio');
const { urls, _config } = require('./config.js')
var https = require('https');
var fs = require('fs');
async function getTrackData(url) {
const response = await axios(url)
return response.data
}
urls.forEach(async (url, i) => {
const data = await getTrackData(url)
let $ = cheerio.load(data, _config)
let dataTrack = JSON.parse($('script').toArray()[5].attribs['data-tralbum']).trackinfo[0];
const { title, file } = dataTrack
download(file['mp3-128'], `./downloads/${title}.mp3`, function () {});
})
var download = function (url, dest, cb) {
var file = fs.createWriteStream(dest);
https.get(url, function (response) {
response.pipe(file);
file.on('finish', function () {
file.close(cb);
});
});
}