From 48bfa048a0c83d9774ef99a105ad89d51b64597c Mon Sep 17 00:00:00 2001 From: Paul Bailey Date: Sun, 7 Dec 2025 23:27:19 +0000 Subject: [PATCH] Fix getCoverArt to properly lookup artwork by album ID --- src/routes/subsonic.js | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/routes/subsonic.js b/src/routes/subsonic.js index 578b500..d76023e 100644 --- a/src/routes/subsonic.js +++ b/src/routes/subsonic.js @@ -554,8 +554,26 @@ router.get('/getCoverArt.view', authenticateSubsonic, async (req, res) => { try { const { id } = req.query; - // Try to find artwork by album ID or track ID - const track = await get('SELECT artwork_path FROM tracks WHERE id = ? OR id IN (SELECT id FROM tracks LIMIT 1)', [id]); + // First try to find by track ID + let track = await get('SELECT artwork_path FROM tracks WHERE id = ?', [id]); + + // If not found, the ID might be an album ID - decode it and find a track from that album + if (!track) { + // Try to find which album this ID represents + const allAlbums = await all(`SELECT DISTINCT album, album_artist FROM tracks`); + + for (const album of allAlbums) { + const albumId = crypto.createHash('md5').update(`album-${album.album}-${album.album_artist}`).digest('hex'); + if (albumId === id) { + // Found the album, get artwork from any track in this album + track = await get( + 'SELECT artwork_path FROM tracks WHERE album = ? AND album_artist = ? AND artwork_path IS NOT NULL LIMIT 1', + [album.album, album.album_artist] + ); + break; + } + } + } if (!track || !track.artwork_path) { return res.status(404).send('Cover art not found'); @@ -564,6 +582,7 @@ router.get('/getCoverArt.view', authenticateSubsonic, async (req, res) => { const artworkPath = `${process.cwd()}/artwork/${track.artwork_path}`; res.sendFile(artworkPath); } catch (error) { + console.error('Error in getCoverArt:', error); res.status(404).send('Cover art not found'); } });