chore: scrobbling

This commit is contained in:
Cory Dransfeldt 2024-03-29 17:01:22 -07:00
parent f140ce22fe
commit b575d25d14

View file

@ -15,11 +15,6 @@ const weekStop = () => {
const filterOldScrobbles = (scrobbles) => { const filterOldScrobbles = (scrobbles) => {
const twoWeeksAgo = DateTime.now().minus({ weeks: 2 }); const twoWeeksAgo = DateTime.now().minus({ weeks: 2 });
console.log(scrobbles)
console.log(scrobbles.filter(scrobble => {
const timestamp = DateTime.fromISO(scrobble.timestamp);
return timestamp >= twoWeeksAgo;
}))
return scrobbles.filter(scrobble => { return scrobbles.filter(scrobble => {
const timestamp = DateTime.fromISO(scrobble.timestamp); const timestamp = DateTime.fromISO(scrobble.timestamp);
return timestamp >= twoWeeksAgo; return timestamp >= twoWeeksAgo;
@ -104,11 +99,11 @@ export default async (request) => {
genre, genre,
image: `https://cdn.coryd.dev/artists/${encodeURIComponent(sanitizeMediaString(artist).replace(/\s+/g, '-').toLowerCase())}.jpg` image: `https://cdn.coryd.dev/artists/${encodeURIComponent(sanitizeMediaString(artist).replace(/\s+/g, '-').toLowerCase())}.jpg`
} }
artistInfo = artistData
await artists.setJSON(artistKey, artistData) await artists.setJSON(artistKey, artistData)
} }
// scrobble logic // scrobble logic
artistInfo = await artists.get(artistKey, { type: 'json'})
const trackScrobbleData = { const trackScrobbleData = {
track, track,
album, album,
@ -118,10 +113,6 @@ export default async (request) => {
} }
const scrobbleData = await scrobbles.get(`${weekStop()}`, { type: 'json'}) const scrobbleData = await scrobbles.get(`${weekStop()}`, { type: 'json'})
const windowData = await scrobbles.get('window', { type: 'json'}) const windowData = await scrobbles.get('window', { type: 'json'})
console.log('### SCROBBLE START')
console.log(scrobbleData);
console.log('### WINDOW START')
console.log(windowData);
await scrobbles.setJSON('now-playing', {...trackScrobbleData, ...{ url: `https://musicbrainz.org/artist/${artistInfo?.['mbid']}`}}) await scrobbles.setJSON('now-playing', {...trackScrobbleData, ...{ url: `https://musicbrainz.org/artist/${artistInfo?.['mbid']}`}})
let scrobbleUpdate = scrobbleData let scrobbleUpdate = scrobbleData
let windowUpdate = windowData; let windowUpdate = windowData;