mirror of
https://github.com/FoxxMD/multi-scrobbler.git
synced 2026-10-19 15:26:33 +00:00
feat(lastfm): add album image
This commit is contained in:
parent
e7ee6d57ad
commit
2d05af0eb4
1 changed files with 31 additions and 0 deletions
31
src/backend/common/vendor/LastfmApiClient.ts
vendored
31
src/backend/common/vendor/LastfmApiClient.ts
vendored
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue