diff --git a/src/components/Music.astro b/src/components/Music.astro deleted file mode 100644 index 4fba620..0000000 --- a/src/components/Music.astro +++ /dev/null @@ -1,7 +0,0 @@ -
-
- - diff --git a/src/js/index.ts b/src/js/index.ts index c08ecf8..c6becdf 100644 --- a/src/js/index.ts +++ b/src/js/index.ts @@ -4,9 +4,8 @@ const links = document.querySelectorAll(".motion-links"); const logo = document.querySelectorAll(".motion-logo"); const text = document.querySelectorAll(".motion-text"); const footer = document.querySelectorAll(".motion-footer"); -const music = document.querySelectorAll(".motion-music"); -const elements = [...text, ...logo, ...links, ...footer, ...music]; +const elements = [...text, ...logo, ...links, ...footer]; animate( elements, diff --git a/src/js/music.ts b/src/js/music.ts deleted file mode 100644 index 7b1f17f..0000000 --- a/src/js/music.ts +++ /dev/null @@ -1,158 +0,0 @@ -interface Track { - artists: string[]; - title: string; - album: { albumtitle: string }; -} - -interface Scrobble { - time: number; - track: Track; -} - -const SPOTIFY_ID = "7d152bfca7e545a5801cc2a0b5b9dcb0"; -const SPOTIFY_SECRET = "ff9db43e1ec7420bacd4e553f09ee555"; - -async function getSpotifyToken(): Promise { - const encoded = btoa(`${SPOTIFY_ID}:${SPOTIFY_SECRET}`); - - try { - const response = await fetch("https://accounts.spotify.com/api/token", { - method: "POST", - headers: { - "Content-Type": "application/x-www-form-urlencoded", - Authorization: `Basic ${encoded}`, - }, - body: "grant_type=client_credentials", - }); - - if (!response.ok) { - throw new Error(`HTTP error! status: ${response.status}`); - } - - const data = await response.json(); - return data.access_token; - } catch (error) { - console.error("Error getting Spotify token:", error); - return null; - } -} - -async function fetchSpotifyCover( - artist: string, - track: string, -): Promise { - const token = await getSpotifyToken(); - if (!token) { - return null; - } - - const encodedArtist = encodeURIComponent(artist); - const encodedTrack = encodeURIComponent(track); - const query = `track:${encodedTrack} artist:${encodedArtist}`; - - try { - const response = await fetch( - `https://api.spotify.com/v1/search?q=${query}&type=track&limit=1`, - { - headers: { - Authorization: `Bearer ${token}`, - }, - }, - ); - - if (!response.ok) { - throw new Error(`Spotify API error! status: ${response.status}`); - } - - const data = await response.json(); - - if (data?.tracks?.items?.length > 0) { - const imageUrl = data.tracks.items[0].album.images[0].url; - return imageUrl; - } - - return null; - } catch (error) { - console.error("Error fetching Spotify cover:", error); - return null; - } -} - -async function fetchAndDisplayLastTrack() { - const container = document.getElementById("last-track-widget"); - - if (!container) { - console.error("Container element not found!"); - return; - } - - try { - let res: Response; - try { - res = await fetch("https://z0x.ca/music"); - if (!res.ok) throw new Error("WAN fetch failed"); - } catch (e) { - res = await fetch("https://z0x.home.arpa/music"); - } - - if (!res.ok) { - throw new Error(`HTTP error! status: ${res.status}`); - } - - const data: { status: string; list: Scrobble[] } = await res.json(); - - let lastTrack: Track | null = null; - if (data?.status === "ok" && data.list?.length) { - lastTrack = data.list.sort( - (a: Scrobble, b: Scrobble) => b.time - a.time, - )[0].track; - } - - if (lastTrack) { - const albumCover = await fetchSpotifyCover( - lastTrack.artists[0], - lastTrack.title, - ); - - let imageElement = ""; - if (albumCover) { - imageElement = `Album Cover`; - } else { - imageElement = ""; - } - - container.innerHTML = ` - ${imageElement} - - - - Last played.. - - - - ${lastTrack.title} - - - - by - - ${lastTrack.artists[0]} - - - - on - - ${lastTrack.album.albumtitle} - - `; - } else { - container.innerHTML = "

No tracks found.

"; - } - } catch (e) { - console.error("Fetch error:", e); - container.innerHTML = "

Error loading tracks.

"; - } finally { - } -} - -fetchAndDisplayLastTrack(); diff --git a/src/pages/index.astro b/src/pages/index.astro index 468deb2..ab56a10 100644 --- a/src/pages/index.astro +++ b/src/pages/index.astro @@ -1,7 +1,6 @@ --- import Links from "@/components/Links.astro"; import Logo from "@/components/Logo.astro"; -import Music from "@/components/Music.astro"; import Text from "@/components/Text.astro"; import Layout from "@/layouts/Layout.astro"; --- @@ -10,5 +9,4 @@ import Layout from "@/layouts/Layout.astro"; -