internal

package
v0.1.14 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 8, 2025 License: BSD-3-Clause Imports: 17 Imported by: 0

Documentation

Overview

Package internal defines internal types and functions for online sources.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendImageEdit added in v0.1.8

func AppendImageEdit(edits []seed.Edit, imgURL, relURL string) ([]seed.Edit, error)

AppendImageEdit appends an informational edit with the supplied cover image URL to edits and returns the updated slice. If edits contains a *seed.Release, it may be updated to redirect to the add-cover-art page.

func FetchJSON added in v0.1.10

func FetchJSON(ctx context.Context, url string, dst any, headers map[string]string, cfg *Config) error

FetchJSON fetches the supplied URL and decodes it into dst.

func FetchPage added in v0.1.8

func FetchPage(ctx context.Context, url string, cfg *Config) (*web.Page, error)

FetchPage fetches and parses the supplied URL. If cfg.DisallowNetwork is true, it attempts to load the page from a file in a testdata directory instead, with "https://www.example.org/foo/bar" mapped to "testdata/www.example.org_foo_bar.html".

func HostnameHasDomain added in v0.1.8

func HostnameHasDomain(hostname, domain string) bool

HostnameHasDomain returns true if hostname is within domain. Provider implementations can use this in SupportsHostname.

func MakeEditNote added in v0.1.8

func MakeEditNote(url string) string

MakeEditNote returns an edit note consisting of the supplied URL and a common suffix.

func MakeImageEditNote added in v0.1.9

func MakeImageEditNote(imgURL, relURL string) string

MakeImageEditNote returns an edit note describing an image extracted from a release page.

func ResolveHostname added in v0.1.8

func ResolveHostname(ctx context.Context, hostname string, cfg *Config) ([]string, error)

ResolveHostname resolves the supplied hostname to one or more IP addresses.

func RewriteReleaseTitle added in v0.1.8

func RewriteReleaseTitle(title string, cfg *Config) string

RewriteReleaseTitle rewrites the supplied release title as requested by cfg.

func RewriteTrackTitle added in v0.1.8

func RewriteTrackTitle(title string, cfg *Config) string

RewriteTrackTitle rewrites the supplied track title as requested by cfg. TODO: Should this function take a seed.Track and also extract artists if ExtractTrackArtists is set? I've only seen that be needed for Bandcamp albums so far.

Types

type BadURLError added in v0.1.8

type BadURLError struct {
	// Msg contains the text from the underlying Go error.
	Msg string
	// NoProvider is true if no provider that supports the URL's hostname was found.
	NoProvider bool
	// SeederURL optionally contains the URL of an alternate seeder that might support this URL.
	SeederURL string
}

BadURLError is returned by MakeEdits to indicate that the supplied URL is unsupported.

func NewBadURLError added in v0.1.8

func NewBadURLError(err error) *BadURLError

func (*BadURLError) Error added in v0.1.8

func (e *BadURLError) Error() string

type Config

type Config struct {
	// CountryCode contains the ISO 3166 code of the country that should be used when requesting
	// album data, e.g. "US" or "DE". This is currently only used for the Tidal API.
	CountryCode string
	// CorrectPunctuation indicates that punctuation in track titles should be replaced with
	// preferred characters (https://wiki.musicbrainz.org/User:Jacobbrett/English_Punctuation_Guide).
	CorrectPunctuation bool
	// ExtractTrackArtists indicates that artist names should be extracted from the
	// beginnings of track names, e.g. "Artist - Title". This is currently only used
	// for Bandcamp pages.
	ExtractTrackArtists bool
	// RemoveParens indicates that parenthetical expressions (plus brackets) should be removed from
	// the ends of track titles, e.g. "Title (Deluxe Edition)".
	RemoveParens bool
	// SplitArtists indicates that artist names should be automatically split on separators like
	// " & " and " feat. ". This is currently only used for Bandcamp pages.
	SplitArtists bool

	// DisallowNetwork indicates that network requests should not be made.
	// This can be set by tests.
	DisallowNetwork bool
	// TestdataDir overrides FetchPage's default directory of "testdata" for page
	// data when DisallowNetwork is true.
	TestdataDir string
	// HostnameAddrs provides answers for ResolveHostname to return if DisallowNetwork is true.
	HostnameAddrs map[string][]string
}

Config is passed to Provider implementations to configure their behavior.

type EntityURL added in v0.1.13

type EntityURL struct {
	// contains filtered or unexported fields
}

EntityURL specifies a URL and entity type for GetURLMBIDs to look up.

func ArtistURL added in v0.1.13

func ArtistURL(url, name string) EntityURL

ArtistURL returns an EntityURL to pass to GetURLMBIDs to look up an artist for a URL.

func LabelURL added in v0.1.13

func LabelURL(url, name string) EntityURL

LabelURL returns an EntityURL to pass to GetURLMBIDs to look up a label for a URL.

type Provider

type Provider interface {
	// String returns a short, lowercase human-readable string describing this provider.
	String() string

	// SupportsHostname returns true if the supplied hostname (e.g. "www.bandcamp.com")
	// can be handled by this provider. Callers are responsible for lowercasing the
	// hostname and removing ":port" suffixes.
	SupportsHostname(ctx context.Context, hostname string, cfg *Config) bool

	// MakeEdits generates one or more seeded edits based on a user-supplied URL.
	// A BadURLError should be returned if the requested URL is unsupported so a
	// helpful error message can be displayed to the user.
	MakeEdits(ctx context.Context, url string, db *mbdb.DB, cfg *Config) ([]seed.Edit, error)

	// ExampleURL returns an example URL that can be displayed to the user.
	ExampleURL() string
}

Provider gets information from an online music provider.

type URLMBIDMap added in v0.1.13

type URLMBIDMap map[string]map[mbdb.EntityType]string

func GetURLMBIDs added in v0.1.13

func GetURLMBIDs(ctx context.Context, db *mbdb.DB, entURLs ...EntityURL) URLMBIDMap

GetURLMBIDs returns the best MBID associated with each of the passed-in URLs. The returned map is keyed by URL and then maps from entity type to MBID.

func (URLMBIDMap) GetArtistMBID added in v0.1.13

func (m URLMBIDMap) GetArtistMBID(url string) string

func (URLMBIDMap) GetLabelMBID added in v0.1.13

func (m URLMBIDMap) GetLabelMBID(url string) string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL