feat(node-sub): add warning when no SRT subs found
All checks were successful
Discord / discord commits (push) Has been skipped

This commit is contained in:
matt1432 2024-04-01 18:40:15 -04:00
parent 8bf6851698
commit 1c214aaadd
2 changed files with 49 additions and 42 deletions

View file

@ -31,9 +31,9 @@ in {
];
script = ''
# find /data/anime -name '*.srt' -exec node-syncsub "{}" \;
# find /data/movies -name '*.srt' -exec node-syncsub "{}" \;
# find /data/tv -name '*.srt' -exec node-syncsub "{}" \;
find /data/movies -name '*.mkv' -printf "%h\0" | xargs -0 -I '{}' node-syncsub '{}' "eng,fra"
# find /data/anime -name '*.mkv' -printf "%h\0" | xargs -0 -I '{}' node-syncsub '{}' "eng,fra"
# find /data/tv -name '*.mkv' -printf "%h\0" | xargs -0 -I '{}' node-syncsub '{}' "eng,fra"
'';
};
timers.subsync-job = {

View file

@ -101,7 +101,7 @@ async function main() {
ffProbe(VIDEO, (_e, data) => {
const AVAIL_LANGS = data.streams
.filter((s) => s.codec_type === 'audio')
.map((s) => s['tags']['language']);
.map((s) => s['tags'] && s['tags']['language']);
// Sync subtitles one by one
langs.forEach(async(lang) => {
@ -131,29 +131,35 @@ async function main() {
});
}
else {
let stream = data.streams.find((s) => {
return s['tags']['language'] === lang &&
s.disposition?.forced === 0 &&
let subs = data.streams.filter((s) => {
return s['tags'] &&
s['tags']['language'] &&
s['tags']['language'] === lang &&
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;
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 (stream === -1) {
if (subs.length === 0) {
console.warn(`No subtitle tracks were found for ${lang}`);
return;
}
else {
// Extract subtitles
spawn('ffmpeg', [
'-i', `'${VIDEO}'`,
'-map', `"0:${stream}"`, `'${IN_FILE}'`,
'-map', `"0:${subs[0].index}"`, `'${IN_FILE}'`,
], SPAWN_OPTS);
// Delete subtitles from video
@ -162,7 +168,7 @@ async function main() {
spawn('ffmpeg', [
'-i', `'${VIDEO}.bak'`,
'-map', '0',
'-map', `-0:${stream}`,
'-map', `-0:${subs[0].index}`,
'-c', 'copy', `'${VIDEO}'`,
], SPAWN_OPTS);
@ -172,6 +178,7 @@ async function main() {
await mv(IN_FILE, OUT_FILE);
});
}
}
});
});
}