From f5df946e0b738f1ac729ffd04c2225a48041dd97 Mon Sep 17 00:00:00 2001 From: SirBlob Date: Sun, 1 Nov 2026 18:42:16 -0500 Subject: [PATCH] Remove recently played from music --- .../about/listening/ListeningSection.svelte | 10 +- .../about/listening/RecentTracks.svelte | 157 ------------------ src/lib/lastfm/types.ts | 2 - src/lib/server/lastfm/api.ts | 7 - src/lib/server/lastfm/profile.ts | 37 +---- 5 files changed, 7 insertions(+), 206 deletions(-) delete mode 100644 src/lib/components/about/listening/RecentTracks.svelte diff --git a/src/lib/components/about/listening/ListeningSection.svelte b/src/lib/components/about/listening/ListeningSection.svelte index cc4d54a..741a807 100644 --- a/src/lib/components/about/listening/ListeningSection.svelte +++ b/src/lib/components/about/listening/ListeningSection.svelte @@ -5,7 +5,6 @@ import Panel from '../../ui/Panel.svelte'; import ActivityPanel from './ActivityPanel.svelte'; import ListeningFetch from './ListeningFetch.svelte'; - import RecentTracks from './RecentTracks.svelte'; import TopCharts from './TopCharts.svelte'; import TrendingArtists from './TrendingArtists.svelte'; @@ -16,18 +15,13 @@ - - - - - -
-
+ +

Top charts

diff --git a/src/lib/components/about/listening/RecentTracks.svelte b/src/lib/components/about/listening/RecentTracks.svelte deleted file mode 100644 index 14f1b3f..0000000 --- a/src/lib/components/about/listening/RecentTracks.svelte +++ /dev/null @@ -1,157 +0,0 @@ - - -{#if tracks.length} - -{:else} -

No scrobbles yet.

-{/if} - - diff --git a/src/lib/lastfm/types.ts b/src/lib/lastfm/types.ts index d7107b5..3089c42 100644 --- a/src/lib/lastfm/types.ts +++ b/src/lib/lastfm/types.ts @@ -48,8 +48,6 @@ export interface ListeningProfile { profileUrl: string; registeredAt: number | null; totals: ListeningTotals; - nowPlaying: PlayedTrack | null; - recentTracks: PlayedTrack[]; daily: CountBucket[]; monthly: CountBucket[]; hourly: CountBucket[]; diff --git a/src/lib/server/lastfm/api.ts b/src/lib/server/lastfm/api.ts index 67697a4..411867c 100644 --- a/src/lib/server/lastfm/api.ts +++ b/src/lib/server/lastfm/api.ts @@ -121,13 +121,6 @@ export async function fetchRecentTracksPage( }; } -export async function fetchNowPlaying(userName: string): Promise { - const { recenttracks } = await callLastfm('user.getrecenttracks', { user: userName, limit: '1' }); - const rawTracks = Array.isArray(recenttracks.track) ? recenttracks.track : [recenttracks.track]; - const nowPlayingRaw = rawTracks.find((raw) => raw['@attr']?.nowplaying === 'true'); - return nowPlayingRaw ? toPlayedTrack(nowPlayingRaw) : null; -} - export async function fetchTrackImage(artist: string, track: string): Promise { const { track: info } = await callLastfm('track.getinfo', { artist, track, autocorrect: '1' }); return largestImage(info?.album?.image); diff --git a/src/lib/server/lastfm/profile.ts b/src/lib/server/lastfm/profile.ts index 28321e5..25a476d 100644 --- a/src/lib/server/lastfm/profile.ts +++ b/src/lib/server/lastfm/profile.ts @@ -1,7 +1,7 @@ -import type { ListeningProfile, PlayedTrack } from '#lib/lastfm/types'; -import { fetchNowPlaying, fetchUserInfo, hasLastfmKey, type UserInfo } from './api'; +import type { ListeningProfile } from '#lib/lastfm/types'; +import { fetchUserInfo, hasLastfmKey, type UserInfo } from './api'; import { loadScrobbleStore, storedScrobbles } from './store'; -import { coverFor, coversVersion, loadCovers, requestTrackCovers } from './covers'; +import { coversVersion, loadCovers, requestTrackCovers } from './covers'; import { lastfmSyncedAt } from './sync'; import { countsByDay, @@ -14,14 +14,11 @@ import { } from './trends'; const userInfoDuration = 30 * 60 * 1000; -const nowPlayingDuration = 60 * 1000; const summaryDuration = 5 * 60 * 1000; -const recentCount = 8; -type Summary = Omit; +type Summary = Omit; let userInfoCache: { info: UserInfo; fetchedAt: number } | null = null; -let nowPlayingCache: { track: PlayedTrack | null; fetchedAt: number } | null = null; let summaryCache: { summary: Summary; scrobbleCount: number; coversVersion: number; builtAt: number } | null = null; async function cachedUserInfo(userName: string): Promise { @@ -34,27 +31,6 @@ async function cachedUserInfo(userName: string): Promise { return userInfoCache?.info ?? null; } -async function cachedNowPlaying(userName: string): Promise { - if (nowPlayingCache && Date.now() - nowPlayingCache.fetchedAt < nowPlayingDuration) return nowPlayingCache.track; - try { - nowPlayingCache = { track: await fetchNowPlaying(userName), fetchedAt: Date.now() }; - } catch (error) { - console.error('Last.fm now playing failed:', error instanceof Error ? error.message : error); - } - return nowPlayingCache?.track ?? null; -} - -function recentTracks(): PlayedTrack[] { - return storedScrobbles() - .slice(-recentCount) - .reverse() - .map((scrobble) => ({ - ...scrobble, - url: `https://www.last.fm/music/${encodeURIComponent(scrobble.artist)}/_/${encodeURIComponent(scrobble.track)}`, - image: coverFor(scrobble.artist, scrobble.album, scrobble.track) - })); -} - function buildSummary(): Summary { const scrobbles = storedScrobbles(); const nowSeconds = Math.floor(Date.now() / 1000); @@ -63,7 +39,6 @@ function buildSummary(): Summary { const streaks = listeningStreaks(dayCounts); return { - recentTracks: recentTracks(), daily, monthly: monthlyBuckets(dayCounts), hourly: hourlyBuckets(scrobbles), @@ -79,7 +54,6 @@ function buildSummary(): Summary { function tracksMissingCovers(summary: Summary) { return Object.values(summary.top) .flatMap((charts) => charts.tracks) - .concat(summary.recentTracks.map((track) => ({ ...track, name: track.track, count: 0 }))) .filter((item) => !item.image && item.artist) .map((item) => ({ artist: item.artist!, track: item.name })); } @@ -105,7 +79,7 @@ export async function getListeningProfile(userName: string): Promise