synchandlers

package
v0.4.21 Latest Latest
Warning

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

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

Documentation

Overview

Package synchandlers provides HTTP handlers for subtitle sync operations (audio-based sync and manual offset adjustment).

Index

Constants

View Source
const MaxSyncSubSize = httpwire.MaxDownloadBytes

MaxSyncSubSize caps subtitle file reads for sync operations.

Variables

This section is empty.

Functions

func ShiftAndFilterCues

func ShiftAndFilterCues(cues []subflux.SubtitleCue, totalShift time.Duration) []subflux.SubtitleCue

ShiftAndFilterCues applies a timing shift to all cues and removes cues that end before time zero. Cue start times are clamped to zero.

Types

type Deps

type Deps struct {
	Store        SyncStore
	SubtitleProc SubtitleProcessor
	Activity     *activity.Log
	Resolve      *resolve.Resolver
}

Deps holds all dependencies for the sync handler family. Resolve is the S7 typed-reference resolver: sync verbs address the subtitle by FileRef and the server resolves both the subtitle path (store row) and the video path (same media) — no client-supplied paths.

type Handler

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

Handler holds all dependencies for the sync handler family.

func New

func New(d Deps) *Handler

New creates a Handler with the given dependencies.

func (*Handler) HandleSyncAudio

func (h *Handler) HandleSyncAudio(w http.ResponseWriter, r *http.Request)

HandleSyncAudio handles POST /api/sync/audio.

func (*Handler) HandleSyncOffset

func (h *Handler) HandleSyncOffset(w http.ResponseWriter, r *http.Request)

HandleSyncOffset handles POST /api/sync/offset.

type SubtitleProcessor added in v0.4.0

type SubtitleProcessor interface {
	NormalizeEncoding(data []byte) []byte
	ParseSRT(data []byte) ([]subflux.SubtitleCue, error)
	WriteSRT(cues []subflux.SubtitleCue) ([]byte, error)
	SyncFromAudio(ctx context.Context, data []byte, videoPath, subtitlePath string) subflux.AudioSyncResult
}

SubtitleProcessor is the SRT surface the sync verbs drive: decode to UTF-8, parse to cues, shift and re-serialize, and run audio-based alignment. All four of the processor's methods, because applying an offset is exactly parse-shift-write and the audio path adds the fourth.

Exported because the server names it: WithSubtitleProc carries the processor from the composition root to here, and naming this type is what stops a second declaration from drifting.

type SyncAudioRequest added in v0.1.148

type SyncAudioRequest struct {
	MediaType subflux.MediaType `json:"media_type"`
	MediaID   string            `json:"media_id"`
	Language  string            `json:"language"`
	Variant   string            `json:"variant,omitempty"`
	Source    string            `json:"source,omitempty"`
	Ordinal   int               `json:"ordinal,omitempty"`
	DryRun    bool              `json:"dry_run,omitempty"`
}

SyncAudioRequest is the typed body for POST /api/sync/audio: the FileRef of the subtitle to align (the server resolves the subtitle path from the store row and the video path from the same media) plus the dry-run flag.

type SyncAudioResponse added in v0.1.148

type SyncAudioResponse struct {
	Method     string  `json:"method"`
	OffsetMs   int64   `json:"offset_ms"`
	Confidence float64 `json:"confidence"`
	Applied    bool    `json:"applied"`
}

SyncAudioResponse is the typed response for POST /api/sync/audio.

type SyncOffsetRequest added in v0.1.148

type SyncOffsetRequest struct {
	MediaType subflux.MediaType `json:"media_type"`
	MediaID   string            `json:"media_id"`
	Language  string            `json:"language"`
	Variant   string            `json:"variant,omitempty"`
	Source    string            `json:"source,omitempty"`
	Ordinal   int               `json:"ordinal,omitempty"`
	OffsetMs  int64             `json:"offset_ms"`
}

SyncOffsetRequest is the typed body for POST /api/sync/offset: the FileRef of the subtitle plus the absolute cumulative offset to apply.

type SyncStore

type SyncStore interface {
	SyncOffset(ctx context.Context, path string) (int64, error)
	SetSyncOffset(ctx context.Context, path string, offsetMs int64) error
}

SyncStore is the offset pair audio-sync reads and writes: 2 of the 36 methods the store offers. Sync handlers touch no other row family.

Jump to

Keyboard shortcuts

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