better error handling and placeholder plays

This commit is contained in:
Wizzard 2023-07-14 13:00:17 -04:00
parent 94f1a8097a
commit 2926d0e468
1 changed files with 9 additions and 7 deletions

10
main.js
View File

@ -118,9 +118,11 @@ async function fetchCurrentScrobble(user) {
const rData = await fetch(options);
if (!rData.track) {
console.error("No track data in track.getInfo for track: " + lastTrackName + " by artist: " + lastArtist);
return null;
let playcount = "0";
if (rData.track && rData.track.userplaycount) {
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;
@ -130,7 +132,7 @@ async function fetchCurrentScrobble(user) {
artist: lastArtist,
album: lastTrack.recenttracks.track[0].album["#text"] || "Unknown Album",
trackName: lastTrackName,
playcount: rData.track.userplaycount ? rData.track.userplaycount : "0",
playcount: playcount,
scrobbles: lastTrack.recenttracks["@attr"].total,
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.",