chore: cleanup
This commit is contained in:
parent
dfc6ee542e
commit
9070daffcd
6 changed files with 3 additions and 139 deletions
|
@ -1,30 +0,0 @@
|
|||
import EleventyFetch from '@11ty/eleventy-fetch'
|
||||
import { artistCapitalization, sanitizeMediaString } from './helpers/music.js'
|
||||
|
||||
export default 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 formatAlbumData = (albums) => albums.map((album) => {
|
||||
return {
|
||||
title: album['name'],
|
||||
artist: artistCapitalization(album['artist']['name']),
|
||||
plays: album['playcount'],
|
||||
rank: album['@attr']['rank'],
|
||||
image: `https://cdn.coryd.dev/albums/${sanitizeMediaString(album['artist']['name']).replace(/\s+/g, '-').toLowerCase()}-${sanitizeMediaString(album['name'].replace(/[:\/\\,'']+/g
|
||||
, '').replace(/\s+/g, '-').toLowerCase())}.jpg`,
|
||||
url: album['mbid']
|
||||
? `https://musicbrainz.org/album/${album['mbid']}`
|
||||
: `https://musicbrainz.org/taglookup/index?tag-lookup.artist=${album['artist'][
|
||||
'name'
|
||||
].replace(/\s+/g, '+')}&tag-lookup.release=${album['name'].replace(/\s+/g, '+')}`,
|
||||
type: 'album',
|
||||
}
|
||||
})
|
||||
|
||||
const res = EleventyFetch(url, {
|
||||
duration: '1h',
|
||||
type: 'json',
|
||||
}).catch()
|
||||
const data = await res
|
||||
return formatAlbumData(data['topalbums']['album'])
|
||||
}
|
|
@ -1,34 +0,0 @@
|
|||
import EleventyFetch from '@11ty/eleventy-fetch';
|
||||
import { artistCapitalization, sanitizeMediaString, mbidMap } from './helpers/music.js'
|
||||
|
||||
export default async function () {
|
||||
const MUSIC_KEY = process.env.API_KEY_LASTFM;
|
||||
const url = `https://ws.audioscrobbler.com/2.0/?method=user.gettopartists&user=coryd_&api_key=${MUSIC_KEY}&limit=8&format=json&period=7day`;
|
||||
const formatArtistData = (artists) => artists.map((artist) => {
|
||||
let mbid = artist['mbid']
|
||||
|
||||
// mbid mismatches
|
||||
if (mbidMap(artist['name']) !== '') mbid = mbidMap(artist['name']);
|
||||
|
||||
return {
|
||||
title: artistCapitalization(artist['name']),
|
||||
plays: artist['playcount'],
|
||||
rank: artist['@attr']['rank'],
|
||||
image: `https://cdn.coryd.dev/artists/${sanitizeMediaString(artist['name']).replace(/\s+/g, '-').toLowerCase()}.jpg`,
|
||||
url: mbid
|
||||
? `https://musicbrainz.org/artist/${mbid}`
|
||||
: `https://musicbrainz.org/search?query=${artist['name'].replace(
|
||||
/\s+/g,
|
||||
'+'
|
||||
)}&type=artist`,
|
||||
type: 'artist',
|
||||
};
|
||||
});
|
||||
|
||||
const res = EleventyFetch(url, {
|
||||
duration: '1h',
|
||||
type: 'json',
|
||||
}).catch();
|
||||
const data = await res;
|
||||
return formatArtistData(data['topartists']['artist'])
|
||||
}
|
|
@ -1,72 +0,0 @@
|
|||
import EleventyFetch from '@11ty/eleventy-fetch'
|
||||
import mbidPatches from './json/mbid-patches.js'
|
||||
|
||||
const mbidMap = (artist) => {
|
||||
return mbidPatches[artist.toLowerCase()] || ''
|
||||
}
|
||||
|
||||
export default 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`
|
||||
if (process.env.ELEVENTY_PRODUCTION) {
|
||||
const res = EleventyFetch(url, {
|
||||
duration: '1h',
|
||||
type: 'json',
|
||||
}).catch()
|
||||
const data = await res
|
||||
let submissions = []
|
||||
data['recenttracks']['track'].forEach((track) => {
|
||||
let artistMbid = track['artist']['mbid']['mbid']
|
||||
|
||||
// mbid mismatches
|
||||
if (mbidMap(track['artist']['#text']) !== '') artistMbid = mbidMap(track['artist']['#text'])
|
||||
|
||||
if (track['date'])
|
||||
submissions.push({
|
||||
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: submissions,
|
||||
}),
|
||||
})
|
||||
|
||||
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: submissions[0]['listened_at'],
|
||||
}),
|
||||
})
|
||||
|
||||
return {
|
||||
listenbrainz_submissions: submissions,
|
||||
}
|
||||
} else {
|
||||
return {}
|
||||
}
|
||||
}
|
Reference in a new issue