The first public release of Fabled Minstrel #158
@@ -210,15 +210,11 @@ func run() error {
|
|||||||
acoustIDLookup := library.NewAcoustIDLookupWorker(pool, logger.With("component", "acoustid_lookup"),
|
acoustIDLookup := library.NewAcoustIDLookupWorker(pool, logger.With("component", "acoustid_lookup"),
|
||||||
acoustIDSettings, acoustIDClient)
|
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
|
// Swap in the production User-Agent + MinPeriod on the registered
|
||||||
// MBCAA provider. init() registered it with default config; this
|
// MBCAA provider. init() registered it with default config; this
|
||||||
// updates the running instance.
|
// updates the running instance.
|
||||||
coverart.NewMBCAAProviderFromConfig(coverart.FetcherConfig{
|
coverart.NewMBCAAProviderFromConfig(coverart.FetcherConfig{
|
||||||
UserAgent: fmt.Sprintf("Minstrel/dev (%s)", contact),
|
UserAgent: buildinfo.UserAgent(cfg.Library.ContactEmail),
|
||||||
MinPeriod: time.Second,
|
MinPeriod: time.Second,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -30,6 +30,8 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"git.fabledsword.com/bvandeusen/minstrel/internal/buildinfo"
|
||||||
)
|
)
|
||||||
|
|
||||||
// DefaultBaseURL is the lookup endpoint.
|
// DefaultBaseURL is the lookup endpoint.
|
||||||
@@ -45,7 +47,6 @@ const (
|
|||||||
// bodyLimit caps the response read. A lookup with meta=recordings for a
|
// bodyLimit caps the response read. A lookup with meta=recordings for a
|
||||||
// popular song runs to tens of kilobytes.
|
// popular song runs to tens of kilobytes.
|
||||||
bodyLimit = 2 << 20
|
bodyLimit = 2 << 20
|
||||||
userAgent = "Minstrel ( https://git.fabledsword.com/bvandeusen/minstrel )"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// The server's error codes that the worker treats differently.
|
// 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-Type", "application/x-www-form-urlencoded")
|
||||||
req.Header.Set("Content-Encoding", "gzip")
|
req.Header.Set("Content-Encoding", "gzip")
|
||||||
req.Header.Set("Accept", "application/json")
|
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)
|
resp, err := c.http.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -29,3 +29,19 @@ var Channel = "local"
|
|||||||
|
|
||||||
// Started is when this process started, for the admin Overview's uptime.
|
// Started is when this process started, for the admin Overview's uptime.
|
||||||
var Started = time.Now()
|
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 + " )"
|
||||||
|
}
|
||||||
|
|||||||
@@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,15 +10,13 @@ import (
|
|||||||
"net/url"
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"git.fabledsword.com/bvandeusen/minstrel/internal/buildinfo"
|
||||||
)
|
)
|
||||||
|
|
||||||
// DefaultBaseURL is the public MusicBrainz web service.
|
// DefaultBaseURL is the public MusicBrainz web service.
|
||||||
const DefaultBaseURL = "https://musicbrainz.org/ws/2"
|
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
|
// DefaultTimeout bounds one request. A browse page with track
|
||||||
// lists is the slowest thing asked for.
|
// lists is the slowest thing asked for.
|
||||||
const DefaultTimeout = 20 * time.Second
|
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)
|
return false, fmt.Errorf("musicbrainz: build request: %w", err)
|
||||||
}
|
}
|
||||||
req.Header.Set("Accept", "application/json")
|
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)
|
resp, err := c.httpClient().Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"git.fabledsword.com/bvandeusen/minstrel/internal/buildinfo"
|
||||||
"git.fabledsword.com/bvandeusen/minstrel/internal/musicbrainz"
|
"git.fabledsword.com/bvandeusen/minstrel/internal/musicbrainz"
|
||||||
"git.fabledsword.com/bvandeusen/minstrel/internal/providers"
|
"git.fabledsword.com/bvandeusen/minstrel/internal/providers"
|
||||||
)
|
)
|
||||||
@@ -16,8 +17,6 @@ import (
|
|||||||
var mbBaseURL = "https://musicbrainz.org/ws/2"
|
var mbBaseURL = "https://musicbrainz.org/ws/2"
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// mbUserAgent identifies the app — MusicBrainz rejects requests without one.
|
|
||||||
mbUserAgent = musicbrainz.UserAgent
|
|
||||||
// artistTagWeightFactor down-weights artist-level fallback tags relative
|
// artistTagWeightFactor down-weights artist-level fallback tags relative
|
||||||
// to recording-specific tags — the artist's overall character is a coarser
|
// to recording-specific tags — the artist's overall character is a coarser
|
||||||
// signal than a tag on the exact recording.
|
// signal than a tag on the exact recording.
|
||||||
@@ -38,8 +37,9 @@ type musicbrainzProvider struct {
|
|||||||
func init() {
|
func init() {
|
||||||
Register(&musicbrainzProvider{
|
Register(&musicbrainzProvider{
|
||||||
client: providers.NewHTTPClient(providers.HTTPOptions{
|
client: providers.NewHTTPClient(providers.HTTPOptions{
|
||||||
Name: "musicbrainz",
|
Name: "musicbrainz",
|
||||||
UserAgent: mbUserAgent,
|
// MusicBrainz rejects requests without one.
|
||||||
|
UserAgent: buildinfo.UserAgent(""),
|
||||||
HTTPClient: &http.Client{Timeout: 30 * time.Second},
|
HTTPClient: &http.Client{Timeout: 30 * time.Second},
|
||||||
// MusicBrainz's 1 request/second is per address: share it with
|
// MusicBrainz's 1 request/second is per address: share it with
|
||||||
// the release catalogue.
|
// the release catalogue.
|
||||||
|
|||||||
Reference in New Issue
Block a user