Add getGenres endpoint
This commit is contained in:
@@ -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 = '<genres>\n';
|
||||||
|
|
||||||
|
genres.forEach(genre => {
|
||||||
|
genresXml += ` <genre songCount="${genre.song_count}" albumCount="${genre.album_count}">${escapeXml(genre.genre)}</genre>\n`;
|
||||||
|
});
|
||||||
|
|
||||||
|
genresXml += '</genres>';
|
||||||
|
|
||||||
|
sendSubsonicResponse(res, genresXml);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error in getGenres:', error);
|
||||||
|
sendSubsonicError(res, 0, error.message);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// Get playlists
|
// Get playlists
|
||||||
router.get('/getPlaylists.view', authenticateSubsonic, async (req, res) => {
|
router.get('/getPlaylists.view', authenticateSubsonic, async (req, res) => {
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user