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-05 11:29:49 +00:00
|
|
|
/**
|
|
|
|
* Get extra song information (lyrics, artist info, album info).
|
|
|
|
*
|
|
|
|
* @param {Object} song
|
|
|
|
* @param {?Function} cb
|
|
|
|
*/
|
|
|
|
fetch(song, cb = null) {
|
|
|
|
// Check if the song's info has been retrieved before.
|
|
|
|
if (song.infoRetrieved) {
|
|
|
|
cb && cb();
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
http.get(`${song.id}/info`, response => {
|
|
|
|
const data = response.data;
|
|
|
|
|
|
|
|
song.lyrics = data.lyrics;
|
|
|
|
|
2016-06-25 08:24:56 +00:00
|
|
|
data.artist_info && artistInfo.merge(song.artist, data.artist_info);
|
2016-06-05 11:29:49 +00:00
|
|
|
data.album_info && albumInfo.merge(song.album, data.album_info);
|
|
|
|
|
|
|
|
song.infoRetrieved = true;
|
|
|
|
|
|
|
|
cb && cb();
|
|
|
|
});
|
|
|
|
},
|
|
|
|
};
|