radio

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2026 License: AGPL-3.0 Imports: 14 Imported by: 0 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 radio plays internet radio stations: streams that go on for as long as anyone listens, from Icecast, SHOUTcast and the like. People add a station by its stream's address, or find one in Radio Browser (radio-browser.info), an open directory of stations. The server passes the stream through to players, and reads the song titles stations send along with it (see icy.go).

Index

Constants

View Source
const UserAgent = "Matinee/1.0 (+https://matinee.yeix.io)"

UserAgent is sent to stations, which count listeners by it.

Variables

View Source
var (
	// ErrBadURL means the address isn't an http or https one.
	ErrBadURL = errors.New("that isn't a web address")
	// ErrNotAudio means the address answered with something that isn't a
	// stream, such as a web page.
	ErrNotAudio = errors.New("that address isn't a radio stream")
	// ErrHLS means the station streams in pieces (HLS), which Matinee
	// can't relay yet.
	ErrHLS = errors.New("that station streams as HLS, which isn't supported yet. Look for its MP3 or AAC stream")
)
View Source
var DirectoryBase = "https://all.api.radio-browser.info"

DirectoryBase is Radio Browser's API. The docs' screenshot server points it at a stand-in at build time.

Functions

func Normalize

func Normalize(raw string) (string, error)

Normalize checks a station's address and fills in https:// when it's left out.

func Relay

func Relay(w http.ResponseWriter, r *http.Request, client *http.Client, addr string, onTitle func(string))

Relay plays a station to a player: it passes the stream through, takes the song titles out of it for onTitle, and ends when the player leaves.

func StreamTitle

func StreamTitle(meta string) (string, bool)

StreamTitle reads the title out of a block such as StreamTitle='Above & Beyond - Sun & Moon';StreamUrl=”;

Types

type Found

type Found struct {
	Name     string   `json:"name"`
	URL      string   `json:"url"`
	Homepage string   `json:"homepage,omitempty"`
	Image    string   `json:"image,omitempty"`
	Tags     []string `json:"tags,omitempty"`
	Country  string   `json:"country,omitempty"` // two letters, such as GB
	Codec    string   `json:"codec,omitempty"`   // such as MP3 or AAC
	Bitrate  int      `json:"bitrate,omitempty"` // kbit/s
	// The station in the library asked about, when it's added already.
	ItemID int64 `json:"itemId,omitempty"`
}

Found is a station in the directory.

func Search(ctx context.Context, client *http.Client, base, q string, byTag bool) ([]Found, error)

Search finds stations by name, or by tag (genre) when byTag, the most listened first. Stations that only stream as HLS are left out.

type Info

type Info struct {
	URL         string // the stream, after following a playlist file
	Name        string // icy-name, if it sends one
	Homepage    string // icy-url
	Genre       string // icy-genre
	ContentType string
}

Info is what a station says about itself when asked for its stream.

func Probe

func Probe(ctx context.Context, client *http.Client, raw string) (Info, error)

Probe opens a station's stream to check it plays, and reads what the station says about itself. A playlist file (.pls or .m3u) is followed to the first stream it lists.

type StatusError

type StatusError struct{ Status string }

StatusError is a station answering with something other than its stream.

func (*StatusError) Error

func (e *StatusError) Error() string

type Title

type Title struct {
	Title string    `json:"title"`
	At    time.Time `json:"at"`
}

Title is a station's song and when it was heard.

type Titles

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

Titles remembers the song each station played last, for players to show.

func (*Titles) Get

func (t *Titles) Get(station int64) (Title, bool)

Get is a station's song, if it sent one in the last hour.

func (*Titles) Set

func (t *Titles) Set(station int64, title string)

Set keeps a station's song.

Jump to

Keyboard shortcuts

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