UNPKG

@aaronlcj/use-last-fm

Version:

Get data from last.fm as a React hook.

30 lines 956 B
export function parseSong(body, imageSize) { var _a, _b, _c; if (!body) { return { status: 'connecting', song: null }; } var lastSong = (_a = body.recenttracks.track) === null || _a === void 0 ? void 0 : _a[0]; if (!lastSong || !((_b = lastSong['@attr']) === null || _b === void 0 ? void 0 : _b.nowplaying)) { return { status: 'idle', song: null }; } var image = lastSong.image.find(function (i) { return i.size === imageSize; }); return { status: 'playing', song: { name: lastSong.name, artist: lastSong.artist['#text'], art: (_c = image === null || image === void 0 ? void 0 : image['#text']) !== null && _c !== void 0 ? _c : lastSong.image[0]['#text'], url: lastSong.url, album: lastSong.album['#text'] } }; } //# sourceMappingURL=lib.js.map