feat(node-sub): add warning when no SRT subs 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
8bf6851698
commit
1c214aaadd
2 changed files with 49 additions and 42 deletions
|
@ -31,9 +31,9 @@ in {
|
||||||
];
|
];
|
||||||
|
|
||||||
script = ''
|
script = ''
|
||||||
# find /data/anime -name '*.srt' -exec node-syncsub "{}" \;
|
find /data/movies -name '*.mkv' -printf "%h\0" | xargs -0 -I '{}' node-syncsub '{}' "eng,fra"
|
||||||
# find /data/movies -name '*.srt' -exec node-syncsub "{}" \;
|
# find /data/anime -name '*.mkv' -printf "%h\0" | xargs -0 -I '{}' node-syncsub '{}' "eng,fra"
|
||||||
# find /data/tv -name '*.srt' -exec node-syncsub "{}" \;
|
# find /data/tv -name '*.mkv' -printf "%h\0" | xargs -0 -I '{}' node-syncsub '{}' "eng,fra"
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
timers.subsync-job = {
|
timers.subsync-job = {
|
||||||
|
|
|
@ -101,7 +101,7 @@ async function main() {
|
||||||
ffProbe(VIDEO, (_e, data) => {
|
ffProbe(VIDEO, (_e, data) => {
|
||||||
const AVAIL_LANGS = data.streams
|
const AVAIL_LANGS = data.streams
|
||||||
.filter((s) => s.codec_type === 'audio')
|
.filter((s) => s.codec_type === 'audio')
|
||||||
.map((s) => s['tags']['language']);
|
.map((s) => s['tags'] && s['tags']['language']);
|
||||||
|
|
||||||
// Sync subtitles one by one
|
// Sync subtitles one by one
|
||||||
langs.forEach(async(lang) => {
|
langs.forEach(async(lang) => {
|
||||||
|
@ -131,46 +131,53 @@ async function main() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
let stream = data.streams.find((s) => {
|
let subs = data.streams.filter((s) => {
|
||||||
return s['tags']['language'] === lang &&
|
return s['tags'] &&
|
||||||
s.disposition?.forced === 0 &&
|
s['tags']['language'] &&
|
||||||
|
s['tags']['language'] === lang &&
|
||||||
s.codec_type === 'subtitle';
|
s.codec_type === 'subtitle';
|
||||||
})?.index ?? -1;
|
|
||||||
|
|
||||||
if (stream === -1) {
|
|
||||||
stream = data.streams.find((s) => {
|
|
||||||
return s['tags']['language'] === lang &&
|
|
||||||
s.codec_type === 'subtitle';
|
|
||||||
})?.index ?? -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (stream === -1) {
|
|
||||||
console.warn(`No subtitle tracks were found for ${lang}`);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Extract subtitles
|
|
||||||
spawn('ffmpeg', [
|
|
||||||
'-i', `'${VIDEO}'`,
|
|
||||||
'-map', `"0:${stream}"`, `'${IN_FILE}'`,
|
|
||||||
], SPAWN_OPTS);
|
|
||||||
|
|
||||||
// Delete subtitles from video
|
|
||||||
spawn('mv', [`'${VIDEO}'`, `'${VIDEO}.bak'`], SPAWN_OPTS);
|
|
||||||
|
|
||||||
spawn('ffmpeg', [
|
|
||||||
'-i', `'${VIDEO}.bak'`,
|
|
||||||
'-map', '0',
|
|
||||||
'-map', `-0:${stream}`,
|
|
||||||
'-c', 'copy', `'${VIDEO}'`,
|
|
||||||
], SPAWN_OPTS);
|
|
||||||
|
|
||||||
spawn('rm', [`'${VIDEO}.bak'`], SPAWN_OPTS);
|
|
||||||
|
|
||||||
runSubSync(cmd, async() => {
|
|
||||||
await mv(IN_FILE, OUT_FILE);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const pgs = subs.filter((s) => s.codec_name === 'hdmv_pgs_subtitle');
|
||||||
|
|
||||||
|
// If we only have PGS subs, warn user
|
||||||
|
if (pgs.length === subs.length) {
|
||||||
|
console.warn(`No SRT subtitle tracks were found for ${lang}`);
|
||||||
|
}
|
||||||
|
// Remove PGS streams from subs
|
||||||
|
subs = subs.filter((s) => s.codec_name !== 'hdmv_pgs_subtitle');
|
||||||
|
|
||||||
|
// Prefer normal subs
|
||||||
|
if (subs.length !== 1) {
|
||||||
|
subs = subs.filter((s) => s.disposition?.forced === 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (subs.length === 0) {
|
||||||
|
console.warn(`No subtitle tracks were found for ${lang}`);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// Extract subtitles
|
||||||
|
spawn('ffmpeg', [
|
||||||
|
'-i', `'${VIDEO}'`,
|
||||||
|
'-map', `"0:${subs[0].index}"`, `'${IN_FILE}'`,
|
||||||
|
], SPAWN_OPTS);
|
||||||
|
|
||||||
|
// Delete subtitles from video
|
||||||
|
spawn('mv', [`'${VIDEO}'`, `'${VIDEO}.bak'`], SPAWN_OPTS);
|
||||||
|
|
||||||
|
spawn('ffmpeg', [
|
||||||
|
'-i', `'${VIDEO}.bak'`,
|
||||||
|
'-map', '0',
|
||||||
|
'-map', `-0:${subs[0].index}`,
|
||||||
|
'-c', 'copy', `'${VIDEO}'`,
|
||||||
|
], SPAWN_OPTS);
|
||||||
|
|
||||||
|
spawn('rm', [`'${VIDEO}.bak'`], SPAWN_OPTS);
|
||||||
|
|
||||||
|
runSubSync(cmd, async() => {
|
||||||
|
await mv(IN_FILE, OUT_FILE);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue