-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdeezer.js
31 lines (28 loc) · 880 Bytes
/
deezer.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
const _ = require('lodash');
const fetch = require('node-fetch');
function simplifyAlbumInfos(infos) {
return {
id: infos.id,
title: infos.title,
upc: infos.upc,
cover: infos.cover_big,
releaseDate: infos.release_date,
tracks: infos.tracks
? infos.tracks.data
.filter(track => track.readable && track.preview)
.map(track => _.pick(track, 'title', 'preview'))
: [],
};
}
async function fetchFromDeezer(eans) {
const albumInfos = [];
for (const ean of eans) {
const response = await fetch(`https://api.deezer.com/album/upc:${ean}`);
const infos = await response.json();
if (!infos.errors) {
albumInfos.push(simplifyAlbumInfos(infos));
}
}
return albumInfos;
}
exports.fetchFromDeezer = fetchFromDeezer;