diff --git a/plugins/Last.fm/src/constants.ts b/plugins/Last.fm/src/constants.ts index 7ed101e..7c7ba35 100644 --- a/plugins/Last.fm/src/constants.ts +++ b/plugins/Last.fm/src/constants.ts @@ -5,7 +5,7 @@ const Constants = { /** Last.fm api key */ LFM_API_KEY: "615322f0047e12aedbc610d9d71f7430", /** These are the default album covers that are used by Last.fm */ - DEFAULT_COVER_HASHES: [ + LFM_DEFAULT_COVER_HASHES: [ "2a96cbd8b46e442fc41c2b86b821562f", "c6f59c1e5e7240a4c0d427abd71f3dbb", ] diff --git a/plugins/Last.fm/src/types.ts b/plugins/Last.fm/src/types.ts index 83cd605..aff6d5d 100644 --- a/plugins/Last.fm/src/types.ts +++ b/plugins/Last.fm/src/types.ts @@ -42,7 +42,7 @@ type ResultActivity = { // The assets of the activity type ActivityAssets = { - large_image: string; + large_image?: string; large_text?: string; } | { small_image: string; diff --git a/plugins/Last.fm/src/utils.ts b/plugins/Last.fm/src/utils.ts index 87b9214..23de96e 100644 --- a/plugins/Last.fm/src/utils.ts +++ b/plugins/Last.fm/src/utils.ts @@ -16,7 +16,10 @@ async function fetchLatestScrobble(): Promise { 'extended': '1' }).toString(); - const info = await fetch(`https://ws.audioscrobbler.com/2.0/?${params}`).then(x => x.json()); + const info = await fetch(`https://ws.audioscrobbler.com/2.0/?${params}`).then(x => { + if (!x.ok) throw new Error(`Failed to fetch latest scrobble: ${x.status} ${x.statusText}`); + return x.json(); + }); const lastTrack = info.recenttracks?.track?.[0] || Promise.reject(info); return { name: lastTrack.name, @@ -30,12 +33,13 @@ async function fetchLatestScrobble(): Promise { } as Track; } -/** Currently ditches the default album covers +/** + * Currently ditches the default album covers * @param cover The album cover given by Last.fm */ function handleAlbumCover(cover: string): string { - // If the cover is a default one, return null (empty) - if (Constants.DEFAULT_COVER_HASHES.some(x => cover.includes(x))) { + // If the cover is a default one, return null (remove the cover) + if (Constants.LFM_DEFAULT_COVER_HASHES.some(x => cover.includes(x))) { return null; } return cover; @@ -98,7 +102,7 @@ export async function update() { return await clearActivity(); } - verboseLog("--> Setting activity..."); + verboseLog("--> Track fetched! Setting activity..."); if (global.lastTrackUrl === lastTrack.url) { verboseLog("--> Last track is the same as the previous one, aborting..."); @@ -121,10 +125,10 @@ export async function update() { }; } - if (lastTrack.albumArt) { + if (lastTrack.album) { activity.assets = { large_image: lastTrack.albumArt, - large_text: `on ${lastTrack.album}`, + large_text: `on ${lastTrack.album}` } }