The first public release of Fabled Minstrel #158

Merged
bvandeusen merged 256 commits from dev into main 2026-12-03 21:41:58 -05:00
6 changed files with 47 additions and 16 deletions
Showing only changes of commit 4587b0a038 - Show all commits
+1 -5
View File
@@ -210,15 +210,11 @@ func run() error {
acoustIDLookup := library.NewAcoustIDLookupWorker(pool, logger.With("component", "acoustid_lookup"),
acoustIDSettings, acoustIDClient)
contact := cfg.Library.ContactEmail
if contact == "" {
contact = "https://git.fabledsword.com/bvandeusen/minstrel"
}
// Swap in the production User-Agent + MinPeriod on the registered
// MBCAA provider. init() registered it with default config; this
// updates the running instance.
coverart.NewMBCAAProviderFromConfig(coverart.FetcherConfig{
UserAgent: fmt.Sprintf("Minstrel/dev (%s)", contact),
UserAgent: buildinfo.UserAgent(cfg.Library.ContactEmail),
MinPeriod: time.Second,
})
+3 -2
View File
@@ -30,6 +30,8 @@ import (
"strconv"
"sync"
"time"
"git.fabledsword.com/bvandeusen/minstrel/internal/buildinfo"
)
// DefaultBaseURL is the lookup endpoint.
@@ -45,7 +47,6 @@ const (
// bodyLimit caps the response read. A lookup with meta=recordings for a
// popular song runs to tens of kilobytes.
bodyLimit = 2 << 20
userAgent = "Minstrel ( https://git.fabledsword.com/bvandeusen/minstrel )"
)
// The server's error codes that the worker treats differently.
@@ -127,7 +128,7 @@ func (c *Client) Lookup(ctx context.Context, apiKey, fingerprint string, duratio
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
req.Header.Set("Content-Encoding", "gzip")
req.Header.Set("Accept", "application/json")
req.Header.Set("User-Agent", userAgent)
req.Header.Set("User-Agent", buildinfo.UserAgent(""))
resp, err := c.http.Do(req)
if err != nil {
+16
View File
@@ -29,3 +29,19 @@ var Channel = "local"
// Started is when this process started, for the admin Overview's uptime.
var Started = time.Now()
// ProjectURL is where Minstrel's source lives. Outside services that ask a
// client to say how to reach its maker are pointed here.
const ProjectURL = "https://git.fabledsword.com/bvandeusen/minstrel"
// UserAgent is how Minstrel names itself to outside services (MusicBrainz,
// the Cover Art Archive, AcoustID), which ask for the app's name, its
// version and a contact, so a release can be told from a dev build in
// their logs. contact is the operator's address when one is configured;
// without one the project's URL stands in.
func UserAgent(contact string) string {
if contact == "" {
contact = ProjectURL
}
return "Minstrel/" + Version + " ( " + contact + " )"
}
+19
View File
@@ -0,0 +1,19 @@
package buildinfo
import "testing"
// The User-Agent carries the build's own version, so MusicBrainz and the
// others can tell a release from a dev build, and a contact: the operator's
// when set, the project's otherwise.
func TestUserAgent_NamesTheVersionAndAContact(t *testing.T) {
was := Version
t.Cleanup(func() { Version = was })
Version = "2026.11.28.1700"
if got, want := UserAgent("admin@example.com"), "Minstrel/2026.11.28.1700 ( admin@example.com )"; got != want {
t.Errorf("with a contact: %q, want %q", got, want)
}
if got, want := UserAgent(""), "Minstrel/2026.11.28.1700 ( "+ProjectURL+" )"; got != want {
t.Errorf("without one: %q, want %q", got, want)
}
}
+4 -5
View File
@@ -10,15 +10,13 @@ import (
"net/url"
"strings"
"time"
"git.fabledsword.com/bvandeusen/minstrel/internal/buildinfo"
)
// DefaultBaseURL is the public MusicBrainz web service.
const DefaultBaseURL = "https://musicbrainz.org/ws/2"
// UserAgent identifies Minstrel. MusicBrainz refuses requests without a
// descriptive one.
const UserAgent = "Minstrel/1.0 ( https://git.fabledsword.com/bvandeusen/minstrel )"
// DefaultTimeout bounds one request. A browse page with track
// lists is the slowest thing asked for.
const DefaultTimeout = 20 * time.Second
@@ -130,7 +128,8 @@ func (c *Client) once(ctx context.Context, full string, out any) (retry bool, er
return false, fmt.Errorf("musicbrainz: build request: %w", err)
}
req.Header.Set("Accept", "application/json")
req.Header.Set("User-Agent", UserAgent)
// MusicBrainz refuses requests without a descriptive User-Agent.
req.Header.Set("User-Agent", buildinfo.UserAgent(""))
resp, err := c.httpClient().Do(req)
if err != nil {
+4 -4
View File
@@ -8,6 +8,7 @@ import (
"sync/atomic"
"time"
"git.fabledsword.com/bvandeusen/minstrel/internal/buildinfo"
"git.fabledsword.com/bvandeusen/minstrel/internal/musicbrainz"
"git.fabledsword.com/bvandeusen/minstrel/internal/providers"
)
@@ -16,8 +17,6 @@ import (
var mbBaseURL = "https://musicbrainz.org/ws/2"
const (
// mbUserAgent identifies the app — MusicBrainz rejects requests without one.
mbUserAgent = musicbrainz.UserAgent
// artistTagWeightFactor down-weights artist-level fallback tags relative
// to recording-specific tags — the artist's overall character is a coarser
// signal than a tag on the exact recording.
@@ -38,8 +37,9 @@ type musicbrainzProvider struct {
func init() {
Register(&musicbrainzProvider{
client: providers.NewHTTPClient(providers.HTTPOptions{
Name: "musicbrainz",
UserAgent: mbUserAgent,
Name: "musicbrainz",
// MusicBrainz rejects requests without one.
UserAgent: buildinfo.UserAgent(""),
HTTPClient: &http.Client{Timeout: 30 * time.Second},
// MusicBrainz's 1 request/second is per address: share it with
// the release catalogue.