a2s.su/pages/js/lastfm-nowplay.js

33 lines
1.2 KiB
JavaScript
Raw Normal View History

2023-08-03 23:39:02 +03:00
export function update_lastfm_nowplay() {
let user = 'Alex_Popov';
let apikey = '5556942dcf4c422dca68d57fbbfdee23';
2023-08-06 03:58:35 +03:00
let url = `https://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user=${user}&api_key=${apikey}&format=json&limit=1`;
2023-08-03 23:39:02 +03:00
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
*/