feat: music from last.fm
This commit is contained in:
parent
03bb2e1016
commit
7472eb6285
13 changed files with 125 additions and 188 deletions
32
src/_data/albums.js
Normal file
32
src/_data/albums.js
Normal file
|
@ -0,0 +1,32 @@
|
|||
const EleventyFetch = require('@11ty/eleventy-fetch')
|
||||
const ALBUM_DENYLIST = ['no-love-deep-web', 'unremittance']
|
||||
|
||||
module.exports = async function () {
|
||||
const MUSIC_KEY = process.env.API_KEY_LASTFM
|
||||
const url = `https://ws.audioscrobbler.com/2.0/?method=user.gettopalbums&user=coryd_&api_key=${MUSIC_KEY}&limit=8&format=json&period=7day`
|
||||
const res = EleventyFetch(url, {
|
||||
duration: '1h',
|
||||
type: 'json',
|
||||
}).catch()
|
||||
const data = await res
|
||||
return data['topalbums']['album'].map((album) => {
|
||||
return {
|
||||
title: album['name'],
|
||||
artist: album['artist']['name'],
|
||||
plays: album['playcount'],
|
||||
rank: album['@attr']['rank'],
|
||||
image: !ALBUM_DENYLIST.includes(album['name'].replace(/\s+/g, '-').toLowerCase())
|
||||
? album['image'][album['image'].length - 1]['#text'].replace(
|
||||
'https://lastfm.freetls.fastly.net',
|
||||
'https://cd-albums.b-cdn.net'
|
||||
)
|
||||
: `https://cdn.coryd.dev/albums/${album['name'].name
|
||||
.replace(/\s+/g, '-')
|
||||
.toLowerCase()}.jpg`,
|
||||
url: album['mbid']
|
||||
? `https://musicbrainz.org/album/${album['mbid']}`
|
||||
: `https://musicbrainz.org/search?query=${encodeURI(album['name'])}&type=release_group`,
|
||||
type: 'album',
|
||||
}
|
||||
})
|
||||
}
|
Reference in a new issue