feat: show total LB play count on artist detail page
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).
This commit is contained in:
@@ -224,6 +224,17 @@ func (e *Service) SimilarArtists(artistMBID string) ([]LBSimilarArtist, error) {
|
|||||||
return e.lb.SimilarArtists(e.ctx, artistMBID)
|
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
|
// Cover Art Archive
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import {
|
|||||||
TopReleaseGroupsForArtist,
|
TopReleaseGroupsForArtist,
|
||||||
SimilarArtists,
|
SimilarArtists,
|
||||||
GetArtistImageURL,
|
GetArtistImageURL,
|
||||||
|
GetArtistPlayCount,
|
||||||
CheckLibraryMBIDs,
|
CheckLibraryMBIDs,
|
||||||
} from '@go/explore/Service';
|
} from '@go/explore/Service';
|
||||||
import type {
|
import type {
|
||||||
@@ -99,6 +100,7 @@ export class ExploreArtistDetails extends LitElement {
|
|||||||
@state() private artistImageURL = '';
|
@state() private artistImageURL = '';
|
||||||
@state() private similarImageURLs = new Map<string, string>();
|
@state() private similarImageURLs = new Map<string, string>();
|
||||||
@state() private topSectionExpanded = false;
|
@state() private topSectionExpanded = false;
|
||||||
|
@state() private artistPlayCount = 0;
|
||||||
private libraryMBIDs = new Set<string>();
|
private libraryMBIDs = new Set<string>();
|
||||||
|
|
||||||
/* ── Styles ── */
|
/* ── Styles ── */
|
||||||
@@ -669,6 +671,9 @@ export class ExploreArtistDetails extends LitElement {
|
|||||||
this.fetchArtistImage(mbid);
|
this.fetchArtistImage(mbid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Play count is fire-and-forget.
|
||||||
|
this.fetchArtistPlayCount(mbid);
|
||||||
|
|
||||||
// Check which release groups are in the local library.
|
// Check which release groups are in the local library.
|
||||||
this.checkLibrary();
|
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() {
|
private async checkLibrary() {
|
||||||
const mbids: string[] = [];
|
const mbids: string[] = [];
|
||||||
|
|
||||||
@@ -1026,6 +1042,9 @@ export class ExploreArtistDetails extends LitElement {
|
|||||||
? html`<div class="artist-native-name">${this.artist.name}</div>`
|
? html`<div class="artist-native-name">${this.artist.name}</div>`
|
||||||
: nothing}
|
: nothing}
|
||||||
${this.renderArtistMeta()}
|
${this.renderArtistMeta()}
|
||||||
|
${this.artistPlayCount > 0
|
||||||
|
? html`<span class="artist-meta">${formatListenCount(this.artistPlayCount)} plays on ListenBrainz</span>`
|
||||||
|
: nothing}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="content">
|
<div class="content">
|
||||||
|
|||||||
+2
@@ -19,6 +19,8 @@ export function GetArtistImages(arg1:Array<string>):Promise<Record<string, strin
|
|||||||
|
|
||||||
export function GetArtistMBID(arg1:string):Promise<string>;
|
export function GetArtistMBID(arg1:string):Promise<string>;
|
||||||
|
|
||||||
|
export function GetArtistPlayCount(arg1:string):Promise<number>;
|
||||||
|
|
||||||
export function GetThumbnail(arg1:string,arg2:string,arg3:string):Promise<string>;
|
export function GetThumbnail(arg1:string,arg2:string,arg3:string):Promise<string>;
|
||||||
|
|
||||||
export function GetThumbnails(arg1:Array<explore.ThumbnailRequest>):Promise<Record<string, string>>;
|
export function GetThumbnails(arg1:Array<explore.ThumbnailRequest>):Promise<Record<string, string>>;
|
||||||
|
|||||||
@@ -34,6 +34,10 @@ export function GetArtistMBID(arg1) {
|
|||||||
return window['go']['explore']['Service']['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) {
|
export function GetThumbnail(arg1, arg2, arg3) {
|
||||||
return window['go']['explore']['Service']['GetThumbnail'](arg1, arg2, arg3);
|
return window['go']['explore']['Service']['GetThumbnail'](arg1, arg2, arg3);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user