feat(node-syncsub): improve language logic
All checks were successful
Discord / discord commits (push) Has been skipped

This commit is contained in:
matt1432 2024-03-30 02:28:22 -04:00
parent f184ffa4bf
commit 148e8e9daf
2 changed files with 192 additions and 14 deletions

View file

@ -0,0 +1,186 @@
export const iso6391To3 = new Map([
['aa', 'aar'],
['ab', 'abk'],
['af', 'afr'],
['ak', 'aka'],
['am', 'amh'],
['ar', 'ara'],
['an', 'arg'],
['as', 'asm'],
['av', 'ava'],
['ae', 'ave'],
['ay', 'aym'],
['az', 'aze'],
['ba', 'bak'],
['bm', 'bam'],
['be', 'bel'],
['bn', 'ben'],
['bi', 'bis'],
['bo', 'bod'],
['bs', 'bos'],
['br', 'bre'],
['bg', 'bul'],
['ca', 'cat'],
['cs', 'ces'],
['ch', 'cha'],
['ce', 'che'],
['cu', 'chu'],
['cv', 'chv'],
['kw', 'cor'],
['co', 'cos'],
['cr', 'cre'],
['cy', 'cym'],
['da', 'dan'],
['de', 'deu'],
['dv', 'div'],
['dz', 'dzo'],
['el', 'ell'],
['en', 'eng'],
['eo', 'epo'],
['et', 'est'],
['eu', 'eus'],
['ee', 'ewe'],
['fo', 'fao'],
['fa', 'fas'],
['fj', 'fij'],
['fi', 'fin'],
['fr', 'fra'],
['fy', 'fry'],
['ff', 'ful'],
['gd', 'gla'],
['ga', 'gle'],
['gl', 'glg'],
['gv', 'glv'],
['gn', 'grn'],
['gu', 'guj'],
['ht', 'hat'],
['ha', 'hau'],
['sh', 'hbs'],
['he', 'heb'],
['hz', 'her'],
['hi', 'hin'],
['ho', 'hmo'],
['hr', 'hrv'],
['hu', 'hun'],
['hy', 'hye'],
['ig', 'ibo'],
['io', 'ido'],
['ii', 'iii'],
['iu', 'iku'],
['ie', 'ile'],
['ia', 'ina'],
['id', 'ind'],
['ik', 'ipk'],
['is', 'isl'],
['it', 'ita'],
['jv', 'jav'],
['ja', 'jpn'],
['kl', 'kal'],
['kn', 'kan'],
['ks', 'kas'],
['ka', 'kat'],
['kr', 'kau'],
['kk', 'kaz'],
['km', 'khm'],
['ki', 'kik'],
['rw', 'kin'],
['ky', 'kir'],
['kv', 'kom'],
['kg', 'kon'],
['ko', 'kor'],
['kj', 'kua'],
['ku', 'kur'],
['lo', 'lao'],
['la', 'lat'],
['lv', 'lav'],
['li', 'lim'],
['ln', 'lin'],
['lt', 'lit'],
['lb', 'ltz'],
['lu', 'lub'],
['lg', 'lug'],
['mh', 'mah'],
['ml', 'mal'],
['mr', 'mar'],
['mk', 'mkd'],
['mg', 'mlg'],
['mt', 'mlt'],
['mn', 'mon'],
['mi', 'mri'],
['ms', 'msa'],
['my', 'mya'],
['na', 'nau'],
['nv', 'nav'],
['nr', 'nbl'],
['nd', 'nde'],
['ng', 'ndo'],
['ne', 'nep'],
['nl', 'nld'],
['nn', 'nno'],
['nb', 'nob'],
['no', 'nor'],
['ny', 'nya'],
['oc', 'oci'],
['oj', 'oji'],
['or', 'ori'],
['om', 'orm'],
['os', 'oss'],
['pa', 'pan'],
['pi', 'pli'],
['pl', 'pol'],
['pt', 'por'],
['ps', 'pus'],
['qu', 'que'],
['rm', 'roh'],
['ro', 'ron'],
['rn', 'run'],
['ru', 'rus'],
['sg', 'sag'],
['sa', 'san'],
['si', 'sin'],
['sk', 'slk'],
['sl', 'slv'],
['se', 'sme'],
['sm', 'smo'],
['sn', 'sna'],
['sd', 'snd'],
['so', 'som'],
['st', 'sot'],
['es', 'spa'],
['sq', 'sqi'],
['sc', 'srd'],
['sr', 'srp'],
['ss', 'ssw'],
['su', 'sun'],
['sw', 'swa'],
['sv', 'swe'],
['ty', 'tah'],
['ta', 'tam'],
['tt', 'tat'],
['te', 'tel'],
['tg', 'tgk'],
['tl', 'tgl'],
['th', 'tha'],
['ti', 'tir'],
['to', 'ton'],
['tn', 'tsn'],
['ts', 'tso'],
['tk', 'tuk'],
['tr', 'tur'],
['tw', 'twi'],
['ug', 'uig'],
['uk', 'ukr'],
['ur', 'urd'],
['uz', 'uzb'],
['ve', 'ven'],
['vi', 'vie'],
['vo', 'vol'],
['wa', 'wln'],
['wo', 'wol'],
['xh', 'xho'],
['yi', 'yid'],
['yo', 'yor'],
['za', 'zha'],
['zh', 'zho'],
['zu', 'zul'],
]);

