api

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2026 License: AGPL-3.0 Imports: 25 Imported by: 0

Documentation

Overview

Package api is a disc module's own HTTP API and SDUI sources (module API 5): a disc's page, why a title is its film and the choice of another, the names given to its titles and chapters, and its sections on a title's page in every app. WittyMediaServer passes the routes on at /api/modules/<module>/... once it has checked who may call them (integration.json).

What a disc holds and which title is its film rests on what only the server keeps and checks: the scan's ranking and an administrator's choice are columns of the server's item, which its own disc sessions play from, and every answer of the disc engine is read in a helper of its own and checked by the server (its scramble and AACS guards stay the server's). So this asks the host API, on behalf of the person asking (/host/v1/discs/...), and shows the answer. The names given to titles and chapters are this module's own, in its own database.

The same files are in WittyDVD and WittyBluray (Config says which): they move into WittyDisc with its next release.

Index

Constants

View Source
const (
	CommandChoose      = commands.Choose
	CommandClearChoice = commands.ClearChoice
	CommandRank        = commands.Rank
	CommandCompare     = commands.Compare
)

Commands, after "<module>.": its own routes, which check again who is asking.

View Source
const DataEnv = "WITTYMODULE_DATA"

DataEnv is where the server says the module's own folder is.

View Source
const DataFormat = 1

DataFormat is this database's form, as module.json's dataFormat says.

View Source
const File = "labels.db"

File is the database's name in the module's data folder.

Variables

This section is empty.

Functions

func Guard

func Guard(token string, next http.Handler) http.Handler

Guard lets in only whoever was told the start's secret, which is the server: a port on this machine can be reached by anything else running on it.

Types

type Analysis

type Analysis struct {
	Kind string `json:"kind"` // dvd or bluray
	// Ranked: the engine gave a ranking; without one, the main title is the older rule's pick.
	Ranked bool `json:"ranked"`
	// Pending: the ranking is being worked out on a server set to go easy on its machine.
	Pending bool `json:"pending"`
	// Main is what Play plays; EngineMain the engine's own pick; -1 when there is none.
	Main          int             `json:"main"`
	EngineMain    int             `json:"engineMain"`
	Chosen        json.RawMessage `json:"chosen"`
	ChosenBy      string          `json:"chosenBy,omitempty"`
	Rank          json.RawMessage `json:"rank"`
	CanChoose     bool            `json:"canChoose"`
	RankError     string          `json:"rankError,omitempty"`
	Protected     bool            `json:"protected"`
	SecondOpinion json.RawMessage `json:"secondOpinion,omitempty"`
}

Analysis is which title is the film and why.

type App

type App struct {
	Config
	Host   Host
	Labels *Store
	Log    *slog.Logger
}

App is what the routes and sources need.

func (*App) Items

func (a *App) Items(req sdui.ItemsRequest) (sdui.ItemsAnswer, error)

Items answers the server's sdui.items call for one of the module's sources.

func (*App) Routes

func (a *App) Routes(mux *http.ServeMux)

Routes adds the module's routes, as integration.json lists them.

type Candidate

type Candidate struct {
	TTN         int     `json:"ttn"`
	DurationSec float64 `json:"durationSec"`
	Class       string  `json:"class"`
	Chapters    int     `json:"chapters"`
}

type Chapter

type Chapter struct {
	N     int     `json:"n"`
	Start float64 `json:"start"`
	Label string  `json:"label"`
}

Chapter is one of a title's chapters.

type Config

type Config struct {
	Module string // wittydvd or wittybluray
	Bluray bool
}

Config is which disc module this is.

func (Config) Commands

func (c Config) Commands() []core.CommandSpec

Commands are the module's own commands, as its sdui.json declares them.

func (Config) Unit

func (c Config) Unit() string

Unit is what the disc calls its titles.

type Disc

type Disc struct {
	ID         int64           `json:"id"`
	Kind       string          `json:"kind"`
	Title      string          `json:"title"`
	Label      string          `json:"label"`
	RuntimeSec float64         `json:"runtimeSec"`
	Scrambled  bool            `json:"scrambled"`
	Main       int             `json:"main"`
	EngineMain int             `json:"engineMain"`
	Chosen     json.RawMessage `json:"chosen"`
	ChosenBy   string          `json:"chosenBy,omitempty"`
	Rank       json.RawMessage `json:"rank"`
	FeatureSec float64         `json:"featureSec,omitempty"`
	RankError  string          `json:"rankError,omitempty"`
	Pending    bool            `json:"pending"`
	NoPlay     bool            `json:"noPlay"`
	Page       *Page           `json:"page,omitempty"`
	PageError  string          `json:"pageError,omitempty"`
	Second     json.RawMessage `json:"secondOpinion,omitempty"`
	// contains filtered or unexported fields
}

Disc is what the host API says of a disc, for a person (WittyMediaServer host_discs.go).

func (*Disc) IsChosen

func (d *Disc) IsChosen() bool

IsChosen says an administrator chose the film.

