fix: only look up a genre if we get an mbid
This commit is contained in:
parent
53948158b9
commit
33bff672cf
1 changed files with 11 additions and 6 deletions
|
@ -42,12 +42,17 @@ export default async () => {
|
||||||
}).catch()
|
}).catch()
|
||||||
const trackData = await trackRes.json()
|
const trackData = await trackRes.json()
|
||||||
const track = trackData['recenttracks']['track'][0]
|
const track = trackData['recenttracks']['track'][0]
|
||||||
const genreUrl = `https://musicbrainz.org/ws/2/artist/${track['artist']['mbid']}?inc=aliases+genres&fmt=json`
|
const mbid = track['artist']['mbid']
|
||||||
const genreRes = await fetch(genreUrl, {
|
let genre = ''
|
||||||
type: 'json',
|
|
||||||
}).catch()
|
if (mbid && mbid !== '') {
|
||||||
const genreData = await genreRes.json()
|
const genreUrl = `https://musicbrainz.org/ws/2/artist/${mbid}?inc=aliases+genres&fmt=json`
|
||||||
const genre = genreData.genres.sort((a, b) => b.count - a.count)[0]['name']
|
const genreRes = await fetch(genreUrl, {
|
||||||
|
type: 'json',
|
||||||
|
}).catch()
|
||||||
|
const genreData = await genreRes.json()
|
||||||
|
genre = genreData.genres.sort((a, b) => b.count - a.count)[0]['name']
|
||||||
|
}
|
||||||
|
|
||||||
return Response.json({
|
return Response.json({
|
||||||
artist: track['artist']['#text'],
|
artist: track['artist']['#text'],
|
||||||
|
|
Reference in a new issue