View file

@ -1,6 +1,7 @@
import { readdir } from 'fs'; import { readdir } from 'fs';
import { ffprobe } from 'fluent-ffmpeg'; import { ffprobe } from 'fluent-ffmpeg';
import { spawn } from 'child_process'; import { spawn } from 'child_process';
import { iso6391To3 } from './lang-codes';
const SUB_EXT_LENGTH = 7; const SUB_EXT_LENGTH = 7;
@ -22,18 +23,9 @@ const main = () => {
!f.endsWith('.srt'))[0]}`; !f.endsWith('.srt'))[0]}`;
ffprobe(VIDEO, (_e, data) => { ffprobe(VIDEO, (_e, data) => {
const other = (lang: string) => lang === 'fre' ? 'eng' : 'fre'; const LANG = iso6391To3.get(FILE.split('.').at(-2) ?? 'en') ?? 'eng';
let lang = FILE.split('.').at(-2) ?? 'en'; const OUT_FILE = `${BASE_NAME}.synced.${LANG.substring(0, 2)}.srt`;
if (lang === 'fr') {
lang = 'fre';
}
else if (lang === 'en') {
lang = 'eng';
}
const OUT_FILE = `${BASE_NAME}.synced.${lang.substring(0, 2)}.srt`;
const OUT_PATH = `${DIR}/${OUT_FILE}`; const OUT_PATH = `${DIR}/${OUT_FILE}`;
if (files.includes(OUT_FILE)) { if (files.includes(OUT_FILE)) {
@ -47,14 +39,14 @@ const main = () => {
const cmd = [ const cmd = [
'--cli sync', '--cli sync',
`--sub-lang ${lang}`, `--sub-lang ${LANG}`,
`--ref-stream-by-lang ${availLangs.includes(lang) ? lang : other(lang)}`, `--ref-stream-by-lang ${availLangs.includes(LANG) ? LANG : availLangs[0]}`,
'--ref-stream-by-type "audio"', '--ref-stream-by-type "audio"',
`--sub '${FILE}'`, `--sub '${FILE}'`,
`--out '${OUT_PATH}'`, `--out '${OUT_PATH}'`,
// `--out '${PATH}'`, // `--out '${OUT_PATH}'`,
`--ref '${VIDEO}'`, `--ref '${VIDEO}'`,
// '--overwrite', // '--overwrite',