chore: remove code left from acquisition and Discover suggestions, and uncalled queries

Nothing reached any of it:
- MusicBrainz search (artists, albums, songs), artist lookups and the
  query escaping they used. The release-group lookups the duplicate
  resolver uses stay.
- Release-group covers, and artist-level tags for artists not in the
  library.
- Nine named queries with no caller (CountTracksByArtist went with the
  previous commit), two of them describing request-progress reporting.

The MusicBrainz client's retry and not-found tests now drive the
release-group lookup.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-25 22:02:00 -05:00
co-authored by Claude Opus 5.5
parent 987c2a68fa
commit 14aa3dcd5e
28 changed files with 10 additions and 817 deletions
-185
View File
@@ -7,16 +7,6 @@ import (
"strings"
)
// Artist is a MusicBrainz artist.
type Artist struct {
MBID string
Name string
SortName string
Disambiguation string
Type string // Person, Group, Orchestra, …; may be empty
Country string
}
// ReleaseGroup is what a person calls an album: one work, released any
// number of times.
type ReleaseGroup struct {
@@ -31,14 +21,6 @@ type ReleaseGroup struct {
ArtistMBIDs []string
}
// Year is the first release's year, or "".
func (g ReleaseGroup) Year() string {
if len(g.FirstReleaseDate) >= 4 {
return g.FirstReleaseDate[:4]
}
return ""
}
// Release is one issue of a release group: a pressing, an edition, a
// digital release, each with its own track list.
type Release struct {
@@ -98,18 +80,6 @@ type Track struct {
RecordingMBID string
}
// Recording is a piece of audio, as a search returns it.
type Recording struct {
MBID string
Title string
LengthMs int
ArtistCredit string
ArtistMBIDs []string
// ReleaseGroup is the group the recording is best known from: the first
// official album it appears on, else the first release listed.
ReleaseGroup ReleaseGroup
}
// --- wire shapes ---
type wireCredit struct {
@@ -138,19 +108,6 @@ func credit(cs []wireCredit) (string, []string) {
return b.String(), ids
}
type wireArtist struct {
ID string `json:"id"`
Name string `json:"name"`
SortName string `json:"sort-name"`
Disambiguation string `json:"disambiguation"`
Type string `json:"type"`
Country string `json:"country"`
}
func (w wireArtist) artist() Artist {
return Artist{MBID: w.ID, Name: w.Name, SortName: w.SortName, Disambiguation: w.Disambiguation, Type: w.Type, Country: w.Country}
}
type wireReleaseGroup struct {
ID string `json:"id"`
Title string `json:"title"`
@@ -192,7 +149,6 @@ type wireRelease struct {
Format string `json:"format"`
Tracks []wireTrack `json:"tracks"`
} `json:"media"`
ReleaseGroup *wireReleaseGroup `json:"release-group"`
}
func (w wireRelease) release() Release {
@@ -217,149 +173,8 @@ func (w wireRelease) release() Release {
return r
}
// --- searches ---
// SearchArtists finds artists by name or alias.
func (c *Client) SearchArtists(ctx context.Context, text string, limit int) ([]Artist, error) {
var resp struct {
Artists []wireArtist `json:"artists"`
}
q := url.Values{"query": {fieldQuery(text, "artist", "alias")}, "limit": {searchLimit(limit)}}
if err := c.get(ctx, "/artist", q, &resp); err != nil {
return nil, err
}
out := make([]Artist, 0, len(resp.Artists))
for _, a := range resp.Artists {
out = append(out, a.artist())
}
return out, nil
}
// SearchReleaseGroups finds albums by title or by artist, so "signal tower ok
// computer" and "ok calculator" both find OK Calculator.
func (c *Client) SearchReleaseGroups(ctx context.Context, text string, limit int) ([]ReleaseGroup, error) {
var resp struct {
ReleaseGroups []wireReleaseGroup `json:"release-groups"`
}
q := url.Values{"query": {fieldQuery(text, "releasegroup", "artist")}, "limit": {searchLimit(limit)}}
if err := c.get(ctx, "/release-group", q, &resp); err != nil {
return nil, err
}
out := make([]ReleaseGroup, 0, len(resp.ReleaseGroups))
for _, g := range resp.ReleaseGroups {
out = append(out, g.group())
}
return out, nil
}
// SearchReleaseGroupsBy finds an artist's albums by title: both must
// match, where SearchReleaseGroups takes either. It is for naming an album
// already in hand, not for a person's search box.
func (c *Client) SearchReleaseGroupsBy(ctx context.Context, artist, title string, limit int) ([]ReleaseGroup, error) {
var resp struct {
ReleaseGroups []wireReleaseGroup `json:"release-groups"`
}
query := "releasegroup:(" + Escape(strings.TrimSpace(title)) + ") AND artist:(" + Escape(strings.TrimSpace(artist)) + ")"
q := url.Values{"query": {query}, "limit": {searchLimit(limit)}}
if err := c.get(ctx, "/release-group", q, &resp); err != nil {
return nil, err
}
out := make([]ReleaseGroup, 0, len(resp.ReleaseGroups))
for _, g := range resp.ReleaseGroups {
out = append(out, g.group())
}
return out, nil
}
// SearchRecordings finds songs by title or by artist.
func (c *Client) SearchRecordings(ctx context.Context, text string, limit int) ([]Recording, error) {
var resp struct {
Recordings []struct {
ID string `json:"id"`
Title string `json:"title"`
Length *int `json:"length"`
ArtistCredit []wireCredit `json:"artist-credit"`
Releases []wireRelease `json:"releases"`
} `json:"recordings"`
}
q := url.Values{"query": {fieldQuery(text, "recording", "artist")}, "limit": {searchLimit(limit)}}
if err := c.get(ctx, "/recording", q, &resp); err != nil {
return nil, err
}
out := make([]Recording, 0, len(resp.Recordings))
for _, r := range resp.Recordings {
name, ids := credit(r.ArtistCredit)
rec := Recording{MBID: r.ID, Title: r.Title, ArtistCredit: name, ArtistMBIDs: ids}
if r.Length != nil {
rec.LengthMs = *r.Length
}
rec.ReleaseGroup = bestKnownFrom(r.Releases)
out = append(out, rec)
}
return out, nil
}
// bestKnownFrom picks the release group a recording should be filed under
// in a search result: the first official album, else the first release.
func bestKnownFrom(releases []wireRelease) ReleaseGroup {
var first *wireReleaseGroup
for _, r := range releases {
if r.ReleaseGroup == nil || r.ReleaseGroup.ID == "" {
continue
}
if first == nil {
first = r.ReleaseGroup
}
if r.Status == "Official" && r.ReleaseGroup.PrimaryType == "Album" && len(r.ReleaseGroup.SecondaryTypes) == 0 {
return r.ReleaseGroup.group()
}
}
if first == nil {
return ReleaseGroup{}
}
return first.group()
}
// --- lookups and browses ---
// Artist looks one artist up by MBID.
func (c *Client) Artist(ctx context.Context, mbid string) (Artist, error) {
var w wireArtist
if err := c.get(ctx, "/artist/"+url.PathEscape(mbid), nil, &w); err != nil {
return Artist{}, err
}
if w.ID == "" {
return Artist{}, ErrBadResponse
}
return w.artist(), nil
}
// ArtistReleaseGroups lists every release group the artist is credited on,
// paging through MusicBrainz's browse.
func (c *Client) ArtistReleaseGroups(ctx context.Context, artistMBID string) ([]ReleaseGroup, error) {
var out []ReleaseGroup
for page := 0; page < maxPages; page++ {
var resp struct {
Count int `json:"release-group-count"`
ReleaseGroups []wireReleaseGroup `json:"release-groups"`
}
q := url.Values{
"artist": {artistMBID}, "inc": {"artist-credits"},
"limit": {strconv.Itoa(pageSize)}, "offset": {strconv.Itoa(len(out))},
}
if err := c.get(ctx, "/release-group", q, &resp); err != nil {
return nil, err
}
for _, g := range resp.ReleaseGroups {
out = append(out, g.group())
}
if len(resp.ReleaseGroups) == 0 || len(out) >= resp.Count {
break
}
}
return out, nil
}
// ReleaseGroupReleases lists every release of a release group with its
// media and track lists.
func (c *Client) ReleaseGroupReleases(ctx context.Context, groupMBID string) ([]Release, error) {