mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-11-28 04:46:07 -08:00
fix(subsync): address PR review of track identity, tool output, and cancellation
- check the active target's source identity too (mpv reuses freed track ids) - include device and inode in the source stamp so a retargeted symlink is caught - reject external-engine output with no readable cues instead of installing it - leave the user's secondary track alone if they changed it during the lookup - reject scene-cut splits that would reorder dialogue lines - document that full line-start agreement overrides the weak-quarter cap - spawn ffmpeg launchers in their own process group and check aborts before spawning (an aborted signal hit a TDZ ReferenceError) - cache the built-in VAD fallback under its own key so Silero is retried - kill the tool directly when taskkill exits nonzero
This commit is contained in:
9 files changed
+219
-47
No files matched your search
@@ -275,11 +275,14 @@ export function buildRetimedPath(subPath: string, replace: boolean): string {
|
||||
export const LOSSY_REWRITE_ERROR_MESSAGE =
|
||||
'Cannot safely rewrite subtitle file because its text encoding could not be decoded unambiguously and losslessly. Convert the file to UTF-8 and retry.';
|
||||
|
||||
/** Size + mtime of a subtitle file, compared before an in-place rewrite to catch edits made mid-sync. */
|
||||
/**
|
||||
* Identity (device + inode, through symlinks) plus size and mtime of a subtitle file, compared
|
||||
* before an in-place rewrite to catch edits or a retargeted symlink mid-sync.
|
||||
*/
|
||||
export function readSubtitleFileStamp(filePath: string): string | null {
|
||||
try {
|
||||
const stat = fs.statSync(filePath);
|
||||
return `${stat.size}\0${stat.mtimeMs}`;
|
||||
return `${stat.dev}:${stat.ino}\0${stat.size}\0${stat.mtimeMs}`;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
@@ -499,6 +502,7 @@ export async function loadSyncedSubtitle(
|
||||
typeof track.id === 'number' ? [track.id] : [],
|
||||
),
|
||||
);
|
||||
const secondaryBeforeAdd = await client.requestProperty('secondary-sid');
|
||||
signal?.throwIfAborted();
|
||||
client.send({ command: buildSubAddCommand(pathToLoad, 'auto', sourceTrack) });
|
||||
const addedTrackId = await findAddedSubtitleTrackId(client, pathToLoad, knownTrackIds);
|
||||
@@ -506,6 +510,13 @@ export async function loadSyncedSubtitle(
|
||||
throw new Error('Synchronized subtitle did not appear in the mpv track list');
|
||||
}
|
||||
signal?.throwIfAborted();
|
||||
// The lookup polls for a while; if the user picked another secondary track meanwhile,
|
||||
// keep their choice (and delay) rather than overriding it.
|
||||
if ((await client.requestProperty('secondary-sid')) !== secondaryBeforeAdd) {
|
||||
throw new Error(
|
||||
`Secondary subtitle changed while loading; saved the synced file at ${pathToLoad} without selecting it.`,
|
||||
);
|
||||
}
|
||||
client.send({ command: ['set_property', 'secondary-sid', addedTrackId] });
|
||||
// The retimed file carries the timing now; only drop the old delay once it is selected.
|
||||
client.send({ command: ['set_property', 'secondary-sub-delay', 0] });
|
||||
|
||||
Reference in new issue
Block a user