Save uncommitted changes
Build / Lint & Test (push) Successful in 22s

This commit is contained in:
PickleRick committed 2026-09-21 10:42:08 +02:00
1 parent 3f0b38d513
commit a8c4a81141
8 files changed
+271 -19

No files matched your search

@@ -72,11 +72,14 @@ const normLang = (tag) => {
const buildSuffix = (lang, stream) => {
const parts = [lang];
if (stream.disposition && stream.disposition.forced) parts.push('forced');
if (stream.disposition && stream.disposition.default) parts.push('default');
const forced = stream.disposition && stream.disposition.forced;
const title = ((stream.tags && (stream.tags.title || stream.tags.TITLE)) || '').toLowerCase();
const isForced = Boolean(forced || title.includes('forced'));
if (isForced) parts.push('forced');
if (isForced || (stream.disposition && stream.disposition.default)) parts.push('default');
if (stream.disposition && stream.disposition.hearing_impaired) parts.push('sdh');
const title = ((stream.tags && stream.tags.title) || '').toLowerCase();
if (!parts.includes('sdh') && title.includes('sdh')) parts.push('sdh');
if (!parts.includes('sdh') && (title.includes('sdh') || title.includes('hearing impaired')
|| title.includes('hearing_impaired'))) parts.push('sdh');
return parts.join('.');
};
@@ -120,7 +123,7 @@ const plugin = async (args) => {
const subtitleEditPath = args.inputs.subtitleEditPath || 'SubtitleEdit';
const targetLangs = (args.inputs.languages || 'ita,eng')
.split(',').map((l) => l.trim().toLowerCase()).filter(Boolean);
.split(',').map((l) => normLang(l)).filter(Boolean);
const streams = (inputFileObj.ffProbeData && inputFileObj.ffProbeData.streams) || [];
const subtitleStreams = streams.filter((s) => s.codec_type === 'subtitle');
@@ -134,6 +137,7 @@ const plugin = async (args) => {
const textTasks = [];
const bitmapTasks = [];
const taskByOutput = new Map();
for (const stream of subtitleStreams) {
const lang = normLang((stream.tags && stream.tags.language) || '');
@@ -146,13 +150,23 @@ const plugin = async (args) => {
const suffix = buildSuffix(lang, stream);
const outSrt = path.join(targetDir, `${baseName}.${suffix}.srt`);
if (TEXT_CODECS.has(codec)) {
textTasks.push({ stream, lang, codec, outSrt });
} else if (BITMAP_CODECS.has(codec)) {
bitmapTasks.push({ stream, lang, codec, outSrt });
const task = { stream, lang, codec, outSrt };
const isText = TEXT_CODECS.has(codec);
const isBitmap = BITMAP_CODECS.has(codec);
if (isText || isBitmap) {
const existing = taskByOutput.get(outSrt);
if (!existing || (isText && existing.type === 'bitmap')) {
taskByOutput.set(outSrt, { ...task, type: isText ? 'text' : 'bitmap' });
}
} else {
jobLog(`[extractSubtitlesAndOcr] Stream #${stream.index} codec "${codec}" not supported — skipping.\n`);
}
}
for (const task of taskByOutput.values()) {
if (task.type === 'text') textTasks.push(task);
else bitmapTasks.push(task);
}
// ── 1. Batch extract text-based subtitles (mkvextract or single-pass FFmpeg)