feat(node-subsync): use ffprobe to check available languages
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
0653a897d7
commit
902364e391
6 changed files with 47 additions and 27 deletions
|
@ -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/anime -name '*.srt' -exec node-syncsub "{}" \;
|
||||
# find /data/movies -name '*.srt' -exec node-syncsub "{}" \;
|
||||
# find /data/tv -name '*.srt' -exec node-syncsub "{}" \;
|
||||
'';
|
||||
};
|
||||
timers.subsync-job = {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
{
|
||||
buildNpmPackage,
|
||||
ffmpeg,
|
||||
nodejs_20,
|
||||
subsync,
|
||||
typescript,
|
||||
|
@ -8,13 +9,13 @@
|
|||
buildNpmPackage {
|
||||
name = "node-syncsub";
|
||||
src = ./.;
|
||||
npmDepsHash = "sha256-kQBZ13bTMxZnv45IwyIV0cYA5tjr4KKU1cpDNx02th0=
|
||||
";
|
||||
npmDepsHash = "sha256-O00VQPCUX6T+rtK3VcAibBipXFwNs4AFA3251qycPBQ=";
|
||||
|
||||
nativeBuildInputs = [
|
||||
nodejs_20
|
||||
ffmpeg
|
||||
subsync
|
||||
typescript
|
||||
nodejs_20
|
||||
];
|
||||
|
||||
buildPhase = ''
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
import { readdir } from 'fs';
|
||||
import { ffprobe } from 'fluent-ffmpeg';
|
||||
import { exec } from 'child_process';
|
||||
|
||||
const SUB_EXT_LENGTH = 7;
|
||||
|
||||
|
@ -14,40 +16,53 @@ const main = () => {
|
|||
const DIR = FILE.substring(0, FILE.lastIndexOf('/'));
|
||||
|
||||
readdir(DIR, (_, files) => {
|
||||
const VIDEO = files.filter((f) =>
|
||||
const VIDEO = `${DIR}/${files.filter((f) =>
|
||||
f.includes(BASE_NAME) &&
|
||||
!f.endsWith('.nfo') &&
|
||||
!f.endsWith('.srt'))[0];
|
||||
!f.endsWith('.srt'))[0]}`;
|
||||
|
||||
let lang = FILE.split('.').at(-2);
|
||||
ffprobe(VIDEO, (_e, data) => {
|
||||
const other = (lang: string) => lang === 'fre' ? 'eng' : 'fre';
|
||||
|
||||
if (lang === 'fr') {
|
||||
lang = 'fre';
|
||||
}
|
||||
else if (lang === 'en') {
|
||||
lang = 'eng';
|
||||
}
|
||||
let lang = FILE.split('.').at(-2) ?? 'en';
|
||||
|
||||
const cmd = [
|
||||
'subsync --cli sync',
|
||||
`--sub-lang ${lang}`,
|
||||
`--ref-lang ${lang}`,
|
||||
if (lang === 'fr') {
|
||||
lang = 'fre';
|
||||
}
|
||||
else if (lang === 'en') {
|
||||
lang = 'eng';
|
||||
}
|
||||
|
||||
`--sub-file '${FILE}'`,
|
||||
`--out-file '${FILE}'`,
|
||||
`--ref-file '${VIDEO}'`,
|
||||
const availLangs = data.streams
|
||||
.filter((s) => s.codec_type === 'audio')
|
||||
.map((s) => s['tags']['language']);
|
||||
|
||||
'--overwrite',
|
||||
];
|
||||
const cmd = [
|
||||
'subsync --cli sync',
|
||||
`--sub-lang ${lang}`,
|
||||
|
||||
// TODO: actually call the command
|
||||
console.log(cmd);
|
||||
`--ref-stream-by-lang ${availLangs.includes(lang) ? lang : other(lang)}`,
|
||||
'--ref-stream-by-type "audio"',
|
||||
|
||||
`--sub '${FILE}'`,
|
||||
`--out '${DIR}/${BASE_NAME}.synced.${lang.substring(0, 2)}.srt'`,
|
||||
// `--out '${FILE}'`,
|
||||
`--ref '${VIDEO}'`,
|
||||
|
||||
// '--overwrite',
|
||||
].join(' ');
|
||||
|
||||
exec(cmd, (error, stdout, stderr) => {
|
||||
console.log(error);
|
||||
console.log(stdout);
|
||||
console.log(stderr);
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
if (FILE) {
|
||||
main();
|
||||
process.exit();
|
||||
}
|
||||
else {
|
||||
console.error('Error: no argument passed');
|
||||
|
|
Binary file not shown.
|
@ -6,5 +6,9 @@
|
|||
"@typescript-eslint/parser": "^6.9.1",
|
||||
"eslint": "^8.52.0",
|
||||
"typescript": "^5.3.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"@types/fluent-ffmpeg": "^2.1.24",
|
||||
"fluent-ffmpeg": "^2.1.2"
|
||||
}
|
||||
}
|
||||
|
|
BIN
flake.nix
BIN
flake.nix
Binary file not shown.
Loading…
Reference in a new issue