diff --git a/src/components/music/SongList.tsx b/src/components/music/SongList.tsx index aed51f8..db45191 100644 --- a/src/components/music/SongList.tsx +++ b/src/components/music/SongList.tsx @@ -1,20 +1,50 @@ 'use client'; +import { useState } from 'react'; import { addMusicSongToPlaylist, playMusicLater, playMusicSong } from '@/lib/music/actions'; import { SourcePill } from '@/lib/music/shared'; import type { Song } from '@/lib/music/types'; +function SongCover({ song }: { song: Song }) { + const [failed, setFailed] = useState(false); + const cover = song.pic && !failed ? song.pic : ''; + + return ( +
+ {cover ? ( + {`${song.name} setFailed(true)} + className="h-full w-full object-cover" + /> + ) : ( +
+ + + +
+ )} +
+ ); +} + export default function SongList({ songs }: { songs: Song[] }) { return (
{songs.map((song, index) => (
playMusicSong(song, index)}> {index + 1}
+
playMusicSong(song, index)}> + +
playMusicSong(song, index)}>
{song.name}
{song.artist}
diff --git a/src/lib/music-v2.ts b/src/lib/music-v2.ts index fc91f17..399301f 100644 --- a/src/lib/music-v2.ts +++ b/src/lib/music-v2.ts @@ -91,7 +91,23 @@ export interface LxServerSong { interval?: string; albumName?: string; img?: string; + image?: string; + imageUrl?: string; + albumPicUrl?: string; + pic?: string; + cover?: string; songmid?: string; + meta?: { + picUrl?: string; + albumName?: string; + }; + album?: { + picUrl?: string; + pic?: string; + }; + al?: { + picUrl?: string; + }; } export function isMusicSource(source: string | null | undefined): source is MusicSource { @@ -163,8 +179,18 @@ export function normalizeLxSong(song: LxServerSong): MusicV2Song { songmid: song.songmid, name: song.name, artist: song.singer, - album: song.albumName, - cover: song.img, + album: song.albumName || song.meta?.albumName, + cover: + song.img || + song.pic || + song.cover || + song.image || + song.imageUrl || + song.albumPicUrl || + song.meta?.picUrl || + song.album?.picUrl || + song.album?.pic || + song.al?.picUrl, durationText: song.interval, }); } diff --git a/src/lib/music/shared.ts b/src/lib/music/shared.ts index 3bdb10c..c615bd8 100644 --- a/src/lib/music/shared.ts +++ b/src/lib/music/shared.ts @@ -19,12 +19,24 @@ export function normalizeSource(source: string | undefined | null): MusicSource export function mapSong(song: any): Song { const rawSource = song.source || song.platform || song.vendor || song.origin; + const pic = + song.pic || + song.cover || + song.img || + song.image || + song.imageUrl || + song.albumPicUrl || + song.meta?.picUrl || + song.album?.picUrl || + song.album?.pic || + song.al?.picUrl; + return { id: String(song.id ?? song.songId ?? song.rid ?? song.mid ?? ''), name: song.name || song.title || '未知歌曲', artist: song.artist || song.singer || song.artists || '未知艺术家', album: song.album || song.albumName, - pic: song.pic || song.cover || song.img, + pic, platform: normalizeSource(rawSource), duration: song.durationSec || song.duration, durationText: song.durationText || song.interval,