Genrekort: bara Utforska + YT; popupen visar kortrutnät med artister och låtar
All checks were successful
build-and-push / build (push) Successful in 13s
All checks were successful
build-and-push / build (push) Successful in 13s
Utforska-popupen renderar två MusicCard-grids (bilder, Hämta, ▶ YT) — genrens låtar berikas nu också med artist-mbid/omslag i backend (cachade uppslag så samma artist inte slås upp dubbelt). Äldre batcher normaliseras i modalen. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01824ZrvG2mDYYrmwqypLNup
This commit is contained in:
@@ -282,15 +282,50 @@ export function suggestEngine({ config, store, lidarr, fetchImpl = fetch }) {
|
||||
async function enrichGenres(rawItems, count, library, likedTitles) {
|
||||
const libSet = new Set(library.map((n) => n.toLowerCase()))
|
||||
const likedSet = new Set(likedTitles.map((t) => t.toLowerCase()))
|
||||
// samma artist slås ofta upp flera gånger (toppartist + låtarnas artister)
|
||||
const hitCache = new Map()
|
||||
const cachedHit = async (name) => {
|
||||
const key = (name ?? '').toLowerCase()
|
||||
if (!hitCache.has(key)) hitCache.set(key, await lidarrArtistHit(name))
|
||||
return hitCache.get(key)
|
||||
}
|
||||
|
||||
const out = []
|
||||
for (const it of rawItems.slice(0, count)) {
|
||||
const topArtists = []
|
||||
for (const name of (it.topArtists ?? []).slice(0, 5)) {
|
||||
if (libSet.has((name ?? '').toLowerCase())) continue
|
||||
const hit = await lidarrArtistHit(name)
|
||||
const hit = await cachedHit(name)
|
||||
if (hit?.inLibrary) continue
|
||||
topArtists.push({ name, mbid: hit?.mbid ?? null, poster: hit?.poster ?? null })
|
||||
topArtists.push({
|
||||
kind: 'artist',
|
||||
name,
|
||||
secondary: '',
|
||||
motivation: '',
|
||||
year: '',
|
||||
mbid: hit?.mbid ?? null,
|
||||
poster: hit?.poster ?? null,
|
||||
inLibrary: false,
|
||||
})
|
||||
}
|
||||
|
||||
const topTracks = []
|
||||
for (const t of (it.topTracks ?? []).filter((t) => !likedSet.has((t.name ?? '').toLowerCase())).slice(0, 5)) {
|
||||
const hit = await cachedHit(t.artist ?? t.name)
|
||||
topTracks.push({
|
||||
kind: 'track',
|
||||
name: t.name,
|
||||
secondary: t.artist ?? '',
|
||||
motivation: '',
|
||||
year: '',
|
||||
mbid: hit?.mbid ?? null,
|
||||
artistMbid: hit?.mbid ?? null,
|
||||
albumMbid: null,
|
||||
poster: hit?.poster ?? null,
|
||||
inLibrary: false,
|
||||
})
|
||||
}
|
||||
|
||||
out.push({
|
||||
kind: 'genre',
|
||||
name: it.name,
|
||||
@@ -301,10 +336,7 @@ export function suggestEngine({ config, store, lidarr, fetchImpl = fetch }) {
|
||||
poster: topArtists.find((a) => a.poster)?.poster ?? null,
|
||||
inLibrary: false,
|
||||
topArtists,
|
||||
topTracks: (it.topTracks ?? [])
|
||||
.filter((t) => !likedSet.has((t.name ?? '').toLowerCase()))
|
||||
.slice(0, 5)
|
||||
.map((t) => ({ name: t.name, artist: t.artist ?? '' })),
|
||||
topTracks,
|
||||
})
|
||||
}
|
||||
return out
|
||||
|
||||
@@ -165,6 +165,10 @@ test('run(genres): artister i prompt, filtrering mot bibliotek + gillat', async
|
||||
'Powerwolf finns i biblioteket och ska filtreras bort',
|
||||
)
|
||||
assert.equal(g.topArtists[0].mbid, 'mbid-x')
|
||||
assert.equal(g.topArtists[0].kind, 'artist', 'toppartister ska vara färdiga kort')
|
||||
assert.equal(g.topTracks[0].kind, 'track')
|
||||
assert.equal(g.topTracks[0].artistMbid, 'mbid-x', 'låtar i genren berikas med artist-mbid')
|
||||
assert.equal(g.topTracks[0].poster, 'http://img/s.jpg', 'låtar i genren får omslag')
|
||||
assert.equal(g.poster, 'http://img/s.jpg', 'genrekortet lånar första toppartistens omslag')
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user