better error handling and placeholder plays
This commit is contained in:
parent
94f1a8097a
commit
2926d0e468
14
main.js
14
main.js
|
@ -62,8 +62,8 @@ async function updateStatus() {
|
||||||
state: `${data.artist} - ${data.album}`,
|
state: `${data.artist} - ${data.album}`,
|
||||||
buttons: [
|
buttons: [
|
||||||
{
|
{
|
||||||
label: `${formatNumber(data.scrobbles)} ${config.label}`,
|
label: `${formatNumber(data.scrobbles)} ${config.label}`,
|
||||||
url: JSON.parse(config.clickable) ? `https://www.last.fm/user/${config.username}/` : "javascript:void(0);"
|
url: JSON.parse(config.clickable) ? `https://www.last.fm/user/${config.username}/` : "javascript:void(0);"
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
@ -118,9 +118,11 @@ async function fetchCurrentScrobble(user) {
|
||||||
|
|
||||||
const rData = await fetch(options);
|
const rData = await fetch(options);
|
||||||
|
|
||||||
if (!rData.track) {
|
let playcount = "0";
|
||||||
console.error("No track data in track.getInfo for track: " + lastTrackName + " by artist: " + lastArtist);
|
if (rData.track && rData.track.userplaycount) {
|
||||||
return null;
|
playcount = rData.track.userplaycount;
|
||||||
|
} else {
|
||||||
|
console.warn("No track data in track.getInfo for track: " + lastTrackName + " by artist: " + lastArtist);
|
||||||
}
|
}
|
||||||
|
|
||||||
let images = lastTrack.recenttracks.track[0].image;
|
let images = lastTrack.recenttracks.track[0].image;
|
||||||
|
@ -130,7 +132,7 @@ async function fetchCurrentScrobble(user) {
|
||||||
artist: lastArtist,
|
artist: lastArtist,
|
||||||
album: lastTrack.recenttracks.track[0].album["#text"] || "Unknown Album",
|
album: lastTrack.recenttracks.track[0].album["#text"] || "Unknown Album",
|
||||||
trackName: lastTrackName,
|
trackName: lastTrackName,
|
||||||
playcount: rData.track.userplaycount ? rData.track.userplaycount : "0",
|
playcount: playcount,
|
||||||
scrobbles: lastTrack.recenttracks["@attr"].total,
|
scrobbles: lastTrack.recenttracks["@attr"].total,
|
||||||
whenScrobbled: lastTrack.recenttracks.track[0]["@attr"],
|
whenScrobbled: lastTrack.recenttracks.track[0]["@attr"],
|
||||||
scrobbleStatus: !lastTrack.recenttracks.track[0]["@attr"] ? `Last scrobbled ${prettyMilliseconds(Date.now() - lastTrack.recenttracks.track[0].date.uts * 1000)} ago.` : "Now scrobbling.",
|
scrobbleStatus: !lastTrack.recenttracks.track[0]["@attr"] ? `Last scrobbled ${prettyMilliseconds(Date.now() - lastTrack.recenttracks.track[0].date.uts * 1000)} ago.` : "Now scrobbling.",
|
||||||
|
|
Loading…
Reference in New Issue