From a2cb72c0f167de0ca856427e74fae9f6fc1549a3 Mon Sep 17 00:00:00 2001 From: Caleb Allen Date: Mon, 30 Mar 2026 08:29:58 -0400 Subject: [PATCH] feat: show total LB play count on artist detail page MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Added GetArtistPlayCount(mbid) — fetches ArtistPopularity from LB for a single MBID and returns the total listen count. Fire-and-forget call on the artist page, displays below the meta line as '1.3M plays on ListenBrainz' (uses existing formatListenCount). --- backend/explore/explore.go | 11 +++++++++++ .../explore-artist-details.ts | 19 +++++++++++++++++++ frontend/wailsjs/go/explore/Service.d.ts | 2 ++ frontend/wailsjs/go/explore/Service.js | 4 ++++ 4 files changed, 36 insertions(+) diff --git a/backend/explore/explore.go b/backend/explore/explore.go index c8ad0da..950e133 100644 --- a/backend/explore/explore.go +++ b/backend/explore/explore.go @@ -224,6 +224,17 @@ func (e *Service) SimilarArtists(artistMBID string) ([]LBSimilarArtist, error) { return e.lb.SimilarArtists(e.ctx, artistMBID) } +// GetArtistPlayCount returns the total LB listen count for an artist. +// Returns 0 if unknown. +func (e *Service) GetArtistPlayCount(artistMBID string) int { + pop, err := e.lb.ArtistPopularity(e.ctx, []string{artistMBID}) + if err != nil || len(pop) == 0 { + return 0 + } + + return pop[artistMBID] +} + // --------------------------------------------------------------------------- // Cover Art Archive // --------------------------------------------------------------------------- diff --git a/frontend/src/components/explore-artist-details/explore-artist-details.ts b/frontend/src/components/explore-artist-details/explore-artist-details.ts index e7b5bc4..f8afc06 100644 --- a/frontend/src/components/explore-artist-details/explore-artist-details.ts +++ b/frontend/src/components/explore-artist-details/explore-artist-details.ts @@ -8,6 +8,7 @@ import { TopReleaseGroupsForArtist, SimilarArtists, GetArtistImageURL, + GetArtistPlayCount, CheckLibraryMBIDs, } from '@go/explore/Service'; import type { @@ -99,6 +100,7 @@ export class ExploreArtistDetails extends LitElement { @state() private artistImageURL = ''; @state() private similarImageURLs = new Map(); @state() private topSectionExpanded = false; + @state() private artistPlayCount = 0; private libraryMBIDs = new Set(); /* ── Styles ── */ @@ -669,6 +671,9 @@ export class ExploreArtistDetails extends LitElement { this.fetchArtistImage(mbid); } + // Play count is fire-and-forget. + this.fetchArtistPlayCount(mbid); + // Check which release groups are in the local library. this.checkLibrary(); @@ -834,6 +839,17 @@ export class ExploreArtistDetails extends LitElement { } } + private async fetchArtistPlayCount(mbid: string) { + try { + const count = await GetArtistPlayCount(mbid); + if (count > 0) { + this.artistPlayCount = count; + } + } catch { + // Non-critical. + } + } + private async checkLibrary() { const mbids: string[] = []; @@ -1026,6 +1042,9 @@ export class ExploreArtistDetails extends LitElement { ? html`
${this.artist.name}
` : nothing} ${this.renderArtistMeta()} + ${this.artistPlayCount > 0 + ? html`${formatListenCount(this.artistPlayCount)} plays on ListenBrainz` + : nothing}
diff --git a/frontend/wailsjs/go/explore/Service.d.ts b/frontend/wailsjs/go/explore/Service.d.ts index d73cc78..fc4e35c 100755 --- a/frontend/wailsjs/go/explore/Service.d.ts +++ b/frontend/wailsjs/go/explore/Service.d.ts @@ -19,6 +19,8 @@ export function GetArtistImages(arg1:Array):Promise; +export function GetArtistPlayCount(arg1:string):Promise; + export function GetThumbnail(arg1:string,arg2:string,arg3:string):Promise; export function GetThumbnails(arg1:Array):Promise>; diff --git a/frontend/wailsjs/go/explore/Service.js b/frontend/wailsjs/go/explore/Service.js index bd9b699..2a7fb22 100755 --- a/frontend/wailsjs/go/explore/Service.js +++ b/frontend/wailsjs/go/explore/Service.js @@ -34,6 +34,10 @@ export function GetArtistMBID(arg1) { return window['go']['explore']['Service']['GetArtistMBID'](arg1); } +export function GetArtistPlayCount(arg1) { + return window['go']['explore']['Service']['GetArtistPlayCount'](arg1); +} + export function GetThumbnail(arg1, arg2, arg3) { return window['go']['explore']['Service']['GetThumbnail'](arg1, arg2, arg3); }