diff --git a/api/now-playing.js b/api/now-playing.js index 0eef12ce..94fa1ae2 100644 --- a/api/now-playing.js +++ b/api/now-playing.js @@ -1,48 +1,48 @@ import { getStore } from '@netlify/blobs' const emojiMap = (genre, artist) => { - const DEFAULT = "๐ŸŽง"; - const normalizedArtist = artist?.toLowerCase(); - if (normalizedArtist === "afi") return "โ›ต๏ธ๐ŸŒ…"; - if (normalizedArtist === "agalloch") return "๐Ÿ”๏ธ"; - if (normalizedArtist === "augury") return "โ˜„๏ธ"; - if (normalizedArtist === "autopsy") 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 "๐Ÿ‘ฝ"; + const DEFAULT = "๐ŸŽง" + const normalizedArtist = artist?.toLowerCase() + if (normalizedArtist === "afi") return "โ›ต๏ธ๐ŸŒ…" + if (normalizedArtist === "agalloch") return "๐Ÿ”๏ธ" + if (normalizedArtist === "augury") return "โ˜„๏ธ" + if (normalizedArtist === "autopsy") 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 === "counting crows") return "๐Ÿฆโ€โฌ›"; - if (normalizedArtist === "david bowie") return "๐Ÿ‘จ๐Ÿปโ€๐ŸŽค"; - if (normalizedArtist === "cevoid of thought") 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 === "minor threat") return "๐Ÿ‘จ๐Ÿปโ€๐Ÿฆฒ"; - if (normalizedArtist === "nomeansno") return "๐Ÿต๐Ÿฎ๐Ÿšฌ"; - if (normalizedArtist === "nothing") return "๐Ÿณ๏ธ"; - if (normalizedArtist === "panopticon") return "๐Ÿช•๐Ÿชฆ"; - if (normalizedArtist === "radiohead") return "๐Ÿ“ป"; - if (normalizedArtist === "taylor swift") return "๐Ÿ‘ธ๐Ÿผ"; - if (normalizedArtist === "the mars volta") return "๐Ÿ’ก๐Ÿ˜ฎ"; - if (normalizedArtist === "thrice") return "๐Ÿ‘จโ€๐ŸŽจ๐Ÿš‘"; + if (normalizedArtist === "bruce springsteen") return "๐Ÿ‡บ๐Ÿ‡ธ" + if (normalizedArtist === "carcass") return "๐Ÿฅผ" + if (normalizedArtist === "counting crows") return "๐Ÿฆโ€โฌ›" + if (normalizedArtist === "david bowie") return "๐Ÿ‘จ๐Ÿปโ€๐ŸŽค" + if (normalizedArtist === "cevoid of thought") 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 === "minor threat") return "๐Ÿ‘จ๐Ÿปโ€๐Ÿฆฒ" + if (normalizedArtist === "nomeansno") return "๐Ÿต๐Ÿฎ๐Ÿšฌ" + if (normalizedArtist === "nothing") return "๐Ÿณ๏ธ" + if (normalizedArtist === "panopticon") return "๐Ÿช•๐Ÿชฆ" + if (normalizedArtist === "radiohead") 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 "๐Ÿคก"; + if (normalizedArtist === "webbed wing") return "๐Ÿคก" // early return for bad input - if (!genre) return DEFAULT; + 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("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") || @@ -50,17 +50,17 @@ const emojiMap = (genre, artist) => { 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 "๐ŸŽค"; + 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("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 "๐Ÿคซ"; + 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") || @@ -68,18 +68,17 @@ const emojiMap = (genre, artist) => { genre.includes("screamo") || genre.includes("grunge") ) - return "๐ŸŽธ"; - return DEFAULT; -}; + return "๐ŸŽธ" + return DEFAULT +} export default async () => { - const TV_KEY = Netlify.env.get("API_KEY_TRAKT"); + const TV_KEY = Netlify.env.get("API_KEY_TRAKT") const scrobbles = getStore('scrobbles') const headers = { "Content-Type": "application/json", "Cache-Control": "public, s-maxage=360, stale-while-revalidate=1080", - }; - + } const traktRes = await fetch("https://api.trakt.tv/users/cdransf/watching", { headers: { "Content-Type": "application/json", @@ -89,13 +88,13 @@ export default async () => { }) .then((data) => { if (data.status === 204) return {} - if (data.ok) return data?.json(); - throw new Error('Something went wrong with the Trakt endpoint.'); + if (data.ok) return data?.json() + throw new Error('Something went wrong with the Trakt endpoint.') }) .catch(err => { - console.log(err); + console.log(err) return {} - }); + }) if (Object.keys(traktRes).length) { if (traktRes["type"] === "episode") { @@ -114,7 +113,6 @@ export default async () => { ) } } - const scrobbleData = await scrobbles.get('now-playing', { type: 'json'}) if (!scrobbleData) return new Response(JSON.stringify({}, { headers })) @@ -129,9 +127,9 @@ export default async () => { }), { headers } ) -}; +} export const config = { cache: "manual", path: "/api/now-playing" -}; +} \ No newline at end of file diff --git a/package.json b/package.json index beefbb38..e96466fb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "coryd.dev", - "version": "13.0.5", + "version": "13.0.6", "description": "The source for my personal site. Built using 11ty.", "type": "module", "scripts": {