Something went wrong. Try again.
Exploring last.fm scrobbles
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940import { styleText } from 'node:util';import { createClient } from '../config.ts';import { userRecentTracks, userTopArtists } from '../endpoints.ts';import { artistName, formatCount } from '../format.ts';
const username = process.argv[2] ?? process.env.LASTFM_USER;
if (!username) { console.error('Usage: pnpm user <username>'); console.error('Or set LASTFM_USER in .env'); process.exit(1);}
console.log(`last.fm user: ${styleText('yellow', username)}`);
const client = createClient();
const recent = await userRecentTracks(client, username, { limit: 10 });console.log('\nRecent tracks');
for (const track of recent.recenttracks.track) { const nowPlaying = track['@attr']?.nowplaying === 'true'; const when = nowPlaying ? 'now playing' : (track.date?.['#text'] ?? ''); const marker = nowPlaying ? '▶' : ' '; console.log(`${marker} ${artistName(track.artist)} — ${track.name}${when ? ` (${when})` : ''}`);}
const topArtists = await userTopArtists(client, username, { period: '1month', limit: 10,});console.log(`\nTop artists (last month)`);console.table( topArtists.topartists.artist.map((artist, index) => ({ '#': index + 1, artist: artistName(artist), playcount: formatCount(artist.playcount), })),);