internal

package
v0.1.10 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2024 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 GetArtistMBIDFromURL

func GetArtistMBIDFromURL(ctx context.Context, db *mbdb.DB, url, name string) string

GetArtistMBIDFromURL attempts to find the MBID of the artist corresponding to url. name should contain the artist name as seen online.

func GetLabelMBIDFromURL

func GetLabelMBIDFromURL(ctx context.Context, db *mbdb.DB, url, name string) string

GetLabelMBIDFromURL attempts to find the MBID of the label corresponding to url. name should contain the label name as seen online.

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 {
	// contains filtered or unexported fields
}

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 Provider

type Provider interface {
	// 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.
	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.

Jump to

Keyboard shortcuts

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