Compare commits

..

No commits in common. "0ee3f248b85b40cf5bd4655dffb32839f89ec836" and "da7e710d2f4be5a3a2fc9a304a6709774e66c169" have entirely different histories.

View file

@ -33,8 +33,6 @@ else {
process.exit(1); process.exit(1);
} }
const escapePath = (p: string) => p.replaceAll("'", "'\\''");
function getVideoPath(files: string[]) { function getVideoPath(files: string[]) {
const fileName = DIR.split('/').at(-1) ?? ''; const fileName = DIR.split('/').at(-1) ?? '';
@ -55,7 +53,6 @@ async function backupSubs(files: string[]) {
await mkdir(`${DIR}/.srt.bak`); await mkdir(`${DIR}/.srt.bak`);
} }
else { else {
// TODO: compare with subs outside of backup dir
const backups = await readDir(`${DIR}/.srt.bak`); const backups = await readDir(`${DIR}/.srt.bak`);
// Remove synced subtitles from the list to sync // Remove synced subtitles from the list to sync
@ -87,7 +84,7 @@ function runSubSync(
onError(error.message); onError(error.message);
} }
spawn('chmod', ['-R', '775', `'${escapePath(DIR)}'`], SPAWN_OPTS); spawn('chmod', ['-R', '775', `'${DIR}'`], SPAWN_OPTS);
} }
async function main() { async function main() {
@ -102,7 +99,7 @@ async function main() {
ffProbe(VIDEO, (_e, data) => { ffProbe(VIDEO, (_e, data) => {
if (!data?.streams) { if (!data?.streams) {
console.error('Couldn\'t find streams in video file'); console.error('Couldn\'t find streams in video file');
process.exit(0); process.exit(1);
} }
const AVAIL_LANGS = data.streams const AVAIL_LANGS = data.streams
@ -124,9 +121,9 @@ async function main() {
AVAIL_LANGS[0]}`, AVAIL_LANGS[0]}`,
'--ref-stream-by-type "audio"', '--ref-stream-by-type "audio"',
`--sub '${escapePath(IN_FILE)}'`, `--sub '${IN_FILE}'`,
`--out '${escapePath(OUT_FILE)}'`, `--out '${OUT_FILE}'`,
`--ref '${escapePath(VIDEO)}'`, `--ref '${VIDEO}'`,
]; ];
if (files.includes(FILE_NAME)) { if (files.includes(FILE_NAME)) {
@ -164,24 +161,21 @@ async function main() {
else { else {
// Extract subtitle // Extract subtitle
spawn('ffmpeg', [ spawn('ffmpeg', [
'-i', `'${escapePath(VIDEO)}'`, '-i', `'${VIDEO}'`,
'-map', `"0:${subs[0].index}"`, `'${escapePath(IN_FILE)}'`, '-map', `"0:${subs[0].index}"`, `'${IN_FILE}'`,
], SPAWN_OPTS); ], SPAWN_OPTS);
// Delete subtitle from video // Delete subtitle from video
spawn('mv', [ spawn('mv', [`'${VIDEO}'`, `'${VIDEO}.bak'`], SPAWN_OPTS);
`'${escapePath(VIDEO)}'`,
`'${escapePath(VIDEO)}.bak'`,
], SPAWN_OPTS);
spawn('ffmpeg', [ spawn('ffmpeg', [
'-i', `'${escapePath(VIDEO)}.bak'`, '-i', `'${VIDEO}.bak'`,
'-map', '0', '-map', '0',
'-map', `-0:${subs[0].index}`, '-map', `-0:${subs[0].index}`,
'-c', 'copy', `'${escapePath(VIDEO)}'`, '-c', 'copy', `'${VIDEO}'`,
], SPAWN_OPTS); ], SPAWN_OPTS);
spawn('rm', [`'${escapePath(VIDEO)}.bak'`], SPAWN_OPTS); spawn('rm', [`'${VIDEO}.bak'`], SPAWN_OPTS);
// Sync extracted subtitle // Sync extracted subtitle
runSubSync(cmd, async() => { runSubSync(cmd, async() => {