chore: improve musicbrainz links

This commit is contained in:
Cory Dransfeldt 2023-11-12 14:48:44 -08:00
parent 336ab14981
commit 23a0aec76a
3 changed files with 11 additions and 3 deletions

View file

@ -123,6 +123,12 @@ export default async () => {
const track = trackData['recenttracks']['track'][0]
const mbid = track['artist']['mbid']
let genre = ''
const artistUrl = mbid
? `https://musicbrainz.org/artist/${mbid}`
: `https://musicbrainz.org/search?query=${track['artist']['#text'].replace(
/\s+/g,
'+'
)}&type=artist`
if (mbid && mbid !== '') {
const genreUrl = `https://musicbrainz.org/ws/2/artist/${mbid}?inc=aliases+genres&fmt=json`
@ -136,7 +142,7 @@ export default async () => {
return Response.json({
content: `${emojiMap(genre, track['artist']['#text'])} <a href="${track['url']}">${
track['name']
} by ${track['artist']['#text']}</a>`,
}</a> by <a href="${artistUrl}">${track['artist']['#text']}</a>`,
})
}

View file

@ -25,7 +25,9 @@ module.exports = async function () {
.toLowerCase()}.jpg`,
url: album['mbid']
? `https://musicbrainz.org/album/${album['mbid']}`
: `https://musicbrainz.org/search?query=${encodeURI(album['name'])}&type=release_group`,
: `https://musicbrainz.org/taglookup/index?tag-lookup.artist=${album['artist'][
'name'
].replace(/\s+/g, '+')}&tag-lookup.release=${album['name'].replace(/\s+/g, '+')}`,
type: 'album',
}
})

View file

@ -18,7 +18,7 @@ module.exports = async function () {
'https://cdn.coryd.dev/artists/missing-artist.jpg',
url: artist['mbid']
? `https://musicbrainz.org/artist/${artist['mbid']}`
: `https://musicbrainz.org/search?query=${encodeURI(artist['name'])}&type=artist`,
: `https://musicbrainz.org/search?query=${artist['name'].replace(/\s+/g, '+')}&type=artist`,
type: 'artist',
}
})