media

package
v0.9.0-dev.52 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Overview

Package media is subflux's identity: the key an episode or movie is stored, matched and served by. A key derives from an external id (TVDB, TMDB or IMDb) and an episode's aired numbering, never from a source's own ids, so two sources naming one item agree on its key.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ValidEpisodeNumber

func ValidEpisodeNumber(n int) bool

ValidEpisodeNumber reports whether n lies in 0 to 65,535, the seasons and episodes a key holds; season 0 holds specials.

func ValidExternalID

func ValidExternalID(id uint64) bool

ValidExternalID reports whether id lies in 1 to 2^53-1, the ids a key holds, so every id survives a round trip through a JavaScript number on the wire.

Types

type ExternalIDs

type ExternalIDs struct{ TVDB, TMDB, IMDb uint64 }

ExternalIDs are an item's ids per scheme; 0 is unknown. IMDb's is numeric: tt0111161 is 111161.

type Key

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

Key names a movie or one episode of a series. Only Choose and ParseKey build one, so every non-zero Key is valid; a movie's season and episode are zero.

func Choose

func Choose(kind Kind, ids ExternalIDs, n Numbering) (Key, bool)

Choose keys an item: an episode by the id of its Numbering.Scheme with its season and episode, a movie by TMDB, then IMDb. An id ValidExternalID refuses counts as unknown. False means unidentified: a zero or unknown kind, an episode under None or with a number ValidEpisodeNumber refuses, or no usable id.

func ParseKey

func ParseKey(s string) (Key, error)

ParseKey is String's inverse, refusing every other spelling, a series root and any text over 64 bytes.

func (Key) Bytes

func (k Key) Bytes() []byte

Bytes is the root's ten bytes, then season and episode as big-endian uint16s, zero for a movie: fourteen bytes.

func (Key) MarshalText

func (k Key) MarshalText() ([]byte, error)

MarshalText is String; the zero Key, which UnmarshalText would refuse, is an error rather than "".

func (Key) Root

func (k Key) Root() RootKey

Root is the movie itself, or the series an episode belongs to.

func (Key) String

func (k Key) String() string

String is a movie's root text, or a series' root text followed by -s<season>e<episode>, each padded to two digits. "" for the zero Key.

func (*Key) UnmarshalText

func (k *Key) UnmarshalText(b []byte) error

UnmarshalText is ParseKey, leaving k unchanged on a refusal.

type Kind

type Kind uint8

Kind is what a key names.

const (
	Episode Kind = iota + 1
	Movie
)

The kinds, from 1, so the zero Kind is none.

func (Kind) MarshalText

func (k Kind) MarshalText() ([]byte, error)

MarshalText is episode or movie.

func (*Kind) UnmarshalText

func (k *Kind) UnmarshalText(b []byte) error

UnmarshalText refuses every spelling but MarshalText's.

type Numbering

type Numbering struct {
	Scheme          Scheme
	Season, Episode int
}

Numbering is an episode's season and episode and the Scheme whose id keys it; each number passes ValidEpisodeNumber. A key's numbering is TVDB's aired order. A movie's is zero and ignored.

type RootKey

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

RootKey names a movie or a series. Only Choose, ParseRootKey and Key.Root build one, so every non-zero RootKey is valid.

func ParseRootKey

func ParseRootKey(s string) (RootKey, error)

ParseRootKey is RootKey.String's inverse, refusing every other spelling, an episode key and any text over 64 bytes.

func (RootKey) Bytes

func (r RootKey) Bytes() []byte

Bytes is kind, scheme and the id as a big-endian uint64: ten bytes, so a prefix scan over one root never reaches another (tmdb-12 against tmdb-120).

func (RootKey) MarshalText

func (r RootKey) MarshalText() ([]byte, error)

MarshalText is String; the zero RootKey is an error rather than "".

func (RootKey) String

func (r RootKey) String() string

String is the canonical text: tmdb-<id> or tt<id> for a movie; tvdb-<id>, tmdbtv-<id> or imdbtv-tt<id> for a series. Ids are decimal with no leading zero, IMDb's padded to seven digits. "" for the zero RootKey.

func (*RootKey) UnmarshalText

func (r *RootKey) UnmarshalText(b []byte) error

UnmarshalText is ParseRootKey, leaving r unchanged on a refusal.

type Scheme

type Scheme uint8

Scheme is the external id a key is built from. None is a movie's numbering scheme, and an episode numbered under None has no key.

const (
	None Scheme = iota
	TVDB
	TMDB
	IMDb
)

The schemes; IMDb is spelled imdb in text.

func (Scheme) MarshalText

func (s Scheme) MarshalText() ([]byte, error)

MarshalText is none, tvdb, tmdb or imdb.

func (*Scheme) UnmarshalText

func (s *Scheme) UnmarshalText(b []byte) error

UnmarshalText refuses every spelling but MarshalText's.

type SourceID

type SourceID string

SourceID names one configured media source: 1 to 32 bytes of [a-z0-9-].

func (SourceID) MarshalText

func (id SourceID) MarshalText() ([]byte, error)

MarshalText refuses an id outside [a-z0-9-]{1,32}, so no id is written that UnmarshalText would refuse.

func (*SourceID) UnmarshalText

func (id *SourceID) UnmarshalText(b []byte) error

UnmarshalText refuses anything outside [a-z0-9-]{1,32}, leaving id unchanged.

Jump to

Keyboard shortcuts

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