mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-11-27 04:46:07 -08:00
fix(subsync): retry embedded tracks omitted from partial combined pass
- Remote auto-sync now retries each ranked embedded track individually when the combined ffmpeg pass fails or returns a partial map - Errors from applying an alignment during the individual fallback now reach the user instead of being swallowed - Manual alass no longer requires ffmpeg up front, and the Jellyfin path now passes fetchImpl through - Tests clean up their temp dirs and add coverage for partial batches, external references and apply errors
This commit is contained in:
2 files changed
+682
-366
No files matched your search
+645
-310
File diff suppressed because it is too large.
Load diff
@@ -1092,23 +1092,8 @@ async function runBuiltinSubsync(
|
|||||||
message: 'Reference and out-of-sync subtitles must be different tracks',
|
message: 'Reference and out-of-sync subtitles must be different tracks',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
const referenceExtension = codecToExtension(referenceTrack.codec);
|
|
||||||
const canTryJellyfinHttp =
|
|
||||||
!referenceTrack.external &&
|
|
||||||
isRemoteMediaPath(context.videoPath) &&
|
|
||||||
typeof referenceTrack['ff-index'] === 'number' &&
|
|
||||||
referenceExtension !== null &&
|
|
||||||
buildJellyfinEmbeddedSubtitleUrl(
|
|
||||||
context.videoPath,
|
|
||||||
referenceTrack['ff-index'],
|
|
||||||
referenceExtension,
|
|
||||||
) !== null;
|
|
||||||
const ffmpegPath =
|
|
||||||
referenceTrack.external || canTryJellyfinHttp
|
|
||||||
? resolved.ffmpegPath
|
|
||||||
: ensureExecutablePath(resolved.ffmpegPath, 'ffmpeg');
|
|
||||||
refExtraction = await extractSubtitleTrackToFile(
|
refExtraction = await extractSubtitleTrackToFile(
|
||||||
ffmpegPath,
|
resolved.ffmpegPath,
|
||||||
context.videoPath,
|
context.videoPath,
|
||||||
referenceTrack,
|
referenceTrack,
|
||||||
context.workingDirectory,
|
context.workingDirectory,
|
||||||
@@ -1434,6 +1419,7 @@ export async function runSubsyncManual(
|
|||||||
resolved,
|
resolved,
|
||||||
client,
|
client,
|
||||||
targetSlot,
|
targetSlot,
|
||||||
|
deps.fetchImpl,
|
||||||
);
|
);
|
||||||
} finally {
|
} finally {
|
||||||
cleanupTemporaryFile(cleaned);
|
cleanupTemporaryFile(cleaned);
|
||||||
@@ -1448,25 +1434,11 @@ export async function runSubsyncManual(
|
|||||||
return { ok: false, message: 'Reference and out-of-sync subtitles must be different tracks' };
|
return { ok: false, message: 'Reference and out-of-sync subtitles must be different tracks' };
|
||||||
}
|
}
|
||||||
|
|
||||||
const referenceExtension = codecToExtension(referenceTrack.codec);
|
|
||||||
const canTryJellyfinHttp =
|
|
||||||
!referenceTrack.external &&
|
|
||||||
isRemoteMediaPath(context.videoPath) &&
|
|
||||||
typeof referenceTrack['ff-index'] === 'number' &&
|
|
||||||
referenceExtension !== null &&
|
|
||||||
buildJellyfinEmbeddedSubtitleUrl(
|
|
||||||
context.videoPath,
|
|
||||||
referenceTrack['ff-index'],
|
|
||||||
referenceExtension,
|
|
||||||
) !== null;
|
|
||||||
const ffmpegPath = canTryJellyfinHttp
|
|
||||||
? resolved.ffmpegPath
|
|
||||||
: ensureExecutablePath(resolved.ffmpegPath, 'ffmpeg');
|
|
||||||
let referenceExtraction: FileExtractionResult | null = null;
|
let referenceExtraction: FileExtractionResult | null = null;
|
||||||
let cleanedRef: FileExtractionResult | null = null;
|
let cleanedRef: FileExtractionResult | null = null;
|
||||||
try {
|
try {
|
||||||
referenceExtraction = await extractSubtitleTrackToFile(
|
referenceExtraction = await extractSubtitleTrackToFile(
|
||||||
ffmpegPath,
|
resolved.ffmpegPath,
|
||||||
context.videoPath,
|
context.videoPath,
|
||||||
referenceTrack,
|
referenceTrack,
|
||||||
context.workingDirectory,
|
context.workingDirectory,
|
||||||
@@ -2039,34 +2011,43 @@ async function runAutoSubsync(deps: TriggerSubsyncFromConfigDeps): Promise<void>
|
|||||||
includeAudio: false,
|
includeAudio: false,
|
||||||
});
|
});
|
||||||
if (singlePass) {
|
if (singlePass) {
|
||||||
for (const [ffIndex, parsed] of singlePass.embeddedSubtitles) {
|
for (const item of remainingItems) {
|
||||||
remoteExtracted.set(ffIndex, parsed);
|
const parsed = singlePass.embeddedSubtitles.get(item.ffIndex);
|
||||||
}
|
if (!parsed) continue;
|
||||||
} else {
|
if (await tryAlignRemoteEmbeddedTrack(item, parsed)) {
|
||||||
// Single-pass failed (e.g. one broken track aborted the combined pass): try
|
return;
|
||||||
// remaining tracks individually in rank order and stop on the first confident match.
|
|
||||||
for (const fallbackItem of remainingItems) {
|
|
||||||
let extraction: FileExtractionResult | null = null;
|
|
||||||
try {
|
|
||||||
extraction = await extractSubtitleTrackToFile(
|
|
||||||
resolved.ffmpegPath,
|
|
||||||
context.videoPath,
|
|
||||||
fallbackItem.track,
|
|
||||||
context.workingDirectory,
|
|
||||||
deps.fetchImpl,
|
|
||||||
);
|
|
||||||
const parsed = readAndParseSubtitleFile(extraction.path);
|
|
||||||
if (parsed.events.length === 0) continue;
|
|
||||||
if (await tryAlignRemoteEmbeddedTrack(fallbackItem, parsed)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
// Continue to lower-ranked sibling tracks if this track fails.
|
|
||||||
} finally {
|
|
||||||
cleanupTemporaryFile(extraction);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Retry any ranked track omitted by the combined pass (whether the pass returned null
|
||||||
|
// or a partial map) individually in rank order, stopping on the first confident match.
|
||||||
|
const missingItems = remainingItems.filter(
|
||||||
|
(item) => !remoteExtracted.has(item.ffIndex),
|
||||||
|
);
|
||||||
|
for (const fallbackItem of missingItems) {
|
||||||
|
let extraction: FileExtractionResult | null = null;
|
||||||
|
let parsed: ParsedSubtitleFile | null = null;
|
||||||
|
try {
|
||||||
|
extraction = await extractSubtitleTrackToFile(
|
||||||
|
resolved.ffmpegPath,
|
||||||
|
context.videoPath,
|
||||||
|
fallbackItem.track,
|
||||||
|
context.workingDirectory,
|
||||||
|
deps.fetchImpl,
|
||||||
|
);
|
||||||
|
parsed = readAndParseSubtitleFile(extraction.path);
|
||||||
|
} catch {
|
||||||
|
// Continue to lower-ranked sibling tracks if extracting or parsing this track fails.
|
||||||
|
continue;
|
||||||
|
} finally {
|
||||||
|
cleanupTemporaryFile(extraction);
|
||||||
|
}
|
||||||
|
if (parsed.events.length === 0) continue;
|
||||||
|
if (await tryAlignRemoteEmbeddedTrack(fallbackItem, parsed)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (remoteExtracted.size > 0) {
|
if (remoteExtracted.size > 0) {
|
||||||
|
|||||||
Reference in new issue
Block a user