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

trackprefs

package
v0.3.2 Latest Latest
Warning

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

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

Documentation

Overview

Package trackprefs persists viewer stream policy and show-specific choices.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AudioOrder added in v0.3.0

func AudioOrder(audio []string, server, original string, preferOriginal bool) []string

AudioOrder is the audio preference for one playback. audio is the viewer's list, or user 0's list when the viewer saved none. PreferOriginal ranks the title original first. Otherwise the order is that list, the catalog language, then the title original. pick uses the file default flag only when none of these match.

func LimitBitrate added in v0.3.0

func LimitBitrate(existing, preference int) int

Types

type Choice

type Choice struct {
	Language string `json:"language"`
	Forced   bool   `json:"forced"`
	SDH      bool   `json:"sdh"`
	Off      bool   `json:"off"`
}

type Options

type Options struct {
	ShowName func(context.Context, int64) string
	// SyncLanguages mirrors a viewer's ordered audio and subtitle lists onto
	// auth_users.audio_languages and auth_users.subtitle_languages, for code
	// that reads them from the user record. It runs after every write of the
	// viewer's rules, with empty lists when the rules are deleted. User 0 is
	// the shared default and is not an account row.
	SyncLanguages func(ctx context.Context, user int64, audio, subtitles []string) error
	// ServerLanguage is the catalog metadata language (config catalog.language,
	// for example en-US). It is not the console locale.
	ServerLanguage func() string
	// PlexLayer is the viewer's cached plex.tv account settings. It sits
	// under the viewer's own row and user 0. A missing callback skips it.
	PlexLayer func(context.Context, int64) (PlexLayer, bool)
}

type PlexLayer added in v0.3.0

type PlexLayer struct {
	AudioLanguage    string
	AutoSelectAudio  bool
	SubtitleLanguage string
	SubtitleMode     string // Ether names: off, foreign-only, always
}

PlexLayer is the default language layer from a plex.tv account.

type Rules

type Rules struct {
	AudioLanguages     []string        `json:"audioLanguages"`
	SubtitleLanguages  []string        `json:"subtitleLanguages"`
	PreferOriginal     bool            `json:"preferOriginal"`
	SubtitleMode       string          `json:"subtitleMode"`  // off, forced-only, foreign-only, always
	SubtitleStyle      string          `json:"subtitleStyle"` // normal, sdh, forced
	SubtitleAppearance json.RawMessage `json:"subtitleAppearance,omitempty"`
	Loudness           bool            `json:"loudness"`
	NightMode          bool            `json:"nightMode"`
	DialogueBoost      bool            `json:"dialogueBoost"`
	MaxBitrateKbps     int             `json:"maxBitrateKbps,omitempty"` // 0 means no viewer preference
	MaxHeight          int             `json:"maxHeight,omitempty"`
	PreferredQuality   string          `json:"preferredQuality,omitempty"`
}

User zero is the owner-configured fallback policy; positive IDs are overrides.

func Default

func Default() Rules

func (Rules) AudioFilters

func (r Rules) AudioFilters(channels int) []string

AudioFilters returns only known ffmpeg filters; arbitrary client strings never enter the command.

func (Rules) Validate

func (r Rules) Validate() error

type SavedChoice

type SavedChoice struct {
	ShowID    int64  `json:"showId"`
	ShowTitle string `json:"showTitle,omitempty"`
	Kind      string `json:"kind"`
	Choice    Choice `json:"choice"`
	UpdatedAt int64  `json:"updatedAt"`
}

type Scope added in v0.3.0

type Scope struct{ Device, Series, Library string }

Scope identifies the authenticated device and the title's series and library.

type ScopedRules added in v0.3.0

type ScopedRules struct {
	AudioLanguages     *[]string        `json:"audioLanguages,omitempty"`
	SubtitleLanguages  *[]string        `json:"subtitleLanguages,omitempty"`
	SubtitleMode       *string          `json:"subtitleMode,omitempty"`
	SubtitleAppearance *json.RawMessage `json:"subtitleAppearance,omitempty"`
	MaxBitrateKbps     *int             `json:"maxBitrateKbps,omitempty"`
	MaxHeight          *int             `json:"maxHeight,omitempty"`
	PreferredQuality   *string          `json:"preferredQuality,omitempty"`
}

