33 lines
1.2 KiB
JavaScript
33 lines
1.2 KiB
JavaScript
|
export function update_lastfm_nowplay() {
|
|||
|
let user = 'Alex_Popov';
|
|||
|
let apikey = '5556942dcf4c422dca68d57fbbfdee23';
|
|||
|
let url = `http://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user=${user}&api_key=${apikey}&format=json&limit=1`;
|
|||
|
|
|||
|
let status_text = document.getElementById('lastfm_card_title');
|
|||
|
let song_text = document.getElementById('lastfm_card_content');
|
|||
|
let desc_text = document.getElementById('lastfm_card_footer');
|
|||
|
|
|||
|
fetch(url)
|
|||
|
.then((response) => response.json())
|
|||
|
.then((data) => {
|
|||
|
// update desc
|
|||
|
let desc_string = `Всего прослушано ${data.recenttracks['@attr'].total} треков`;
|
|||
|
desc_text.innerText = desc_string;
|
|||
|
|
|||
|
// update content
|
|||
|
let track_string = `${data.recenttracks.track[0].artist['#text']} — ${data.recenttracks.track[0].name}`;
|
|||
|
song_text.innerText = track_string;
|
|||
|
|
|||
|
// TODO: get play now
|
|||
|
status_text.innerText = 'Последняя проигранная композиция';
|
|||
|
})
|
|||
|
.catch((err) => console.warn('Something went wrong.', err));
|
|||
|
}
|
|||
|
|
|||
|
/*
|
|||
|
Application name a2s
|
|||
|
API key 5556942dcf4c422dca68d57fbbfdee23
|
|||
|
Shared secret e1e1baa61478c5745c35b985ed2a49a9
|
|||
|
Registered to Alex_Popov
|
|||
|
*/
|