2016-06-25 10:15:57 +00:00
|
|
|
import { http, albumInfo, artistInfo } from '..';
|
2016-06-05 11:29:49 +00:00
|
|
|
|
2016-06-25 10:15:57 +00:00
|
|
|
export const songInfo = {
|
2016-06-25 16:05:24 +00:00
|
|
|
/**
|
|
|
|
* Get extra song information (lyrics, artist info, album info).
|
|
|
|
*
|
|
|
|
* @param {Object} song
|
|
|
|
*/
|
2016-06-27 06:11:35 +00:00
|
|
|
fetch(song) {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
// Check if the song's info has been retrieved before.
|
|
|
|
if (song.infoRetrieved) {
|
|
|
|
resolve(song);
|
|
|
|
return;
|
|
|
|
}
|
2016-06-05 11:29:49 +00:00
|
|
|
|
2016-06-27 06:11:35 +00:00
|
|
|
http.get(`${song.id}/info`, r => {
|
|
|
|
song.lyrics = r.data.lyrics;
|
|
|
|
r.data.artist_info && artistInfo.merge(song.artist, r.data.artist_info);
|
|
|
|
r.data.album_info && albumInfo.merge(song.album, r.data.album_info);
|
|
|
|
song.infoRetrieved = true;
|
|
|
|
resolve(song)
|
|
|
|
}, r => reject(r));
|
2016-06-25 16:05:24 +00:00
|
|
|
});
|
|
|
|
},
|
2016-06-05 11:29:49 +00:00
|
|
|
};
|