A decentralized music tracking and discovery platform built on AT Protocol 馃幍
at fix/spotify 56 lines 1.5 kB view raw
1import chalk from "chalk"; 2import { RockskyClient } from "client"; 3import fs from "fs/promises"; 4import os from "os"; 5import path from "path"; 6import { getBorderCharacters, table } from "table"; 7 8export async function stats(did?: string) { 9 const tokenPath = path.join(os.homedir(), ".rocksky", "token.json"); 10 try { 11 await fs.access(tokenPath); 12 } catch (err) { 13 if (!did) { 14 console.error( 15 `You are not logged in. Please run ${chalk.greenBright( 16 "`rocksky login <username>.bsky.social`" 17 )} first.` 18 ); 19 return; 20 } 21 } 22 23 const tokenData = await fs.readFile(tokenPath, "utf-8"); 24 const { token } = JSON.parse(tokenData); 25 if (!token && !did) { 26 console.error( 27 `You are not logged in. Please run ${chalk.greenBright( 28 "`rocksky login <username>.bsky.social`" 29 )} first.` 30 ); 31 return; 32 } 33 34 const client = new RockskyClient(token); 35 const stats = await client.stats(did); 36 37 console.log( 38 table( 39 [ 40 ["Scrobbles", chalk.magenta(stats.scrobbles)], 41 ["Tracks", chalk.magenta(stats.tracks)], 42 ["Albums", chalk.magenta(stats.albums)], 43 ["Artists", chalk.magenta(stats.artists)], 44 ["Loved Tracks", chalk.magenta(stats.lovedTracks)], 45 ], 46 { 47 border: getBorderCharacters("void"), 48 columnDefault: { 49 paddingLeft: 0, 50 paddingRight: 1, 51 }, 52 drawHorizontalLine: () => false, 53 } 54 ) 55 ); 56}