Source: human-feedback note 01KVDYV3A35B57N15CRBQDXPCH (project/reddit-spotify-linker, 2026-06-18) — "remove the musicbrainz integration and just use spotify"; a google search for "<name> bandcamp" fallback; and "would a local llm be better able to categorise these ... include instructions for running something suitable via ollama (16GB M2)". - Remove MusicBrainz entirely (viaMusicBrainz + url-rels + rate-gate; lib relUrls/mbResult). Spotify is now the only music API; it both gates by exact-name match and supplies the direct artist link. - Optional ollama LLM gate (OLLAMA_URL enables it, OLLAMA_MODEL default qwen2.5:3b) called over plain HTTP -> stays zero npm-dep. It classifies which candidates are real artists/albums (the matching-quality lever). Pure prompt/parse logic in new llm.js (unit-tested in llm.test.js); the fetch + resolveAll gate wiring live in resolver.js. - A confirmed name links to its direct Spotify page when available, else a Google search for "<name> bandcamp". New "google" primary platform rendered by the extension (styles.css blue accent + platform-aware link title in content.js). - README: drop MusicBrainz; document the two gates + a runnable local-LLM setup for a 16GB MacBook M2. AGENTS.md: flip the old "no ML/NER" standing decision per the human override. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
43 lines
1.9 KiB
JavaScript
43 lines
1.9 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();
|
|
|
|
// Fallback link when we have no direct Spotify page: a Google search biased at Bandcamp,
|
|
// which surfaces the artist's Bandcamp page (when it exists) plus general results.
|
|
export const googleSearch = (n) => `https://www.google.com/search?q=${encodeURIComponent(`${n} bandcamp`)}`;
|
|
|
|
// The precision lever: return the item whose name matches the candidate
|
|
// case-insensitively, else null. Tolerates null/garbage items.
|
|
export function pickArtist(name, items) {
|
|
const want = norm(name);
|
|
return (items ?? []).find((a) => a && norm(a.name) === want) ?? null;
|
|
}
|
|
|
|
// A "/search" url means we don't have a direct artist page (just a search fallback).
|
|
export const isSearchUrl = (url) => typeof url === "string" && url.includes("/search");
|
|
|
|
// True for http/https URLs only — reject javascript:, ftp:, garbage. The Spotify
|
|
// external_url flows into an injected link's href, so validate it defensively.
|
|
export function isHttpUrl(u) {
|
|
try {
|
|
const p = new URL(u).protocol;
|
|
return p === "https:" || p === "http:";
|
|
} catch {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
// Build the single link to show for a confirmed name. Prefer the direct Spotify artist
|
|
// url (validated http(s), not a /search url); otherwise fall back to a Google→Bandcamp
|
|
// search. `primary` is what the extension renders ({ platform, url }).
|
|
export function linkResult(name, spotifyUrl) {
|
|
const direct = spotifyUrl && isHttpUrl(spotifyUrl) && !isSearchUrl(spotifyUrl) ? spotifyUrl : null;
|
|
if (direct) {
|
|
return { name, spotify: direct, primary: { platform: "spotify", url: direct } };
|
|
}
|
|
const url = googleSearch(name);
|
|
return { name, google: url, primary: { platform: "google", url } };
|
|
}
|