A tool to scrobble tracks from your Apple Music data export to Teal.fm.
at main 753 B view raw
1import { readFile, writeFile } from "fs/promises"; 2import type { AppleMusicPlaybackEvent } from "../types"; 3 4const cacheFilePath = "cache/progress.json"; 5 6export type CacheRecord = { 7 songName: string; 8 timestamp: string; 9}; 10 11export async function getCache(): Promise<CacheRecord[]> { 12 try { 13 const data = await readFile(cacheFilePath, "utf-8"); 14 return JSON.parse(data); 15 } catch (error) { 16 return []; 17 } 18} 19 20export async function updateCache( 21 event: AppleMusicPlaybackEvent, 22): Promise<void> { 23 const cache = await getCache(); 24 cache.push({ 25 songName: event["Song Name"], 26 timestamp: event["Event End Timestamp"], 27 }); 28 await writeFile(cacheFilePath, JSON.stringify(cache, null, 2)); 29}