fix(node-sub): move back sub in case of sync failure
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
40ee4f048c
commit
d625b740be
1 changed files with 9 additions and 13 deletions
|
@ -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);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue