feat(node-syncsub): substract subs from video file if not found
All checks were successful
Discord / discord commits (push) Has been skipped
All checks were successful
Discord / discord commits (push) Has been skipped
This commit is contained in:
parent
aeddb3eb92
commit
57816ab604
2 changed files with 42 additions and 11 deletions
|
@ -232,6 +232,7 @@ export const ISO6393To1 = new Map([
|
||||||
['fij', 'fj'],
|
['fij', 'fj'],
|
||||||
['fin', 'fi'],
|
['fin', 'fi'],
|
||||||
['fra', 'fr'],
|
['fra', 'fr'],
|
||||||
|
['fre', 'fr'],
|
||||||
['fry', 'fy'],
|
['fry', 'fy'],
|
||||||
['ful', 'ff'],
|
['ful', 'ff'],
|
||||||
['gla', 'gd'],
|
['gla', 'gd'],
|
||||||
|
|
|
@ -38,6 +38,13 @@ function getVideoPath(files: string[]) {
|
||||||
!f.endsWith('.srt'))[0]}`;
|
!f.endsWith('.srt'))[0]}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function runSubSync(cmd: string[]) {
|
||||||
|
spawn('subsync', cmd, {
|
||||||
|
shell: true,
|
||||||
|
stdio: [process.stdin, process.stdout, process.stderr],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
const files = await readDir(DIR);
|
const files = await readDir(DIR);
|
||||||
|
|
||||||
|
@ -74,13 +81,6 @@ async function main() {
|
||||||
const IN_FILE = `${DIR}/.srt.bak/${FILE_NAME}`;
|
const IN_FILE = `${DIR}/.srt.bak/${FILE_NAME}`;
|
||||||
const OUT_FILE = `${DIR}/${FILE_NAME}`;
|
const OUT_FILE = `${DIR}/${FILE_NAME}`;
|
||||||
|
|
||||||
if (files.includes(FILE_NAME)) {
|
|
||||||
await mv(OUT_FILE, IN_FILE);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// TODO: check data and extract sub
|
|
||||||
}
|
|
||||||
|
|
||||||
const cmd = [
|
const cmd = [
|
||||||
'--cli sync',
|
'--cli sync',
|
||||||
`--sub-lang ${lang}`,
|
`--sub-lang ${lang}`,
|
||||||
|
@ -95,10 +95,40 @@ async function main() {
|
||||||
`--ref '${VIDEO}'`,
|
`--ref '${VIDEO}'`,
|
||||||
];
|
];
|
||||||
|
|
||||||
spawn('subsync', cmd, {
|
if (files.includes(FILE_NAME)) {
|
||||||
|
await mv(OUT_FILE, IN_FILE);
|
||||||
|
runSubSync(cmd);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
let stream = data.streams.find((s) => {
|
||||||
|
return s['tags']['language'] === lang &&
|
||||||
|
s.disposition!.forced === 0 &&
|
||||||
|
s.codec_type === 'subtitle';
|
||||||
|
})!.index;
|
||||||
|
|
||||||
|
if (!stream) {
|
||||||
|
stream = data.streams.find((s) => {
|
||||||
|
return s['tags']['language'] === lang &&
|
||||||
|
s.codec_type === 'subtitle';
|
||||||
|
})!.index;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!stream) {
|
||||||
|
console.warn(`No subtitle tracks were found for ${lang}`);
|
||||||
|
process.exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
spawn('ffmpeg', [
|
||||||
|
'-i', `'${VIDEO}'`,
|
||||||
|
'-map', `0:${stream}`, `'${IN_FILE}'`,
|
||||||
|
], {
|
||||||
shell: true,
|
shell: true,
|
||||||
stdio: [process.stdin, process.stdout, process.stderr],
|
stdio: [process.stdin, process.stdout, process.stderr],
|
||||||
|
|
||||||
|
}).on('close', () => {
|
||||||
|
runSubSync(cmd);
|
||||||
});
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue