feat: programmatically import to listenbrainz at build time
This commit is contained in:
parent
ae4f4ca908
commit
de4152170f
4 changed files with 81 additions and 6 deletions
3
.env
3
.env
|
@ -5,4 +5,5 @@ API_KEY_MOVIEDB=
|
||||||
API_KEY_WEBMENTIONS_CORYD_DEV=
|
API_KEY_WEBMENTIONS_CORYD_DEV=
|
||||||
API_TOKEN_READWISE=
|
API_TOKEN_READWISE=
|
||||||
SECRET_FEED_ALBUM_RELEASES=
|
SECRET_FEED_ALBUM_RELEASES=
|
||||||
COOKIE_STORYGRAPH=
|
COOKIE_STORYGRAPH=
|
||||||
|
LISTENBRAINZ_TOKEN=
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "coryd.dev",
|
"name": "coryd.dev",
|
||||||
"version": "2.2.4",
|
"version": "2.3.0",
|
||||||
"description": "The source for my personal site, blog and portfolio. Built using 11ty and hosted on Netlify.",
|
"description": "The source for my personal site, blog and portfolio. Built using 11ty and hosted on Netlify.",
|
||||||
"main": "index.html",
|
"main": "index.html",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|
68
src/_data/tracks.js
Normal file
68
src/_data/tracks.js
Normal file
|
@ -0,0 +1,68 @@
|
||||||
|
const EleventyFetch = require('@11ty/eleventy-fetch')
|
||||||
|
const mbidPatches = require('./json/mbid-patches.json')
|
||||||
|
|
||||||
|
const mbidMap = (artist) => {
|
||||||
|
return mbidPatches[artist.toLowerCase()] || ''
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = async function () {
|
||||||
|
const MUSIC_KEY = process.env.API_KEY_LASTFM
|
||||||
|
const LISTENBRAINZ_TOKEN = process.env.LISTENBRAINZ_TOKEN
|
||||||
|
const url = `https://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user=coryd_&api_key=${MUSIC_KEY}&format=json&limit=200`
|
||||||
|
const res = EleventyFetch(url, {
|
||||||
|
duration: '1h',
|
||||||
|
type: 'json',
|
||||||
|
}).catch()
|
||||||
|
const data = await res
|
||||||
|
const submission = data['recenttracks']['track'].map((track) => {
|
||||||
|
let artistMbid = track['artist']['mbid']['mbid']
|
||||||
|
|
||||||
|
// mbid mismatches
|
||||||
|
if (mbidMap(track['artist']['#text']) !== '') artistMbid = mbidMap(track['artist']['#text'])
|
||||||
|
|
||||||
|
return {
|
||||||
|
track_metadata: {
|
||||||
|
track_name: track['name'],
|
||||||
|
artist_name: track['artist']['#text'],
|
||||||
|
release_name: track['album']['#text'],
|
||||||
|
additional_info: {
|
||||||
|
submission_client: 'coryd.dev last.fm importer',
|
||||||
|
lastfm_track_mbid: track['mbid'],
|
||||||
|
lastfm_release_mbid: track['album']['mbid'],
|
||||||
|
lastfm_artist_mbid: artistMbid,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
listened_at: track['date']['uts'],
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
await fetch('https://api.listenbrainz.org/1/submit-listens', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
Accept: 'application/json',
|
||||||
|
Authorization: `Token ${LISTENBRAINZ_TOKEN}`,
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
listen_type: 'import',
|
||||||
|
payload: submission,
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
|
||||||
|
await fetch('https://api.listenbrainz.org/1/latest-import', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
Accept: 'application/json',
|
||||||
|
Authorization: `Token ${LISTENBRAINZ_TOKEN}`,
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
service: 'lastfm',
|
||||||
|
ts: submission[0]['listened_at'],
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
console.log({
|
||||||
|
listenbrainz_submission: submission,
|
||||||
|
})
|
||||||
|
return {
|
||||||
|
listenbrainz_submission: submission,
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
! tailwindcss v3.3.5 | MIT License | https://tailwindcss.com
|
! tailwindcss v3.3.6 | MIT License | https://tailwindcss.com
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -121,8 +121,10 @@ strong {
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
1. Use the user's configured `mono` font family by default.
|
1. Use the user's configured `mono` font-family by default.
|
||||||
2. Correct the odd `em` font sizing in all browsers.
|
2. Use the user's configured `mono` font-feature-settings by default.
|
||||||
|
3. Use the user's configured `mono` font-variation-settings by default.
|
||||||
|
4. Correct the odd `em` font sizing in all browsers.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
code,
|
code,
|
||||||
|
@ -131,8 +133,12 @@ samp,
|
||||||
pre {
|
pre {
|
||||||
font-family: ml, ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
|
font-family: ml, ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
|
||||||
/* 1 */
|
/* 1 */
|
||||||
font-size: 1em;
|
font-feature-settings: normal;
|
||||||
/* 2 */
|
/* 2 */
|
||||||
|
font-variation-settings: normal;
|
||||||
|
/* 3 */
|
||||||
|
font-size: 1em;
|
||||||
|
/* 4 */
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Reference in a new issue