From f38f432bad3d94d26b5f8f08db12ec11597a8fe9 Mon Sep 17 00:00:00 2001 From: r-freeman Date: Sat, 18 Feb 2023 22:51:56 +0000 Subject: [PATCH] Added spotify metric to dashboard --- lib/dashboard.ts | 8 +++++++- lib/statsfm.ts | 5 ++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/dashboard.ts b/lib/dashboard.ts index 847bcb0..5c4434f 100644 --- a/lib/dashboard.ts +++ b/lib/dashboard.ts @@ -16,7 +16,7 @@ export async function getDashboardData() { const totalArticleViews = (await getViews()).views const topArtist = await getTopArtist() const {genre} = await getTopGenre() - const {minutesListened, streams} = await getStats() + const {hoursListened, minutesListened, streams} = await getStats() const metrics: Metric[] = [ { @@ -25,6 +25,12 @@ export async function getDashboardData() { group: "Spotify", href: "https://open.spotify.com/?" }, + { + title: "Hours listened", + value: +hoursListened, + group: "Spotify", + href: "https://open.spotify.com/?" + }, { title: "Minutes listened", value: +minutesListened, diff --git a/lib/statsfm.ts b/lib/statsfm.ts index 7fea878..cc1268e 100644 --- a/lib/statsfm.ts +++ b/lib/statsfm.ts @@ -18,10 +18,13 @@ export const getStats = async () => { } }).then(r => r.json()) as StatsFmResponse - const minutesListened = ((response.items.durationMs / 1000) / 60).toFixed(0) + const {durationMs} = response.items + const hoursListened = (durationMs / 3_600_000).toFixed(0) + const minutesListened = (durationMs / 60_000).toFixed(0) const streams = response.items.count return { + hoursListened, minutesListened, streams }