ScopedRules only changes fields explicitly supplied; nil means inherit.

type Selection

type Selection struct {
	Audio    int
	Subtitle int
}

type Service

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

func New

func New(db *sql.DB, opts ...Options) *Service

func (*Service) DeleteRules

func (s *Service) DeleteRules(ctx context.Context, user int64) error

func (*Service) DeleteScopedField added in v0.3.0

func (s *Service) DeleteScopedField(ctx context.Context, user int64, scope, id, field string) error

DeleteScopedField clears one override without disturbing concurrent writes to the other fields in the same scope.

func (*Service) Forget

func (s *Service) Forget(ctx context.Context, user, show int64) error

func (*Service) GetRules

func (s *Service) GetRules(ctx context.Context, user int64) (Rules, error)

func (*Service) Handler

func (s *Service) Handler() http.Handler

Handler serves /{userID} and /{userID}/shows/{showID} (DELETE). Mount behind the admin owner's authentication and CSRF middleware.

func (*Service) HasViewerRules added in v0.3.0

func (s *Service) HasViewerRules(ctx context.Context, user int64) (bool, error)

HasViewerRules reports whether this viewer stored their own rules. GetRules also falls back to user 0, the shared default, which is not a change this viewer made.

func (*Service) Memory

func (s *Service) Memory(ctx context.Context, user int64) ([]SavedChoice, error)

func (*Service) PutRules

func (s *Service) PutRules(ctx context.Context, user int64, r Rules) error

func (*Service) PutScoped added in v0.3.0

func (s *Service) PutScoped(ctx context.Context, user int64, scope, id string, value ScopedRules) error

func (*Service) Remember

func (s *Service) Remember(ctx context.Context, user int64, key core.RatingKey, kind string, track *core.StreamInfo) error

func (*Service) ScopedRules added in v0.3.0

func (s *Service) ScopedRules(ctx context.Context, user int64, scope Scope) (Rules, bool, error)

ScopedRules returns the effective rules and whether any override applied. Each field inherits independently, with device taking highest precedence.

func (*Service) ScopedRulesWithSources added in v0.3.0

func (s *Service) ScopedRulesWithSources(ctx context.Context, user int64, scope Scope) (Rules, map[string]string, error)

ScopedRulesWithSources also identifies the winning scoped override for each field.

func (*Service) Select

func (s *Service) Select(ctx context.Context, user int64, key core.RatingKey, info core.MediaInfo, original string) (Selection, error)

Select returns positions in MediaInfo.Streams, never ffprobe indices.

func (*Service) SelectScoped added in v0.3.0

func (s *Service) SelectScoped(ctx context.Context, user int64, key core.RatingKey, info core.MediaInfo, original string, scope Scope) (Selection, bool, error)

SelectScoped falls back to Select unchanged when no scoped preference applies.

func (*Service) SetAppearance added in v0.3.0

func (s *Service) SetAppearance(ctx context.Context, user int64, raw json.RawMessage) error

func (*Service) SetAudioPreferences added in v0.3.0

func (s *Service) SetAudioPreferences(ctx context.Context, user int64, languages []string) error

func (*Service) SetBitratePreference added in v0.3.0

func (s *Service) SetBitratePreference(ctx context.Context, user int64, kbps int) error

func (*Service) SetHeightPreference added in v0.3.0

func (s *Service) SetHeightPreference(ctx context.Context, user int64, height int, quality string) error

func (*Service) SetSubtitleLanguage added in v0.3.0

func (s *Service) SetSubtitleLanguage(ctx context.Context, user int64, languages []string) error

func (*Service) SetSubtitleMode added in v0.3.0

func (s *Service) SetSubtitleMode(ctx context.Context, user int64, mode string) error

func (*Service) SetSubtitlePreferences added in v0.3.0

func (s *Service) SetSubtitlePreferences(ctx context.Context, user int64, languages []string, mode string) error

SetSubtitlePreferences updates only subtitle fields, preserving concurrent audio and other rule changes. The compare-and-swap is shared across nodes.

Jump to

Keyboard shortcuts

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