The Odesli/Songlink API rejects artist URLs (405 UNSUPPORTED_URL — it is song/album only), so the planned Odesli hop is not viable for artist linking. Pivoted to MusicBrainz `inc=url-rels`, which returns the artist's official Bandcamp + Spotify URLs directly, zero-cred: - service/lib.js: relUrls() extracts direct bandcamp/spotify from MB relations; mbResult() prefers them, falls back to search URLs per-platform (replaces searchResult). - service/resolver.js: viaMusicBrainz now does search -> url-rels enrichment (both throttled through one gate); resolveOne calls it directly. - service/lib.test.js: +3 tests (relUrls + mbResult); 9 total, green. - README: document the direct-link behavior. Verified zero-cred end to end: "Cattle Decapitation" -> open.spotify.com/artist/... + cattledecapitation.bandcamp.com/ (both direct, not search); nonsense -> null. Source: task/odesli-direct-links (objective/linker-improvements); approach changed from Odesli to MB url-rels after the API probe; goal (direct Bandcamp) achieved. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
46 lines
2.0 KiB
JavaScript
46 lines
2.0 KiB
JavaScript
// Pure, side-effect-free helpers for the resolver. Kept separate from resolver.js
|
|
// (which has the HTTP-server side effect) so they can be unit-tested with `node --test`
|
|
// without starting a server. The artist-match precision lever lives here.
|
|
|
|
export const norm = (s) => String(s).normalize("NFKC").trim().toLowerCase();
|
|
|
|
export const bandcampSearch = (n) => `https://bandcamp.com/search?q=${encodeURIComponent(n)}&item_type=b`;
|
|
export const spotifySearch = (n) => `https://open.spotify.com/search/${encodeURIComponent(n)}`;
|
|
|
|
// The precision lever: return the result whose name matches the candidate
|
|
// case-insensitively, else null. `minScore` (MusicBrainz) additionally requires a
|
|
// confidence score. Tolerates null/garbage items.
|
|
export function pickArtist(name, items, { minScore = null } = {}) {
|
|
const want = norm(name);
|
|
return (
|
|
(items ?? []).find(
|
|
(a) => a && norm(a.name) === want && (minScore == null || (a.score ?? 0) >= minScore),
|
|
) ?? null
|
|
);
|
|
}
|
|
|
|
// Link object for a confirmed Spotify hit (direct artist url when present, else search).
|
|
export const spotifyResult = (hit) => ({
|
|
name: hit.name,
|
|
spotify: hit.external_urls?.spotify ?? spotifySearch(hit.name),
|
|
bandcamp: bandcampSearch(hit.name),
|
|
});
|
|
|
|
// Extract direct links from a MusicBrainz artist's url-relations (zero-cred: MB stores
|
|
// official Bandcamp / streaming URLs). Either field may be null.
|
|
export function relUrls(relations) {
|
|
const urls = (relations ?? []).map((r) => r && r.url && r.url.resource).filter(Boolean);
|
|
const find = (host) => urls.find((u) => u.includes(host)) ?? null;
|
|
return { bandcamp: find("bandcamp.com"), spotify: find("open.spotify.com") };
|
|
}
|
|
|
|
// Link object for a confirmed MusicBrainz hit: prefer the direct url-rel links, fall back
|
|
// to search urls when MB has no relation for that platform.
|
|
export function mbResult(hit, links) {
|
|
return {
|
|
name: hit.name,
|
|
spotify: links?.spotify ?? spotifySearch(hit.name),
|
|
bandcamp: links?.bandcamp ?? bandcampSearch(hit.name),
|
|
};
|
|
}
|