fix(metadata): direct parsing of tempo and key_of from GetSongBPM API search response
This commit is contained in:
1 parent
c800429318
commit
b782ae5685
1 file changed
+10
-12
+10
-12
@@ -72,18 +72,16 @@ router.get('/', async (req, res) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const searchResults = gsbRes.data && gsbRes.data.search;
|
const searchResults = gsbRes.data && gsbRes.data.search;
|
||||||
if (searchResults && searchResults.length > 0) {
|
if (Array.isArray(searchResults) && searchResults.length > 0) {
|
||||||
const songId = searchResults[0].song_id;
|
const song = searchResults[0];
|
||||||
if (songId) {
|
if (song.tempo) {
|
||||||
const songRes = await axios.get('https://api.getsong.co/song/', {
|
bpm = parseFloat(song.tempo);
|
||||||
params: { api_key: process.env.GETSONGBPM_API_KEY, id: songId },
|
}
|
||||||
timeout: 4000
|
if (song.key_of) {
|
||||||
});
|
camelotKey = standardizeKey(song.key_of);
|
||||||
if (songRes.data && songRes.data.song) {
|
}
|
||||||
bpm = songRes.data.song.tempo;
|
if (song.artist && song.artist.genres && tags.length === 0) {
|
||||||
const keyStr = songRes.data.song.key_of;
|
tags = song.artist.genres.slice(0, 4);
|
||||||
camelotKey = standardizeKey(keyStr);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|||||||
Reference in new issue
Block a user