diff --git a/src/routes/subsonic.js b/src/routes/subsonic.js index 15d2747..578b500 100644 --- a/src/routes/subsonic.js +++ b/src/routes/subsonic.js @@ -568,6 +568,32 @@ router.get('/getCoverArt.view', authenticateSubsonic, async (req, res) => { } }); +// Get genres +router.get('/getGenres.view', authenticateSubsonic, async (req, res) => { + try { + const genres = await all(` + SELECT DISTINCT genre, COUNT(*) as song_count, COUNT(DISTINCT album) as album_count + FROM tracks + WHERE genre IS NOT NULL AND genre != '' + GROUP BY genre + ORDER BY genre + `); + + let genresXml = '\n'; + + genres.forEach(genre => { + genresXml += ` ${escapeXml(genre.genre)}\n`; + }); + + genresXml += ''; + + sendSubsonicResponse(res, genresXml); + } catch (error) { + console.error('Error in getGenres:', error); + sendSubsonicError(res, 0, error.message); + } +}); + // Get playlists router.get('/getPlaylists.view', authenticateSubsonic, async (req, res) => { try {