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:
+34
-5
@@ -1,7 +1,7 @@
|
||||
// Unit tests for the resolver's pure logic (run with `node --test`). Zero-dep.
|
||||
import { test } from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { norm, bandcampSearch, spotifySearch, pickArtist, spotifyResult, searchResult } from "./lib.js";
|
||||
import { norm, bandcampSearch, spotifySearch, pickArtist, spotifyResult, relUrls, mbResult } from "./lib.js";
|
||||
|
||||
test("norm lowercases, trims, NFKC-normalizes", () => {
|
||||
assert.equal(norm(" Cerebral Bore "), "cerebral bore");
|
||||
@@ -39,10 +39,39 @@ test("spotifyResult prefers the direct url, falls back to search", () => {
|
||||
assert.equal(noUrl.spotify, "https://open.spotify.com/search/Devourment");
|
||||
});
|
||||
|
||||
test("searchResult builds spotify + bandcamp search urls", () => {
|
||||
const r = searchResult({ name: "Cerebral Bore" });
|
||||
assert.equal(r.spotify, "https://open.spotify.com/search/Cerebral%20Bore");
|
||||
assert.equal(r.bandcamp, "https://bandcamp.com/search?q=Cerebral%20Bore&item_type=b");
|
||||
test("relUrls picks direct bandcamp + spotify from MB relations, tolerates junk", () => {
|
||||
const relations = [
|
||||
{ url: { resource: "https://cattledecapitation.bandcamp.com/" } },
|
||||
{ url: { resource: "https://open.spotify.com/artist/67ZMMtA88DDO0gTuRrzGjn" } },
|
||||
{ url: { resource: "https://en.wikipedia.org/wiki/Cattle_Decapitation" } },
|
||||
null,
|
||||
{ url: null },
|
||||
];
|
||||
const links = relUrls(relations);
|
||||
assert.equal(links.bandcamp, "https://cattledecapitation.bandcamp.com/");
|
||||
assert.equal(links.spotify, "https://open.spotify.com/artist/67ZMMtA88DDO0gTuRrzGjn");
|
||||
});
|
||||
|
||||
test("relUrls returns nulls when relations absent/empty", () => {
|
||||
assert.deepEqual(relUrls(null), { bandcamp: null, spotify: null });
|
||||
assert.deepEqual(relUrls([]), { bandcamp: null, spotify: null });
|
||||
});
|
||||
|
||||
test("mbResult prefers direct links, falls back to search per-platform", () => {
|
||||
const direct = mbResult(
|
||||
{ name: "Cattle Decapitation" },
|
||||
{ bandcamp: "https://cattledecapitation.bandcamp.com/", spotify: "https://open.spotify.com/artist/x" },
|
||||
);
|
||||
assert.equal(direct.bandcamp, "https://cattledecapitation.bandcamp.com/");
|
||||
assert.equal(direct.spotify, "https://open.spotify.com/artist/x");
|
||||
|
||||
const fallback = mbResult({ name: "Cerebral Bore" }, null);
|
||||
assert.equal(fallback.spotify, "https://open.spotify.com/search/Cerebral%20Bore");
|
||||
assert.equal(fallback.bandcamp, "https://bandcamp.com/search?q=Cerebral%20Bore&item_type=b");
|
||||
|
||||
const partial = mbResult({ name: "X" }, { bandcamp: null, spotify: "https://open.spotify.com/artist/y" });
|
||||
assert.equal(partial.spotify, "https://open.spotify.com/artist/y");
|
||||
assert.match(partial.bandcamp, /bandcamp\.com\/search/);
|
||||
});
|
||||
|
||||
test("link builders url-encode", () => {
|
||||
|
||||
Reference in New Issue
Block a user