diff --git a/src/routes/subsonic.js b/src/routes/subsonic.js index 7c50d9c..1881266 100644 --- a/src/routes/subsonic.js +++ b/src/routes/subsonic.js @@ -213,7 +213,8 @@ router.get('/getMusicDirectory.view', authenticateSubsonic, async (req, res) => router.get('/getArtists.view', authenticateSubsonic, async (req, res) => { try { const artists = await all(` - SELECT DISTINCT artist, COUNT(DISTINCT album) as album_count + SELECT DISTINCT artist, COUNT(DISTINCT album) as album_count, + (SELECT artwork_path FROM tracks t2 WHERE t2.artist = tracks.artist AND artwork_path IS NOT NULL LIMIT 1) as artwork_path FROM tracks GROUP BY artist ORDER BY artist @@ -230,7 +231,8 @@ router.get('/getArtists.view', authenticateSubsonic, async (req, res) => { grouped[letter].push({ id: artistId, name: artist.artist, - albumCount: artist.album_count + albumCount: artist.album_count, + coverArt: artist.artwork_path ? artistId : '' }); }); @@ -239,7 +241,12 @@ router.get('/getArtists.view', authenticateSubsonic, async (req, res) => { Object.keys(grouped).sort().forEach(letter => { artistsXml += ` \n`; grouped[letter].forEach(artist => { - artistsXml += ` \n`; + artistsXml += ` \n`; }); artistsXml += ` \n`; }); @@ -568,9 +575,25 @@ router.get('/getCoverArt.view', authenticateSubsonic, async (req, res) => { // 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 not found, try artist ID + if (!track) { + const allArtists = await all(`SELECT DISTINCT artist FROM tracks`); + + for (const artist of allArtists) { + const artistId = crypto.createHash('md5').update(`artist-${artist.artist}`).digest('hex'); + if (artistId === id) { + // Found the artist, get artwork from any of their tracks + track = await get( + 'SELECT artwork_path FROM tracks WHERE artist = ? AND artwork_path IS NOT NULL LIMIT 1', + [artist.artist] + ); + break; + } + } + } + + // If still not found, try album ID 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) {