func (*Disc) Ranking

func (d *Disc) Ranking() *Rank

Ranking is the kept ranking, read, or nil.

type Dual

type Dual struct {
	Config
	Helper wittymodule.Handler
	// contains filtered or unexported fields
}

Dual is one process answering as either of the two things a server starts the module's program as:

  • a helper with one open disc, as it always was (Helper), started for each disc played or ranked, and never given a network;
  • the module's service (module API 5): the server's first call is then service.MethodStart, with where its host API is. It listens on this machine only, with a secret of its own, for the routes the server passes on, and answers the SDUI and lifecycle calls. It reads no disc.

wittymodule/service.Main runs a service only, and answers every other call with "unknown-method", so it can't also be the helper a server asks about one disc: this is that part of it, with the same guard (a WittyModule gap: a service with helper calls of its own).

func (*Dual) App

func (d *Dual) App() (*App, error)

App is the service's routes and sources, with its database opened the first time it's needed.

func (*Dual) Handle

func (d *Dual) Handle(method string, params json.RawMessage) (any, []byte, error)

Handle is the helper protocol's handler, for wittymodule.Serve.

func (*Dual) Mux

func (d *Dual) Mux() http.Handler

Mux is the service's handler: the module's routes under /http, as the server passes them.

type Episode

type Episode struct {
	Index       int     `json:"index"`
	TTN         int     `json:"ttn"`
	DurationSec float64 `json:"durationSec"`
	StartSec    float64 `json:"startSec"`
	Part        bool    `json:"part"`
}

type Host

type Host interface {
	Do(ctx context.Context, on host.On, method, path string, body, out any) error
}

Host is the host API, as much of it as this needs.

type Issue

type Issue struct {
	What     string `json:"what"`
	Severity string `json:"severity"`
	TTN      int    `json:"ttn"`
}

type Labels

type Labels struct {
	Titles   map[string]string            `json:"titles"`
	Chapters map[string]map[string]string `json:"chapters"`
}

Labels are names given to a disc's titles and chapters, keyed by title number and chapter number (as strings, for JSON).

func (Labels) Clean

func (l Labels) Clean() Labels

Clean drops empty names and trims the rest.

type Menu struct {
	Kind  string `json:"kind"`
	VTS   int    `json:"vts"`
	Label string `json:"label"`
}

Menu is one of the disc's menus a viewer can jump into.

type Page

type Page struct {
	Main   *Title  `json:"main"`
	Extras []Title `json:"extras"`
	Menus  []Menu  `json:"menus"`
	Hidden int     `json:"hidden"`
}

Page is a disc's page: the film, the other titles worth watching, the menus to jump into.

type Rank

type Rank struct {
	Engine     string      `json:"engine"`
	Main       int         `json:"main"`
	Confidence float64     `json:"confidence"`
	Level      string      `json:"level"`
	Why        string      `json:"why"`
	Versions   []Version   `json:"versions"`
	Episodes   []Episode   `json:"episodes"`
	Candidates []Candidate `json:"candidates"`
	Decoys     int         `json:"decoys"`
	Hidden     int         `json:"hidden"`
	Repairs    []string    `json:"repairs"`
	RepairCnt  int         `json:"repairCount"`
	Issues     []Issue     `json:"issues"`
	Padded     int64       `json:"paddedSectors"`
	Second     *Second     `json:"secondOpinion"`
}

Rank is the parts of a kept ranking the pages show.

type Second

type Second struct {
	Source      string   `json:"source"`
	Agrees      bool     `json:"agrees"`
	Note        string   `json:"note"`
	Differences []string `json:"differences"`
}

type Store

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

Store is the module's database.

func Open

func Open(dir string) (*Store, error)

Open opens (or makes) the database in a folder.

func (*Store) Close

func (s *Store) Close() error

Close closes it.

func (*Store) Forget

func (s *Store) Forget(ctx context.Context, item int64) error

Forget drops a disc's names, when its item is gone.

func (*Store) Get

func (s *Store) Get(ctx context.Context, item int64) Labels

Get is a disc's names (never nil maps).

func (*Store) Set

func (s *Store) Set(ctx context.Context, item int64, l Labels) error

Set replaces a disc's names.

type Title

type Title struct {
	TTN         int       `json:"ttn"`
	Label       string    `json:"label"` // the name someone gave it, "" for none
	DurationSec float64   `json:"durationSec"`
	Chapters    []Chapter `json:"chapters"`
	Audio       []string  `json:"audio"`
	Subtitles   []string  `json:"subtitles"`
	Angles      int       `json:"angles"`
	Wide        bool      `json:"wide"`
}

Title is one title (a DVD's) or playlist (a Blu-ray's).

type Version

type Version struct {
	Kind        string  `json:"kind"`
	TTN         int     `json:"ttn"`
	Angle       int     `json:"angle"`
	DurationSec float64 `json:"durationSec"`
	Label       string  `json:"label"`
	Main        bool    `json:"main"`
}

Jump to

Keyboard shortcuts

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