2023-02-02 21:47:35 +00:00
|
|
|
import fetch from 'node-fetch'
|
|
|
|
|
|
|
|
const STATSFM_USERNAME = process.env.STATSFM_USERNAME
|
|
|
|
const STATSFM_LIFETIME_STATS = `https://beta-api.stats.fm/api/v1/users/${STATSFM_USERNAME}/streams/stats?range=lifetime`
|
|
|
|
|
|
|
|
type StatsFmResponse = {
|
|
|
|
items: {
|
|
|
|
durationMs: number
|
2023-02-12 19:08:08 +00:00
|
|
|
count: number
|
2023-02-02 21:47:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export const getStats = async () => {
|
|
|
|
const response = await fetch(STATSFM_LIFETIME_STATS, {
|
|
|
|
method: 'GET',
|
|
|
|
headers: {
|
|
|
|
'Accept': 'application/json'
|
|
|
|
}
|
|
|
|
}).then(r => r.json()) as StatsFmResponse
|
|
|
|
|
|
|
|
const minutesListened = ((response.items.durationMs / 1000) / 60).toFixed(0)
|
2023-02-12 19:08:08 +00:00
|
|
|
const streams = response.items.count
|
2023-02-02 21:47:35 +00:00
|
|
|
|
|
|
|
return {
|
2023-02-12 19:08:08 +00:00
|
|
|
minutesListened,
|
|
|
|
streams
|
2023-02-02 21:47:35 +00:00
|
|
|
}
|
|
|
|
}
|