diff --git a/src/routes/subsonic.js b/src/routes/subsonic.js index 6f1c407..974bf4e 100644 --- a/src/routes/subsonic.js +++ b/src/routes/subsonic.js @@ -137,22 +137,25 @@ router.get('/getMusicDirectory.view', authenticateSubsonic, async (req, res) => if (targetArtist) { const albums = await all(` SELECT DISTINCT album, album_artist, year, - (SELECT artwork_path FROM tracks t2 WHERE t2.album = tracks.album AND t2.artist = ? LIMIT 1) as artwork_path, - COUNT(*) as track_count + (SELECT artwork_path FROM tracks t2 WHERE t2.album = tracks.album AND t2.artist = ? LIMIT 1) as artwork_path FROM tracks WHERE artist = ? GROUP BY album, album_artist ORDER BY year DESC, album `, [targetArtist, targetArtist]); - let dirXml = `\n`; + const artistIdForParent = crypto.createHash('md5').update(`artist-${targetArtist}`).digest('hex'); + let dirXml = `\n`; albums.forEach(album => { const albumId = crypto.createHash('md5').update(`album-${album.album}-${album.album_artist}`).digest('hex'); const coverArt = album.artwork_path ? albumId : ''; - dirXml += ` \n`; + dirXml += ` \n`; }); dirXml += ''; @@ -184,11 +187,16 @@ router.get('/getMusicDirectory.view', authenticateSubsonic, async (req, res) => return sendSubsonicError(res, 70, 'Album not found'); } + // Find the parent artist ID const firstTrack = tracks[0]; - let dirXml = `\n`; + const parentArtistId = crypto.createHash('md5').update(`artist-${firstTrack.artist}`).digest('hex'); + + let dirXml = `\n`; tracks.forEach(track => { - dirXml += buildSongXml(track, req); + const songXml = buildSongXml(track, req); + // Replace the closing /> with isDir="false" /> + dirXml += songXml.replace('type="music"/>', 'type="music" isDir="false"/>'); }); dirXml += '';