Help us shape the future of Go! Take the 2026 Go Developer Survey

contentrating

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2026 License: GPL-3.0 Imports: 4 Imported by: 0

Documentation

Overview

Package contentrating is Ether's one content-rating model. Every certification (US MPAA and TV Parental Guidelines, and the boards of the countries TMDB lists) normalises to a Rating: the issuing country, the label as certified, and an age Level. Rules, viewer limits and pickers compare Levels, so "PG" and "TV-PG" are the same choice everywhere.

Stored form. US labels are stored bare ("PG", "TV-14"), exactly as Plex shows them. Any other country's label is stored region-qualified the way Plex Media Server writes it, lowercase country then a slash: "de/6", "gb/12A", "ca/14A". A foreign label is never stored as if it were US.

Index

Constants

View Source
const NotRatedKey = "NR"

NotRatedKey is the rule and picker value for titles without a usable rating.

Variables

Levels lists the rated levels, mildest first. There is no separate "7+" level: the 6–11 age ratings (TV-Y7, DE 6, SE 7, BR 10) sit with PG, so an allowlist of G and PG never hides a title rated milder than PG.

Functions

func Allowed

func Allowed(rating, max string) bool

Allowed is !Exceeds, for readability at call sites.

func Canonical

func Canonical(v string) (key string, ok bool)

Canonical maps any accepted rule or limit value to the level's Key: "TV-G" and "gb/U" become "G", "Not rated" becomes "NR". ok is false for a value that names no level and is not an explicit "not rated".

func Equivalents

func Equivalents(l Level) []string

Equivalents lists the labels each country's board uses for level l, as stored values (bare US, "cc/label" elsewhere), US first then by country.

func Exceeds

func Exceeds(rating, max string) bool

Exceeds reports whether rating is above the limit max. An empty limit is unrestricted. An unrated title, or a limit that names no level, exceeds every limit: restricted viewers never see what Ether cannot place.

func FromPrefixed

func FromPrefixed(label string) string

FromPrefixed reads a Jellyfin or Emby rating label back into stored form: "DE-6" is "de/6" when DE is a board Ether knows; anything else ("PG-13", "TV-14") is already a stored label.

func IsNotRated

func IsNotRated(v string) bool

IsNotRated reports whether an owner value means "titles without a rating".

func Prefixed

func Prefixed(stored string) string

Prefixed is a stored rating in the form Jellyfin and Emby store and show ratings: bare for the US, "DE-6" (country, hyphen, label) elsewhere.

func Qualify

func Qualify(country, label string) string

Qualify is the stored form of a country's label: bare for the US, otherwise "cc/label" like Plex Media Server.

Types

type Certification

type Certification struct {
	Country string // ISO 3166-1, any case
	Label   string
	// ReleaseType is TMDB's movie release type (1 premiere, 2 limited
	// theatrical, 3 theatrical, 4 digital, 5 physical, 6 TV); 0 for TV
	// show content ratings.
	ReleaseType int
}

Certification is one rating a provider lists for a title.

type Level

type Level int

Level is an age band. Higher is more mature; Unrated sorts first and is never inside a limit. The integer values are persisted (catalogue content_rating_rank), so they must not be renumbered.

const (
	Unrated  Level = iota // no usable certification: blank, NR, Unrated, unknown label
	AllAges               // G, TV-G, TV-Y; U (GB), 0 (DE), L (BR)
	Parental              // PG, TV-PG, TV-Y7; PG (GB), 6 (DE), 7 (SE), 10 (BR)
	Teen                  // PG-13, TV-14; 12A (GB), 12 (DE), 14A (CA)
	Mature                // R, TV-MA; 15 (GB), 16 (DE), MA15+ (AU)
	Adult                 // NC-17; 18 (GB, DE), R18+ (AU)
)

func AgeLevel

func AgeLevel(age int) Level

AgeLevel is the band holding a minimum age: 0–5 all ages, 6–11 parental guidance, 12–14 teens, 15–17 mature, 18 and over adults.

func LevelOf

func LevelOf(s string) Level

LevelOf is Parse(s).Level.

func Lookup

func Lookup(country, label string) Level

Lookup is the level of a country's label. A label the country's table does not list falls back to a plain age ("16", "12+"); otherwise it is Unrated.

func (Level) Age

func (l Level) Age() int

Age is the minimum viewer age the level stands for (-1 when unrated). It is also the parental score other protocols use (Jellyfin and Emby compare these numbers; Jellyfin's US file scores G 0, PG 10, PG-13 13).

func (Level) Key

func (l Level) Key() string

Key is the canonical value a rule or viewer limit stores for the level: the US film label where there is one. "NR" is the explicit "Not rated" choice.

func (Level) USLabels

func (l Level) USLabels() []string

USLabels are the US film and TV labels of a level, in display order.

type Rating

type Rating struct {
	// Country is the ISO 3166-1 code of the issuing board, upper case
	// ("US", "DE", "CA-QC"). Empty when a bare stored label is not a US
	// label and its country cannot be known.
	Country string
	Label   string // as certified: "TV-PG", "6", "12A"
	Level   Level
}

Rating is one parsed certification.

func Parse

func Parse(s string) Rating

Parse reads a stored or owner-entered rating. Bare US labels resolve as US. A bare label from another system (stored by an older release, or typed by the owner) resolves only when every board that uses it agrees on the level, or when it is a plain age ("12", "16+"); anything else is Unrated rather than a guess.

func (Rating) Rated

func (r Rating) Rated() bool

Rated reports whether the rating has an age level.

type Selection

type Selection struct {
	Value  string // stored form: "PG", "de/6"; "" when nothing usable
	Source string // "tmdb:US:6", "tmdb:CA"; "" when Value is ""
}

Selection is the chosen rating in stored form, and where it came from.

func Select

func Select(certs []Certification, region string) Selection

Select chooses a title's rating from a provider's certifications: the owner's region first, then the US, then other countries (foreignPriority order). Within a country it takes the first label that has an age level, by release type. A foreign rating is kept region-qualified ("de/6"), never passed off as US. When no country has a rated label, an explicit "not rated" from the region or the US is kept ("NR"), as Plex shows it.

Jump to

Keyboard shortcuts

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