Last.fm: always show album name
This commit is contained in:
parent
c86e190274
commit
b6d46a160a
3 changed files with 13 additions and 9 deletions
|
|
@ -5,7 +5,7 @@ const Constants = {
|
||||||
/** Last.fm api key */
|
/** Last.fm api key */
|
||||||
LFM_API_KEY: "615322f0047e12aedbc610d9d71f7430",
|
LFM_API_KEY: "615322f0047e12aedbc610d9d71f7430",
|
||||||
/** These are the default album covers that are used by Last.fm */
|
/** These are the default album covers that are used by Last.fm */
|
||||||
DEFAULT_COVER_HASHES: [
|
LFM_DEFAULT_COVER_HASHES: [
|
||||||
"2a96cbd8b46e442fc41c2b86b821562f",
|
"2a96cbd8b46e442fc41c2b86b821562f",
|
||||||
"c6f59c1e5e7240a4c0d427abd71f3dbb",
|
"c6f59c1e5e7240a4c0d427abd71f3dbb",
|
||||||
]
|
]
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@ type ResultActivity = {
|
||||||
|
|
||||||
// The assets of the activity
|
// The assets of the activity
|
||||||
type ActivityAssets = {
|
type ActivityAssets = {
|
||||||
large_image: string;
|
large_image?: string;
|
||||||
large_text?: string;
|
large_text?: string;
|
||||||
} | {
|
} | {
|
||||||
small_image: string;
|
small_image: string;
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,10 @@ async function fetchLatestScrobble(): Promise<Track> {
|
||||||
'extended': '1'
|
'extended': '1'
|
||||||
}).toString();
|
}).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);
|
const lastTrack = info.recenttracks?.track?.[0] || Promise.reject(info);
|
||||||
return {
|
return {
|
||||||
name: lastTrack.name,
|
name: lastTrack.name,
|
||||||
|
|
@ -30,12 +33,13 @@ async function fetchLatestScrobble(): Promise<Track> {
|
||||||
} as Track;
|
} as Track;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Currently ditches the default album covers
|
/**
|
||||||
|
* Currently ditches the default album covers
|
||||||
* @param cover The album cover given by Last.fm
|
* @param cover The album cover given by Last.fm
|
||||||
*/
|
*/
|
||||||
function handleAlbumCover(cover: string): string {
|
function handleAlbumCover(cover: string): string {
|
||||||
// If the cover is a default one, return null (empty)
|
// If the cover is a default one, return null (remove the cover)
|
||||||
if (Constants.DEFAULT_COVER_HASHES.some(x => cover.includes(x))) {
|
if (Constants.LFM_DEFAULT_COVER_HASHES.some(x => cover.includes(x))) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return cover;
|
return cover;
|
||||||
|
|
@ -98,7 +102,7 @@ export async function update() {
|
||||||
return await clearActivity();
|
return await clearActivity();
|
||||||
}
|
}
|
||||||
|
|
||||||
verboseLog("--> Setting activity...");
|
verboseLog("--> Track fetched! Setting activity...");
|
||||||
|
|
||||||
if (global.lastTrackUrl === lastTrack.url) {
|
if (global.lastTrackUrl === lastTrack.url) {
|
||||||
verboseLog("--> Last track is the same as the previous one, aborting...");
|
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 = {
|
activity.assets = {
|
||||||
large_image: lastTrack.albumArt,
|
large_image: lastTrack.albumArt,
|
||||||
large_text: `on ${lastTrack.album}`,
|
large_text: `on ${lastTrack.album}`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue