Add artist artwork support using album covers from their tracks
This commit is contained in:
@@ -213,7 +213,8 @@ router.get('/getMusicDirectory.view', authenticateSubsonic, async (req, res) =>
|
|||||||
router.get('/getArtists.view', authenticateSubsonic, async (req, res) => {
|
router.get('/getArtists.view', authenticateSubsonic, async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const artists = await all(`
|
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
|
FROM tracks
|
||||||
GROUP BY artist
|
GROUP BY artist
|
||||||
ORDER BY artist
|
ORDER BY artist
|
||||||
@@ -230,7 +231,8 @@ router.get('/getArtists.view', authenticateSubsonic, async (req, res) => {
|
|||||||
grouped[letter].push({
|
grouped[letter].push({
|
||||||
id: artistId,
|
id: artistId,
|
||||||
name: artist.artist,
|
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 => {
|
Object.keys(grouped).sort().forEach(letter => {
|
||||||
artistsXml += ` <index name="${letter}">\n`;
|
artistsXml += ` <index name="${letter}">\n`;
|
||||||
grouped[letter].forEach(artist => {
|
grouped[letter].forEach(artist => {
|
||||||
artistsXml += ` <artist id="${artist.id}" name="${escapeXml(artist.name)}" albumCount="${artist.albumCount}"/>\n`;
|
artistsXml += ` <artist id="${artist.id}" name="${escapeXml(artist.name)}" `;
|
||||||
|
artistsXml += `albumCount="${artist.albumCount}" `;
|
||||||
|
if (artist.coverArt) {
|
||||||
|
artistsXml += `coverArt="${artist.coverArt}" `;
|
||||||
|
}
|
||||||
|
artistsXml += `/>\n`;
|
||||||
});
|
});
|
||||||
artistsXml += ` </index>\n`;
|
artistsXml += ` </index>\n`;
|
||||||
});
|
});
|
||||||
@@ -568,9 +575,25 @@ router.get('/getCoverArt.view', authenticateSubsonic, async (req, res) => {
|
|||||||
// First try to find by track ID
|
// First try to find by track ID
|
||||||
let track = await get('SELECT artwork_path FROM tracks WHERE id = ?', [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) {
|
if (!track) {
|
||||||
// Try to find which album this ID represents
|
|
||||||
const allAlbums = await all(`SELECT DISTINCT album, album_artist FROM tracks`);
|
const allAlbums = await all(`SELECT DISTINCT album, album_artist FROM tracks`);
|
||||||
|
|
||||||
for (const album of allAlbums) {
|
for (const album of allAlbums) {
|
||||||
|
|||||||
Reference in New Issue
Block a user