Repository navigation
Reference implementation
This article explains part of Radio 2.0 in plain words. It is not normative: where it differs from the specification, the specification is right.
The reference implementation is the Go library and command line tool kept in the Radio 2.0 repository. It validates manifests, events and schedules, finds manifests from homepages and stream URLs, and applies the verification and network rules. It is pure Go with no cgo, under the MIT licence, and there are no packaged releases or SDKs in other languages yet.
| Module | github.com/Tend-Stack/radio2 |
| Packages |
manifest, discover, schema, and the command cmd/radio2
|
| Spec version | 0.2.4-draft |
| Language | Go, pure Go, no cgo |
| Releases | None packaged yet |
| Status | Draft |
manifest holds the types for the manifest, events and the schedule, plus these functions:
-
Parsedecodes strictly. The document must be one UTF-8 JSON object within the size limit, and members the schema does not define are errors.ParseEventandParseScheduledo the same for those documents. -
ParseLenientis for consumers that must ignore unknown members. -
Validatechecks a manifest document against the embedded schema and the rules a schema cannot express: unique stream ids, split sums,httpsand the development-host exemptions, schedule order and time zones.ValidateManifest,ValidateEventandValidateSchedulecover the other entry points. -
Normalizeapplies the section 2.5 rules in place and returns anInfovalue with the tier, the default stream id and a list of changes. - Helpers include
IsCountry,IsDevelopmentHost,IsDevelopmentURL, and methods onManifestsuch asDefaultStream,Tier,OnAir,TransmissionandStreamCarries.
Validate takes an Options value whose Tier field is manifest.Production (the zero value) or manifest.Development. The returned Report has OK(), Errors() and Warnings(). Each Problem carries a JSON pointer, a message, a rule name and a severity.
discover finds a manifest from a homepage (HTML link, then the well-known address) or from a stream URL (the HTTP Link header, never reading the stream body, with icy-url as a fallback). It applies the section 4 verification rule and the section 10.2 limits. discover.New(discover.Config{}) makes a client. Its methods are Discover, FromHomepage and FromStream; Verify applies the verification rule to a parsed manifest. A Result reports ManifestURL, Via (link-header, html-link or well-known), the manifest, any validation Problems and a verdict with Verified, OriginVerified and the Reasons it is not. Config sets timeout, maximum body, maximum redirects, a development switch and a user agent; the defaults are 10 seconds, 256 KiB and 5 redirects.
schema embeds the three JSON Schemas with go:embed.
cmd/radio2 is the command line tool; see radio2 command line tool.
This is the README's own sample:
rep := manifest.Validate(data, manifest.Options{})
if !rep.OK() {
for _, p := range rep.Errors() {
fmt.Println(p) // "/streams/1/id: stream id "main" is used more than once [unique-id]"
}
}
res, err := discover.New(discover.Config{}).Discover(ctx, "https://radio.example.org/")
// res.ManifestURL, res.Verifiedgo test -race ./... runs the specification, schema and example checks. See Conformance. Discovery is tested against local httptest servers.
There are no SDKs in other languages yet. The list of known software is on Implementations. A validator in any language can use the published JSON Schemas for the schema part, but the rules a schema cannot express need code.
Radio 2.0 is an open standard, MIT licensed. Documentation: radio2.org. Questions: Discussions.
Overview
The manifest
Discovery and identity
Live data
Money
Implementations and tools
- Implementations
- Reference implementation
- radio2 command line tool
- Create a manifest
- Conformance
- Stations
- Brand and badges
Project
Documentation
Community