Documentation
¶
Overview ¶
Package match turns a line of text like "Miles Davis - Doxy" into a Spotify search query, and picks the best track from what the search returns.
This exists because of two February 2026 changes pulling in the same direction. The search limit dropped from 50 to 10, and the track object lost `popularity` — which used to be how you told the canonical release from six karaoke covers of it. Ranking therefore has to happen here, on the names, with only ten candidates to work from.
The scoring is deliberately conservative: it would rather mark a match uncertain and let a human look than quietly add the tribute-band version.
Index ¶
Constants ¶
const ConfidentScore = 0.85
ConfidentScore is the threshold at or above which a match is taken as correct without asking. Tuned so that a difference in bracketed suffix ("Remastered", "feat. …") still clears it, while a different song by the right artist does not.
Variables ¶
This section is empty.
Functions ¶
func Normalize ¶
Normalize folds a name to a comparable form: lowercase, without diacritics, punctuation or runs of whitespace.
func Score ¶
Score rates a candidate against the query, between 0 and 1.
Title carries more weight than artist because a wrong title is always the wrong track, whereas an artist mismatch is often just a credit the query left out — a featured guest, or "Simon & Garfunkel" against "Paul Simon".
func SortedQualifiers ¶
func SortedQualifiers() []string
SortedQualifiers returns the qualifier list, for the tests and for `--help` to show what gets ignored when comparing names.
Types ¶
type Named ¶
Named is the shape Best needs from a candidate: a title and its artists. The spotify package's Track satisfies it, and so does a test fixture, which keeps this package free of the API types.
type Query ¶
type Query struct {
// Artist is the artist as written, empty when the line named only a title.
Artist string
// Title is the track title as written.
Title string
// Raw is the original line, used verbatim when it already looks like a
// hand-written Spotify query.
Raw string
// Literal marks a line the caller wrote as a Spotify query itself, which is
// passed through untouched.
Literal bool
}
Query is a parsed request for one track.
func ParseLine ¶
ParseLine reads one input line into a Query.
"Artist - Title" is the convention every playlist export uses, so that is the assumed order. A line already carrying a Spotify field filter is passed through as written, on the grounds that someone who typed `artist:` knows what they meant better than this heuristic does.
func (Query) SearchQuery ¶
SearchQuery renders the query for GET /search.
Field filters rather than a bare string: `track:"Doxy" artist:"Miles Davis"` keeps the artist from being matched against the title and back. That matters more than it used to, with only ten results to spend.
type Result ¶
type Result struct {
// Index is the candidate's position in the search results. Kept because
// Spotify's own ordering is the only relevance signal left once popularity is
// gone, so it breaks ties.
Index int
// Score is between 0 and 1.
Score float64
// Confident reports whether Score cleared ConfidentScore.
Confident bool
}
Result is a scored candidate.