feat(subsync): integrate built-in automatic subtitle syncing

This commit is contained in:
sudacode committed 2026-11-25 19:47:56 -08:00
1 parent 926e6b047e
commit 05bdb64880
44 files changed
+6498 -135

No files matched your search

+8
View File
@@ -16,6 +16,8 @@ export interface RuntimeOptionsIpcDepsParams {
export interface SubsyncRuntimeDepsParams {
getMpvClient: () => ReturnType<SubsyncRuntimeDeps['getMpvClient']>;
getResolvedSubsyncConfig: () => SubsyncResolvedConfig;
getVadPaths?: SubsyncRuntimeDeps['getVadPaths'];
canPickReferenceFile?: SubsyncRuntimeDeps['canPickReferenceFile'];
isSubsyncInProgress: () => boolean;
setSubsyncInProgress: (inProgress: boolean) => void;
showMpvOsd: (text: string) => void;
@@ -37,6 +39,8 @@ export function createSubsyncRuntimeDeps(params: SubsyncRuntimeDepsParams): Subs
return {
getMpvClient: params.getMpvClient,
getResolvedSubsyncConfig: params.getResolvedSubsyncConfig,
getVadPaths: params.getVadPaths,
canPickReferenceFile: params.canPickReferenceFile,
isSubsyncInProgress: params.isSubsyncInProgress,
setSubsyncInProgress: params.setSubsyncInProgress,
showMpvOsd: params.showMpvOsd,
@@ -84,6 +88,8 @@ export interface MainIpcRuntimeServiceDepsParams {
getSecondarySubMode: IpcDepsRuntimeOptions['getSecondarySubMode'];
getMpvClient: IpcDepsRuntimeOptions['getMpvClient'];
runSubsyncManual: IpcDepsRuntimeOptions['runSubsyncManual'];
openSubsyncManual?: IpcDepsRuntimeOptions['openSubsyncManual'];
pickSubsyncReferenceFile?: IpcDepsRuntimeOptions['pickSubsyncReferenceFile'];
getRuntimeOptions: IpcDepsRuntimeOptions['getRuntimeOptions'];
setRuntimeOption: IpcDepsRuntimeOptions['setRuntimeOption'];
reportOverlayContentBounds: IpcDepsRuntimeOptions['reportOverlayContentBounds'];
@@ -267,6 +273,8 @@ export function createMainIpcRuntimeServiceDeps(
getSecondarySubMode: params.getSecondarySubMode,
getMpvClient: params.getMpvClient,
runSubsyncManual: params.runSubsyncManual,
openSubsyncManual: params.openSubsyncManual,
pickSubsyncReferenceFile: params.pickSubsyncReferenceFile,
getRuntimeOptions: params.getRuntimeOptions,
setRuntimeOption: params.setRuntimeOption,
reportOverlayContentBounds: params.reportOverlayContentBounds,
+35 -1
View File
@@ -1,20 +1,26 @@
import * as path from 'node:path';
import type { MpvIpcClient } from '../../core/services/mpv';
import {
openSubsyncManualPickerRuntime,
runSubsyncManualFromIpcRuntime,
triggerSubsyncFromConfigRuntime,
} from '../../core/services/subsync-runner';
import { expandSubtitleGenerationPath } from '../../core/services/subtitle-generation-files';
import { SUBTITLE_GENERATION_VAD_MODEL } from '../../shared/subtitle-generation-vad-model';
import type {
SubsyncResult,
SubsyncManualPayload,
SubsyncManualRunRequest,
ResolvedConfig,
} from '../../types';
import { getSubsyncConfig } from '../../subsync/utils';
import { fileExists, findSubsyncExecutable, getSubsyncConfig } from '../../subsync/utils';
import { createSubsyncRuntimeServiceInputFromState } from '../subsync-runtime';
export type MainSubsyncRuntimeDeps = {
getMpvClient: () => MpvIpcClient | null;
getResolvedConfig: () => ResolvedConfig;
getSubtitleGenerationModelDirectory?: () => string;
canPickReferenceFile?: () => boolean;
getSubsyncInProgress: () => boolean;
setSubsyncInProgress: (inProgress: boolean) => void;
showMpvOsd: (text: string) => void;
@@ -23,12 +29,37 @@ export type MainSubsyncRuntimeDeps = {
export function createMainSubsyncRuntime(deps: MainSubsyncRuntimeDeps): {
triggerFromConfig: () => Promise<void>;
openManualPicker: () => Promise<void>;
runManualFromIpc: (request: SubsyncManualRunRequest) => Promise<SubsyncResult>;
} {
const resolveVadPaths = () => {
const config = deps.getResolvedConfig();
const gen = config.subtitleGeneration;
const vadExecutablePath = findSubsyncExecutable(gen?.vadPath, [
'whisper-vad-speech-segments',
'vad-speech-segments',
]);
let vadModelPath: string | null = null;
const configuredModel = gen?.vadModelPath?.trim() ?? '';
if (configuredModel) {
const expanded = path.resolve(expandSubtitleGenerationPath(configuredModel));
if (fileExists(expanded)) vadModelPath = expanded;
} else if (deps.getSubtitleGenerationModelDirectory) {
const managedModel = path.join(
deps.getSubtitleGenerationModelDirectory(),
SUBTITLE_GENERATION_VAD_MODEL.filename,
);
if (fileExists(managedModel)) vadModelPath = managedModel;
}
return { vadExecutablePath, vadModelPath };
};
const getRuntimeServiceParams = () =>
createSubsyncRuntimeServiceInputFromState({
getMpvClient: () => deps.getMpvClient(),
getResolvedSubsyncConfig: () => getSubsyncConfig(deps.getResolvedConfig().subsync),
getVadPaths: resolveVadPaths,
canPickReferenceFile: deps.canPickReferenceFile,
getSubsyncInProgress: () => deps.getSubsyncInProgress(),
setSubsyncInProgress: (inProgress: boolean) => deps.setSubsyncInProgress(inProgress),
showMpvOsd: (text: string) => deps.showMpvOsd(text),
@@ -39,6 +70,9 @@ export function createMainSubsyncRuntime(deps: MainSubsyncRuntimeDeps): {
triggerFromConfig: async (): Promise<void> => {
await triggerSubsyncFromConfigRuntime(getRuntimeServiceParams());
},
openManualPicker: async (): Promise<void> => {
await openSubsyncManualPickerRuntime(getRuntimeServiceParams());
},
runManualFromIpc: async (request: SubsyncManualRunRequest): Promise<SubsyncResult> =>
runSubsyncManualFromIpcRuntime(request, getRuntimeServiceParams()),
};
+13
View File
@@ -3,6 +3,7 @@ import type { SubsyncManualPayload, SubsyncManualRunRequest, SubsyncResult } fro
import type { SubsyncRuntimeDeps } from '../core/services/subsync-runner';
import { createSubsyncRuntimeDeps } from './dependencies';
import {
openSubsyncManualPickerRuntime as openSubsyncManualPickerRuntimeCore,
runSubsyncManualFromIpcRuntime as runSubsyncManualFromIpcRuntimeCore,
triggerSubsyncFromConfigRuntime as triggerSubsyncFromConfigRuntimeCore,
} from '../core/services';
@@ -10,6 +11,8 @@ import {
export interface SubsyncRuntimeServiceInput {
getMpvClient: SubsyncRuntimeDeps['getMpvClient'];
getResolvedSubsyncConfig: () => SubsyncResolvedConfig;
getVadPaths?: SubsyncRuntimeDeps['getVadPaths'];
canPickReferenceFile?: SubsyncRuntimeDeps['canPickReferenceFile'];
isSubsyncInProgress: SubsyncRuntimeDeps['isSubsyncInProgress'];
setSubsyncInProgress: SubsyncRuntimeDeps['setSubsyncInProgress'];
showMpvOsd: SubsyncRuntimeDeps['showMpvOsd'];
@@ -19,6 +22,8 @@ export interface SubsyncRuntimeServiceInput {
export interface SubsyncRuntimeServiceStateInput {
getMpvClient: SubsyncRuntimeServiceInput['getMpvClient'];
getResolvedSubsyncConfig: SubsyncRuntimeServiceInput['getResolvedSubsyncConfig'];
getVadPaths?: SubsyncRuntimeServiceInput['getVadPaths'];
canPickReferenceFile?: SubsyncRuntimeServiceInput['canPickReferenceFile'];
getSubsyncInProgress: () => boolean;
setSubsyncInProgress: SubsyncRuntimeServiceInput['setSubsyncInProgress'];
showMpvOsd: SubsyncRuntimeServiceInput['showMpvOsd'];
@@ -31,6 +36,8 @@ export function createSubsyncRuntimeServiceInputFromState(
return {
getMpvClient: input.getMpvClient,
getResolvedSubsyncConfig: input.getResolvedSubsyncConfig,
getVadPaths: input.getVadPaths,
canPickReferenceFile: input.canPickReferenceFile,
isSubsyncInProgress: input.getSubsyncInProgress,
setSubsyncInProgress: input.setSubsyncInProgress,
showMpvOsd: input.showMpvOsd,
@@ -44,6 +51,8 @@ export function createSubsyncRuntimeServiceDeps(
return createSubsyncRuntimeDeps({
getMpvClient: params.getMpvClient,
getResolvedSubsyncConfig: params.getResolvedSubsyncConfig,
getVadPaths: params.getVadPaths,
canPickReferenceFile: params.canPickReferenceFile,
isSubsyncInProgress: params.isSubsyncInProgress,
setSubsyncInProgress: params.setSubsyncInProgress,
showMpvOsd: params.showMpvOsd,
@@ -55,6 +64,10 @@ export function triggerSubsyncFromConfigRuntime(params: SubsyncRuntimeServiceInp
return triggerSubsyncFromConfigRuntimeCore(createSubsyncRuntimeServiceDeps(params));
}
export function openSubsyncManualPickerRuntime(params: SubsyncRuntimeServiceInput): Promise<void> {
return openSubsyncManualPickerRuntimeCore(createSubsyncRuntimeServiceDeps(params));
}
export async function runSubsyncManualFromIpcRuntime(
request: SubsyncManualRunRequest,
params: SubsyncRuntimeServiceInput,