langfeat

package
v0.3.1 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: 12 Imported by: 0

Documentation

Overview

Package langfeat runs the owner's language-model features that a viewer or admin asks for explicitly: translating an existing subtitle, writing subtitles from audio, and translating an overview and tagline. Nothing here runs on a timer, and a search or a library row never calls a model.

Index

Constants

View Source
const (
	// TranslateOfferID and TranscribeOfferID are reserved subtitle offer
	// ids. They sit above ordinary provider file ids and inside the range
	// JavaScript can round-trip, because some clients keep the id in a number.
	TranslateOfferID  int64 = 9000000000000001
	TranscribeOfferID int64 = 9000000000000002
)

Variables

This section is empty.

Functions

func IsReserved

func IsReserved(id int64) bool

IsReserved reports whether id belongs to a language feature offer.

Types

type Gates

type Gates struct {
	SubtitleTranslate bool
	SpeechToText      bool
	OverviewTranslate bool
	TextReady         bool
	SpeechReady       bool
}

Gates are the switches and whether each requirement is configured.

type Offer

type Offer struct {
	ID       int64
	Language string
	Title    string
	Provider string
}

Offer is one subtitle choice shown in a viewer's search. Building the list does not call a model.

type Options

type Options struct {
	Dir   string
	Gates func() Gates
	// Translate is one language-model call. system and user are the prompt.
	Translate func(ctx context.Context, system, user string) (string, error)
	// Transcribe reads a 16 kHz mono wav and returns timed subtitle text.
	Transcribe func(ctx context.Context, wavPath, language string) (string, error)
	Subtitles  *subtitles.Service
	// Audio extracts a wav of the playing title. It runs only when a viewer
	// picks the from-audio track.
	Audio func(ctx context.Context, user *core.User, title *core.Title) (wavPath string, cleanup func(), err error)
	// SourceText reads an embedded subtitle when nothing is cached yet.
	// It runs only when a viewer picks the translated track.
	SourceText func(ctx context.Context, user *core.User, title *core.Title, exceptLang string) (lang, text string, err error)
	Now        func() time.Time
}

Options build a Service.

type Service

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

Service caches translations and transcripts under Dir.

func New

func New(o Options) *Service

New builds a Service.

func (*Service) Fulfill

func (s *Service) Fulfill(ctx context.Context, user *core.User, title *core.Title, id int64) (core.StreamInfo, error)

Fulfill builds the track a viewer picked. A cached track is returned without calling a model.

func (*Service) Offers

func (s *Service) Offers(title *core.Title, lang string) []Offer

Offers lists the tracks a viewer may ask for. It does not translate, transcribe, or read the media.

func (*Service) Overview

func (s *Service) Overview(ctx context.Context, title *core.Title, lang string, detail bool) (summary, tagline string, ok bool)

Overview returns a cached translation. When detail is true and nothing is cached, it translates. A library row passes detail false and never calls the model.

func (*Service) Queue

func (s *Service) Queue(ctx context.Context, title *core.Title, lang string) (overviewDoc, error)

Queue translates one title for an admin. A cached result is returned without another model call.

func (*Service) ResetGates

func (s *Service) ResetGates()

ResetGates drops the short-lived copy of Gates. Tests use it after a save.

Jump to

Keyboard shortcuts

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