optimize music widget

This commit is contained in:
zoop 2026-09-13 08:33:01 -04:00
parent 1bd2d9edb1
commit f88dc71a7b
No known key found for this signature in database
GPG Key ID: 15C0D336C9E08F3F
4 changed files with 6 additions and 50 deletions

View File

@ -84,11 +84,6 @@ import { Icon } from "astro-icon/components";
<ul class="stat-list" id="lfm-artists"></ul>
</div>
<div class="stat-block" id="lfm-recent-block" hidden>
<h2 class="label">recently played</h2>
<ul class="stat-list stat-list--plain" id="lfm-recent"></ul>
</div>
<p class="wall-foot">
scrobbling <a
href="https://www.last.fm/user/zoop-zach"
@ -338,13 +333,6 @@ import { Icon } from "astro-icon/components";
letter-spacing: 0.02em;
color: var(--faint);
}
.stat-list--plain li::before {
display: none;
}
.stat-list--plain .stat-list__v {
color: var(--faint);
}
.np {
display: flex;
gap: 0.8rem;

View File

@ -53,7 +53,6 @@ export const GET: APIRoute = async () => {
nowPlaying: null as unknown,
top: [] as unknown[],
topArtists: [] as unknown[],
history: [] as unknown[],
weekPlays: 0,
allTimePlays: 0,
estMinutes: 0,
@ -70,16 +69,15 @@ export const GET: APIRoute = async () => {
try {
const [recent, top, artists, week, info] = await Promise.all([
call("method=user.getrecenttracks&limit=8&extended=1"),
call("method=user.gettoptracks&period=7day&limit=8"),
call("method=user.gettopartists&period=7day&limit=6"),
call("method=user.getrecenttracks&limit=1&extended=1"),
call("method=user.gettoptracks&period=7day&limit=5"),
call("method=user.gettopartists&period=7day&limit=5"),
call(`method=user.getrecenttracks&limit=1&from=${from}`),
call("method=user.getinfo"),
]);
const rtRaw = (recent as any)?.recenttracks?.track;
const rtArr: any[] = Array.isArray(rtRaw) ? rtRaw : rtRaw ? [rtRaw] : [];
const rt = rtArr[0];
const rt = Array.isArray(rtRaw) ? rtRaw[0] : rtRaw;
const nowPlaying = rt
? {
title: rt.name ?? "",
@ -92,16 +90,6 @@ export const GET: APIRoute = async () => {
}
: null;
const history = rtArr
.filter((t: any) => t["@attr"]?.nowplaying !== "true" && t.date?.uts)
.slice(0, 6)
.map((t: any) => ({
title: t.name ?? "",
artist: t.artist?.name ?? t.artist?.["#text"] ?? "",
playedAt: n(t.date.uts) * 1000,
}))
.filter((t: any) => t.title);
const topTracks = ((top as any)?.toptracks?.track ?? [])
.map((t: any) => ({
title: t.name ?? "",
@ -137,7 +125,6 @@ export const GET: APIRoute = async () => {
nowPlaying,
top: topTracks,
topArtists,
history,
weekPlays,
allTimePlays,
estMinutes,

View File

@ -10,11 +10,6 @@ interface ArtistRow {
plays: number;
url: string;
}
interface HistRow {
title: string;
artist: string;
playedAt: number;
}
interface NP {
title: string;
artist: string;
@ -29,7 +24,6 @@ interface Data {
nowPlaying: NP | null;
top: Track[];
topArtists: ArtistRow[];
history: HistRow[];
weekPlays: number;
allTimePlays: number;
estMinutes: number;
@ -142,12 +136,6 @@ function renderStats(d: Data): void {
w: Math.round((a.plays / artMax) * 100),
})),
);
fillList(
"lfm-recent",
"lfm-recent-block",
d.history.map((h) => ({ k: h.title, sub: h.artist, v: ago(h.playedAt) })),
);
}
function mockData(): Data {
@ -180,13 +168,7 @@ function mockData(): Data {
{ name: "Lil Uzi Vert", plays: 18, url: "" },
{ name: "Kehlani", plays: 12, url: "" },
{ name: "The Weeknd", plays: 7, url: "" },
],
history: [
{ title: "20 Min", artist: "Lil Uzi Vert", playedAt: Date.now() - 6 * 60_000 },
{ title: "After Party", artist: "Don Toliver", playedAt: Date.now() - 12 * 60_000 },
{ title: "Gemstones", artist: "Don Toliver", playedAt: Date.now() - 40 * 60_000 },
{ title: "NIGHTS LIKE THIS", artist: "Kehlani", playedAt: Date.now() - 3 * 3_600_000 },
{ title: "HEARTLESS", artist: "The Weeknd", playedAt: Date.now() - 26 * 3_600_000 },
{ name: "Kanye West", plays: 5, url: "" },
],
weekPlays: 128,
allTimePlays: 4210,
@ -216,7 +198,6 @@ async function load(): Promise<MusicState> {
const top = Array.isArray(data.top) ? data.top : [];
data.top = top;
data.topArtists = Array.isArray(data.topArtists) ? data.topArtists : [];
data.history = Array.isArray(data.history) ? data.history : [];
data.lib = data.lib ?? { artists: 0, albums: 0, tracks: 0 };
if (np) renderNowPlaying(np);
renderStats(data);