-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
42 lines (29 loc) · 1.08 KB
/
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
const fetch = require('node-fetch');
const getClientId = require('./get-client-id');
const getPlaylistInfo = require('./get-playlist-info');
const downloadTrack = require('./download-track');
const run = async () => {
const initialResponse = await fetch(process.argv[2]);
const html = await initialResponse.text();
const clientId = await getClientId(html);
const playlistInfo = await getPlaylistInfo({ html, clientId });
const trackIds = playlistInfo.tracks.map(({ id }) => id);
const tracksParam = trackIds.join('%2C');
const idToNumberMap = playlistInfo.tracks.reduce((acc, track, index) => {
acc[track.id] = index + 1;
return acc;
}, {});
const url = `https://api-v2.soundcloud.com/tracks?ids=${tracksParam}&client_id=${clientId}`;
const trackInfoResponse = await fetch(url);
const trackInfo = await trackInfoResponse.json();
trackInfo.forEach((track) => {
downloadTrack({
clientId,
track,
playlistName: playlistInfo.title,
artworkUrl: playlistInfo.artworkUrl,
trackNumber: idToNumberMap[track.id],
});
})
};
run();