Documentation
¶
Overview ¶
Package synchandlers provides HTTP handlers for subtitle sync operations (audio-based sync and manual offset adjustment).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AudioExecutor ¶ added in v0.5.0
type AudioExecutor struct {
Store SyncStore
Proc SubtitleProcessor
Media mediaWriter
Runner AudioJobRunner
}
AudioExecutor runs one accepted sync job end to end: read and normalize the subtitle at RUN time (the analysis sees current content, not accept-time content), run the typed core — whose admission hook the dispatcher supplies — and on a result apply the correction (SRT write-back plus cumulative offset bookkeeping, exactly the synchronous handler's old apply path). It is constructed by the composition root and handed to the dispatcher as its execFunc.
func (*AudioExecutor) Execute ¶ added in v0.5.0
func (e *AudioExecutor) Execute(ctx context.Context, in *syncjobs.ExecInput, hook func() bool) syncjobs.ExecResult
Execute implements syncjobs.execFunc.
type AudioJobRunner ¶ added in v0.5.0
type AudioJobRunner interface {
RunAudio(ctx context.Context, data []byte, videoPath, subtitlePath string, hook syncworker.AdmissionHook) syncworker.RunOutcome
}
AudioJobRunner is the typed sync core the executor drives: the hook-taking audio run with named outcomes. *syncworker.Client satisfies it (both the process-isolating and the in-process construction).
type Deps ¶
type Deps struct {
Store SyncStore
Files seasonFileStore
SubtitleProc SubtitleProcessor
Media mediaWriter
Jobs *syncjobs.Dispatcher
Resolve *resolve.Resolver
SeasonState func() *SeasonState
}
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. Jobs is the async sync dispatcher POST /api/sync/audio and POST /api/sync/season hand accepted work to; Files and SeasonState feed the season batch's enumeration.
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler holds all dependencies for the sync handler family.
func (*Handler) HandleSyncAudio ¶
func (h *Handler) HandleSyncAudio(w http.ResponseWriter, r *http.Request)
HandleSyncAudio handles POST /api/sync/audio: validate, then hand the job to the dispatcher and answer 202 {activity_id, job_id}. The dialog matches the terminal sync:done event on job_id; a same-file dispatch answers the EXISTING job's ids (even at capacity), and a full admission lease answers a typed 429 the client renders inline and never auto-retries.
func (*Handler) HandleSyncJobs ¶ added in v0.5.0
func (h *Handler) HandleSyncJobs(w http.ResponseWriter, r *http.Request)
HandleSyncJobs handles GET /api/sync/jobs: the job registry in its total order (accepted_at DESC, job_id DESC), optionally filtered by batch_activity_id. The reload path re-attaches through this read.
func (*Handler) HandleSyncOffset ¶
func (h *Handler) HandleSyncOffset(w http.ResponseWriter, r *http.Request)
HandleSyncOffset handles POST /api/sync/offset.
func (*Handler) HandleSyncSeason ¶ added in v0.5.0
func (h *Handler) HandleSyncSeason(w http.ResponseWriter, r *http.Request)
HandleSyncSeason handles POST /api/sync/season: enumerate server-side, then hand ONE batch to the dispatcher and answer 202 {activity_id}. Every per-item fact lives in the job registry (all item records created at acceptance); the batch activity entry carries the aggregate only.
type SeasonState ¶ added in v0.5.0
type SeasonState struct {
Cfg seasonCfg
Sonarr seasonSonarr
}
SeasonState is the hot-reloadable dependency snapshot for one season dispatch. Sonarr is nil when not configured.
type SeasonSyncAccepted ¶ added in v0.5.0
type SeasonSyncAccepted struct {
ActivityID string `json:"activity_id"`
}
SeasonSyncAccepted is the 202 body for POST /api/sync/season: the batch activity id. Item job ids arrive via the registry read (GET /api/sync/jobs?batch_activity_id=) and the per-item sync:done events.
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)
}
SubtitleProcessor is the SRT surface the sync verbs drive: decode to UTF-8, parse to cues, and re-serialize. The heavy audio analysis is NOT here — the async job executor drives the typed sync core directly (AudioJobRunner), and cues arrive in its result.
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 SyncAccepted ¶ added in v0.5.0
SyncAccepted is the 202 body for POST /api/sync/audio: the activity entry id and the numeric job id the dialog correlates sync:done on.
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 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 SyncSeasonRequest ¶ added in v0.5.0
SyncSeasonRequest is the typed body for POST /api/sync/season: the Sonarr series id plus the season whose subtitle files the server enumerates.
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.