diff --git a/api/now-playing.js b/api/now-playing.js index d1b33878..dfcf441e 100644 --- a/api/now-playing.js +++ b/api/now-playing.js @@ -1,8 +1,34 @@ import { createClient } from '@supabase/supabase-js'; +import slugify from 'slugify' const SUPABASE_URL = process.env.SUPABASE_URL const SUPABASE_KEY = process.env.SUPABASE_KEY -const supabase = createClient(SUPABASE_URL, SUPABASE_KEY); +const supabase = createClient(SUPABASE_URL, SUPABASE_KEY) + +const sanitizeMediaString = (str) => { + const sanitizedString = str.normalize('NFD').replace(/[\u0300-\u036f\u2010—\.\?\(\)\[\]\{\}]/g, '').replace(/\.{3}/g, '') + + return slugify(sanitizedString, { + replacement: '-', + remove: /[#,&,+()$~%.'":*?<>{}]/g, + lower: true, + }) +} + +const regionNames = new Intl.DisplayNames(['en'], { type: 'region' }) +const getCountryName = (countryCode) => regionNames.of(countryCode.trim()) || countryCode.trim() +const parseCountryField = (countryField) => { + if (!countryField) return null + + const delimiters = [',', '/', '&', 'and'] + let countries = [countryField] + + delimiters.forEach(delimiter => { + countries = countries.flatMap(country => country.split(delimiter)) + }) + + return countries.map(getCountryName).join(', ') +} const emojiMap = (genre, artist) => { const DEFAULT = "🎧" @@ -90,7 +116,7 @@ export default async () => { track_name, artist_name, listened_at, - artists (mbid, genre) + artists (mbid, genre, country) `) .order('listened_at', { ascending: false }) .range(0, 1) @@ -115,7 +141,7 @@ export default async () => { content: `${emojiMap( scrobbleData.artists.genre, scrobbleData.artist_name - )} ${scrobbleData.track_name} by ${ + )} ${scrobbleData.track_name} by ${ scrobbleData.artist_name }`, }), { headers }); diff --git a/package-lock.json b/package-lock.json index c127d9da..cb98fc41 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "coryd.dev", - "version": "17.0.3", + "version": "17.0.4", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "coryd.dev", - "version": "17.0.3", + "version": "17.0.4", "license": "MIT", "dependencies": { "@cdransf/api-text": "^1.2.2", @@ -3346,9 +3346,9 @@ "dev": true }, "node_modules/electron-to-chromium": { - "version": "1.4.781", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.781.tgz", - "integrity": "sha512-aBI40ltvcWJQDW+V803FY6HjXAfi5xCWzpa3vSM/NGg7GfKEvI7ftzW4Gb2XKTRO4WsxDG7YG8ykrr/pG9bkKQ==", + "version": "1.4.782", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.782.tgz", + "integrity": "sha512-JUfU61e8tr+i5Y1FKXcKs+Xe+rJ+CEqm4cgv1kMihPE2EvYHmYyVr3Im/+1+Z5B29Be2EEGCZCwAc6Tazdl1Yg==", "dev": true }, "node_modules/encodeurl": { diff --git a/package.json b/package.json index 1bdc96d4..3e8b99e1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "coryd.dev", - "version": "17.0.3", + "version": "17.0.4", "description": "The source for my personal site. Built using 11ty.", "type": "module", "scripts": {