feat(lastfm): add album image

This commit is contained in:
FoxxMD 2026-09-30 14:11:55 +00:00
parent e7ee6d57ad
commit 2d05af0eb4

View file

@ -746,6 +746,7 @@ export const formatPlayObj = (obj: LastFMTrackObject, options: FormatPlayObjectO
mbid: artistMbid,
},
name: title,
image,
album: {
'#text': album,
mbid: albumMbid,
@ -792,6 +793,27 @@ export const formatPlayObj = (obj: LastFMTrackObject, options: FormatPlayObjectO
}
}
if(brainz !== undefined && !objectIsEmpty(brainz)) {
play.data.meta = {
brainz
}
}
const i = image ?? [];
let imageSizeNum: number = 0;
let imageUrl: string | undefined = undefined;
if(i !== undefined && i !== null && i.length > 0) {
for(const im of i) {
const res = lastfmImageSize.safeParse(im.size);
if(res.success && lastfmImageSizeMap[res.data] > imageSizeNum) {
imageSizeNum = lastfmImageSizeMap[res.data];
imageUrl = im["#text"];
}
}
}
if(imageUrl !== undefined) {
play.album.image = imageUrl;
}
return baseFormatPlayObj(obj, play);
}
@ -828,6 +850,15 @@ type LastFMTrackScrobbleResponse = Readonly<{
};
}>;
const lastfmImageSize = z.enum(['small','medium','large','extralarge']);
type LastFmImageSizes = z.infer<typeof lastfmImageSize>;
const lastfmImageSizeMap: Record<LastFmImageSizes, number> = {
small: 1,
medium: 2,
large: 3,
extralarge: 4
} as const;
export type LastFMTrackObject = {
artist: {
mbid?: string;