feat: direct Spotify/Bandcamp links via MusicBrainz url-relations (task/odesli-direct-links)
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>
This commit is contained in:
+17
-6
@@ -26,9 +26,20 @@ export const spotifyResult = (hit) => ({
|
||||
bandcamp: bandcampSearch(hit.name),
|
||||
});
|
||||
|
||||
// Link object for a confirmed MusicBrainz hit (search urls — MB gives no platform ids).
|
||||
export const searchResult = (hit) => ({
|
||||
name: hit.name,
|
||||
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),
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user