better error handling and placeholder plays
This commit is contained in:
parent
94f1a8097a
commit
2926d0e468
10
main.js
10
main.js
|
@ -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