discover

package
v0.2.4-draft Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2026 License: MIT Imports: 14 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package discover finds a station's manifest from a homepage or a stream URL (SPECIFICATION.md section 3) and applies the verification rule of section 4.3, with the fetching limits of section 10.2.

Index

Constants

View Source
const (
	DefaultTimeout      = 10 * time.Second
	DefaultMaxBody      = manifest.MaxManifestBytes
	DefaultMaxRedirects = 5
)

Defaults from section 10.2.

View Source
const (
	// ManifestRel is the link relation of the HTTP Link header (section 3, item 3).
	ManifestRel = "radio-manifest"
	// ManifestType is the media type of the HTML link (section 3, item 2).
	ManifestType = "application/radio-manifest+json"
	// WellKnownPath is the well-known address (section 3, item 1).
	WellKnownPath = "/.well-known/radio-manifest.json"
)

Variables

View Source
var (
	ErrNoManifest         = errors.New("no manifest found")
	ErrTooLarge           = errors.New("response body exceeds the size limit")
	ErrTooManyRedirects   = errors.New("too many redirects")
	ErrInsecureRedirect   = errors.New("redirect to http is not allowed in the production tier")
	ErrInsecureURL        = errors.New("address must use https in the production tier")
	ErrDevelopmentAddress = errors.New("development-tier address refused (section 10.2)")
	ErrGUIDMismatch       = errors.New("guid differs between the fetched copy and the manifestUrl copy (section 4.2)")
	ErrBadScheme          = errors.New("only http and https addresses are supported")
)

Errors returned by discovery.

Functions

This section is empty.

Types

type Client

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

Client performs discovery.

func New

func New(cfg Config) *Client

New returns a Client for cfg.

func (*Client) Discover

func (c *Client) Discover(ctx context.Context, raw string) (*Result, error)

Discover accepts a homepage or a stream URL. It probes the URL with HEAD: a stream-like answer (audio or playlist content type, icy headers, or a radio-manifest Link header) takes the stream path, anything else the homepage path. The call is bounded by Config.Timeout.

func (*Client) FromHomepage

func (c *Client) FromHomepage(ctx context.Context, homepage string) (*Result, error)

FromHomepage discovers a manifest from a homepage URL: the HTML link first (it wins when the two disagree, section 3), then the well-known address.

func (*Client) FromStream

func (c *Client) FromStream(ctx context.Context, streamURL string) (*Result, error)

FromStream discovers a manifest from a stream URL: the HTTP Link header (HEAD, then a one-byte ranged GET whose body is never read), then an icy-url header taken as a homepage. The stream body is never downloaded.

type Config

type Config struct {
	// HTTPClient is optional; its Transport is used, its CheckRedirect and
	// Timeout are replaced. When nil a client with a guarded dialer is built.
	HTTPClient *http.Client
	// Timeout bounds one whole discovery call (default 10 s).
	Timeout time.Duration
	// MaxBody is the largest body read (default 256 KiB).
	MaxBody int64
	// MaxRedirects is the most redirects followed (default 5).
	MaxRedirects int
	// Development configures the client for development: http is allowed for
	// development hosts and development addresses may be contacted.
	Development bool
	// AllowPrivate lets the client contact development-tier addresses without
	// relaxing the https rules; intended for tests with TLS servers on loopback.
	AllowPrivate bool
	// UserAgent defaults to "radio2-discover".
	UserAgent string
}

Config controls a Client. The zero value is the production tier with the limits of section 10.2.

type Result

type Result struct {
	Input       string
	Kind        string // "homepage" or "stream"
	ManifestURL string // the manifest's own manifestUrl once fetched
	FoundAt     string // where the manifest address was first found
	Via         Via
	// ICYHomepage is the homepage taken from an icy-url header, when used.
	ICYHomepage string
	Manifest    *manifest.Manifest
	// Problems are validation findings on the fetched manifest (informational:
	// a consumer ignores unknown members, so they do not stop discovery).
	Problems []manifest.Problem
	Verdict
}

Result is the outcome of a discovery.

type StatusError

type StatusError struct {
	URL        string
	Code       int
	RetryAfter string
}

StatusError is returned for a non-200 answer. A 503 or a network failure is not removal (section 4.4); 404 and 410 are.

func (*StatusError) Error

func (e *StatusError) Error() string

func (*StatusError) Removed

func (e *StatusError) Removed() bool

Removed reports whether the status means the station no longer publishes at that address (404 or 410).

type Verdict

type Verdict struct {
	// OriginVerified: manifestUrl is the well-known address on the homepage
	// origin, or the homepage's HTML link names exactly manifestUrl.
	OriginVerified bool
	// Verified: OriginVerified, https for homepage and manifestUrl, and a
	// production-tier manifest. Only a verified manifest may be listed publicly.
	Verified bool
	// By is "well-known" or "html-link" when OriginVerified.
	By string
	// Reasons explain why a manifest is not verified.
	Reasons []string
}

Verdict is the outcome of the verification rule of section 4.3.

func Verify

func Verify(m *manifest.Manifest, homepageLink string) Verdict

Verify applies section 4.3 to a manifest. homepageLink is the href of the radio-manifest link in the manifest's homepage document, resolved to an absolute URL, or "" when the page has none (or was not read).

type Via

type Via string

Via names how the manifest address was found.

const (
	ViaLinkHeader Via = "link-header" // HTTP Link header of a stream
	ViaHTMLLink   Via = "html-link"   // <link rel="alternate"> of the homepage
	ViaWellKnown  Via = "well-known"  // /.well-known/radio-manifest.json
)

Jump to

Keyboard shortcuts

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