fix(node-sub): move back sub in case of sync failure
All checks were successful
Discord / discord commits (push) Has been skipped

This commit is contained in:
matt1432 2024-04-24 14:50:25 -04:00
parent 40ee4f048c
commit d625b740be

View file

@ -75,16 +75,16 @@ async function backupSubs(files: string[]) {
} }
} }
function runSubSync( async function runSubSync(
cmd: string[], cmd: string[],
onError = (error?: string) => { input: string,
console.error(error); output: string,
},
) { ) {
const { error } = spawn('subsync', cmd, SPAWN_OPTS); spawn('subsync', cmd, SPAWN_OPTS);
if (error) { if (!(await readDir(DIR)).includes(output)) {
onError(error.message); await mv(input, output);
console.log('Subtitle was moved back');
} }
spawn('chmod', ['-R', '775', `'${escapePath(DIR)}'`], SPAWN_OPTS); spawn('chmod', ['-R', '775', `'${escapePath(DIR)}'`], SPAWN_OPTS);
@ -132,9 +132,7 @@ async function main() {
if (files.includes(FILE_NAME)) { if (files.includes(FILE_NAME)) {
await mv(OUT_FILE, IN_FILE); await mv(OUT_FILE, IN_FILE);
runSubSync(cmd, async() => { runSubSync(cmd, IN_FILE, OUT_FILE);
await mv(IN_FILE, OUT_FILE);
});
} }
else { else {
let subs = data.streams.filter((s) => { let subs = data.streams.filter((s) => {
@ -184,9 +182,7 @@ async function main() {
spawn('rm', [`'${escapePath(VIDEO)}.bak'`], SPAWN_OPTS); spawn('rm', [`'${escapePath(VIDEO)}.bak'`], SPAWN_OPTS);
// Sync extracted subtitle // Sync extracted subtitle
runSubSync(cmd, async() => { runSubSync(cmd, IN_FILE, OUT_FILE);
await mv(IN_FILE, OUT_FILE);
});
} }
} }
}); });