diff --git a/api/now-playing.js b/api/now-playing.js index 7441e0cb..6bc4074e 100644 --- a/api/now-playing.js +++ b/api/now-playing.js @@ -30,90 +30,10 @@ const parseCountryField = (countryField) => { return countries.map(getCountryName).join(', ') } -const emojiMap = (genre, artist) => { - const DEFAULT = "๐ŸŽง" - const normalizedArtist = artist?.toLowerCase() - if (normalizedArtist === "afi") return "โ›ต๏ธ๐ŸŒ…" - if (normalizedArtist === "agalloch") return "๐Ÿ”๏ธ" - if (normalizedArtist === "american football") return "๐Ÿ " - if (normalizedArtist === "augury") return "โ˜„๏ธ" - if (normalizedArtist === "autopsy") return "๐ŸงŸ" - if (normalizedArtist === "bad religion") return "๐Ÿšซโœ๏ธ" - if (normalizedArtist === "balance and composure") return "๐Ÿช‚" - if (normalizedArtist === "bedsore") return "๐Ÿ›๏ธ" - if (normalizedArtist === "birds in row") return "๐Ÿฆ…๐Ÿฆ‰๐Ÿฆข" - if (normalizedArtist === "black flag") return "๐Ÿด" - if (normalizedArtist === "blink-182") return "๐Ÿ˜ต" - if (normalizedArtist === "blood incantation") return "๐Ÿ‘ฝ" - if (normalizedArtist === "bolt thrower") return "โš”๏ธ" - if (normalizedArtist === "bruce springsteen") return "๐Ÿ‡บ๐Ÿ‡ธ" - if (normalizedArtist === "carcass") return "๐Ÿฅผ" - if (normalizedArtist === "cloud rat") return "โ˜๏ธ๐Ÿ€" - if (normalizedArtist === "counting crows") return "๐Ÿฆโ€โฌ›" - if (normalizedArtist === "david bowie") return "๐Ÿ‘จ๐Ÿปโ€๐ŸŽค" - if (normalizedArtist === "devoid of thought") return "๐Ÿšซ๐Ÿ’ญ" - if (normalizedArtist === "deftones") return "๐Ÿฆ‰" - if (normalizedArtist === "drug church") return "๐Ÿ’Šโ›ช๏ธ" - if (normalizedArtist === "fleshwater") return "๐Ÿค" - if (normalizedArtist === "full of hell & nothing") return "๐Ÿซจ๐ŸŽธ" - if (normalizedArtist === "imperial triumphant") return "๐ŸŽญ" - if (normalizedArtist === "mastodon") return "๐Ÿ‹" - if (normalizedArtist === "mineral") return "๐Ÿชจ" - if (normalizedArtist === "minor threat") return "๐Ÿ‘จ๐Ÿปโ€๐Ÿฆฒ" - if (normalizedArtist === "nomeansno") return "๐Ÿต๐Ÿฎ๐Ÿšฌ" - if (normalizedArtist === "nothing") return "๐Ÿณ๏ธ" - if (normalizedArtist === "panopticon") return "๐Ÿช•๐Ÿชฆ" - if (normalizedArtist === "plunger") return "๐Ÿช " - if (normalizedArtist === "radiohead") return "๐Ÿ“ป" - if (normalizedArtist === "soccer mommy") return "โšฝ๏ธ" - if (normalizedArtist === "taylor swift") return "๐Ÿ‘ธ๐Ÿผ" - if (normalizedArtist === "the mars volta") return "๐Ÿ’ก๐Ÿ˜ฎ" - if (normalizedArtist === "thrice") return "๐Ÿ‘จโ€๐ŸŽจ๐Ÿš‘" - if (normalizedArtist === "tom waits") return "๐Ÿคน๐Ÿป" - if (normalizedArtist === "webbed wing") return "๐Ÿคก" - - // early return for bad input - if (!genre) return DEFAULT - - if (genre.includes("death metal") || genre.includes("death-doom")) return "๐Ÿ’€" - if (genre.includes("black metal") || genre.includes("blackgaze")) return "๐Ÿชฆ" - if (genre.includes("metal")) return "๐Ÿค˜" - if (genre.includes("emo") || genre.includes("blues")) return "๐Ÿ˜ข" - if (genre.includes("grind") || genre.includes("powerviolence")) return "๐Ÿซจ" - if ( - genre.includes("country") || - genre.includes("americana") || - genre.includes("bluegrass") || - genre.includes("folk") || - genre.includes("songwriter") - ) - return "๐Ÿช•" - if (genre.includes("post-punk")) return "๐Ÿ˜”" - if (genre.includes("dance-punk")) return "๐Ÿชฉ" - if (genre.includes("punk") || genre.includes("hardcore")) return "โœŠ" - if (genre.includes("hip hop")) return "๐ŸŽค" - if (genre.includes("hip-hop")) return "๐ŸŽค" - if (genre.includes("progressive") || genre.includes("experimental")) - return "๐Ÿค“" - if (genre.includes("jazz")) return "๐ŸŽบ" - if (genre.includes("psychedelic")) return "๐Ÿ’Š" - if (genre.includes("dance") || genre.includes("electronic")) return "๐Ÿ’ป" - if (genre.includes("ambient")) return "๐Ÿคซ" - if ( - genre.includes("alternative") || - genre.includes("rock") || - genre.includes("shoegaze") || - genre.includes("screamo") || - genre.includes("grunge") - ) - return "๐ŸŽธ" - return DEFAULT -} - const fetchGenreById = async (genreId) => { const { data, error } = await supabase .from('genres') - .select('name') + .select('emoji') .eq('id', genreId) .single() @@ -122,7 +42,7 @@ const fetchGenreById = async (genreId) => { return null } - return data.name + return data.emoji } export default async () => { @@ -132,7 +52,7 @@ export default async () => { track_name, artist_name, listened_at, - artists (mbid, genres, country) + artists (mbid, genres, country, emoji) `) .order('listened_at', { ascending: false }) .range(0, 1) @@ -152,13 +72,11 @@ export default async () => { } const scrobbleData = data[0] - scrobbleData.genre = await fetchGenreById(data[0].artists.genres) + const genreEmoji = await fetchGenreById(data[0].artists.genres) + const emoji = scrobbleData.artists.emoji || genreEmoji return new Response(JSON.stringify({ - content: `${emojiMap( - scrobbleData.genre, - scrobbleData.artist_name - )} ${scrobbleData.track_name} by ${ + content: `${emoji || '๐ŸŽง'} ${scrobbleData.track_name} by ${ scrobbleData.artist_name }`, }), { headers }); diff --git a/package-lock.json b/package-lock.json index 5acd4e3c..45296155 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "coryd.dev", - "version": "18.1.4", + "version": "18.2.4", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "coryd.dev", - "version": "18.1.4", + "version": "18.2.4", "license": "MIT", "dependencies": { "@cdransf/api-text": "^1.4.0", diff --git a/package.json b/package.json index 2380b44d..5edab42c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "coryd.dev", - "version": "18.1.4", + "version": "18.2.4", "description": "The source for my personal site. Built using 11ty.", "type": "module", "scripts": {