Eslint style and fixes

This commit is contained in:
Izuco 2021-07-02 20:09:31 +02:00
parent 9ea16caffc
commit 6edf34a768
3 changed files with 43 additions and 54 deletions

33
funi.js
View file

@ -18,7 +18,6 @@ const { lookpath } = require('lookpath');
const m3u8 = require('m3u8-parsed');
const crypto = require('crypto');
const got = require('got');
const iso639 = require('iso-639');
// extra
const appYargs = require('./modules/module.app-args');
@ -41,13 +40,13 @@ let cfg = {
/* Normalise paths for use outside the current directory */
for (let key of Object.keys(cfg.dir)) {
if (!path.isAbsolute(cfg.dir[key])) {
cfg.dir[key] = path.join(workingDir, cfg.dir[key])
cfg.dir[key] = path.join(workingDir, cfg.dir[key]);
}
}
for (let key of Object.keys(cfg.bin)) {
if (!path.isAbsolute(cfg.bin[key])) {
cfg.bin[key] = path.join(workingDir, cfg.bin[key])
cfg.bin[key] = path.join(workingDir, cfg.bin[key]);
}
}
@ -65,11 +64,11 @@ const argv = appYargs.appArgv(cfg.cli);
module.exports = {
argv,
cfg
}
};
// Import merger after argv has been exported
const merger = require('./modules/merger')
const merger = require('./modules/merger');
// check page
if(!isNaN(parseInt(argv.p, 10)) && parseInt(argv.p, 10) > 0){
@ -421,7 +420,7 @@ function getSubsUrl(m){
subLangs = [ 'enUS' ];
}
let found = []
let found = [];
for(let i in m){
let fpp = m[i].filePath.split('.');
@ -432,7 +431,7 @@ function getSubsUrl(m){
path: m[i].filePath,
ext: `.${lang}`,
langName: subType[lang],
language: m[i]?.languages[0]?.code ?? lang.slice(0, 2)
language: m[i].languages[0].code ?? lang.slice(0, 2)
});
}
}
@ -668,16 +667,6 @@ async function downloadStreams(){
}
}
let langCode;
for (let lang in iso639.iso_639_2) {
let langObj = iso639.iso_639_2[lang];
if (langObj.hasOwnProperty('639-1') && langObj['639-1'] === plAud['language']) {
langCode = langObj['639-2'];
}
}
if (!langCode)
langCode = argv.sub ? 'jpn' : 'eng';
// usage
let usableMKVmerge = true;
let usableFFmpeg = true;
@ -701,14 +690,14 @@ async function downloadStreams(){
if(!argv.mp4 && usableMKVmerge){
let ffext = !argv.mp4 ? 'mkv' : 'mp4';
let command = merger.buildCommandMkvMerge(`${muxTrg}.ts`, plAud, stDlPath, `${muxTrg}.${ffext}`)
console.log(command)
shlp.exec('mkvmerge', `"${mkvmergebinfile}"`, command)
let command = merger.buildCommandMkvMerge(`${muxTrg}.ts`, plAud, stDlPath, `${muxTrg}.${ffext}`);
console.log(command);
shlp.exec('mkvmerge', `"${mkvmergebinfile}"`, command);
}
else if(usableFFmpeg){
let ffext = !argv.mp4 ? 'mkv' : 'mp4';
let command = merger.buildCommandFFmpeg(`${muxTrg}.ts`, plAud, stDlPath, `${muxTrg}.${ffext}`)
shlp.exec('ffmpeg',`"${ffmpegbinfile}"`,command)
let command = merger.buildCommandFFmpeg(`${muxTrg}.ts`, plAud, stDlPath, `${muxTrg}.${ffext}`);
shlp.exec('ffmpeg',`"${ffmpegbinfile}"`,command);
}
else{
console.log('\n[INFO] Done!\n');

View file

@ -1,5 +1,5 @@
const iso639 = require('iso-639');
const argv = require('../funi').argv
const argv = require('../funi').argv;
/**
* @param {string} videoFile
@ -8,33 +8,33 @@ const argv = require('../funi').argv
* @returns {string}
*/
const buildCommandFFmpeg = (videoFile, audioSettings, subtitles, output) => {
let args = []
args.push(`-i "${videoFile}"`)
let args = [];
args.push(`-i "${videoFile}"`);
if (audioSettings.uri)
args.push(`-i "${audioSettings.uri}"`)
args.push(`-i "${audioSettings.uri}"`);
for (let index in subtitles) {
let sub = subtitles[index]
args.push(`-i "${sub.file}"`)
let sub = subtitles[index];
args.push(`-i "${sub.file}"`);
}
args.push('-map 0')
args.push('-map 0');
if (audioSettings.uri)
args.push( `-map 1`)
args.push( '-map 1');
args.push(...subtitles.map((_, index) => `-map ${index + (audioSettings.uri ? 2 : 1)}`))
args.push(...subtitles.map((_, index) => `-map ${index + (audioSettings.uri ? 2 : 1)}`));
args.push(
'-metadata:s:v:0 title="[Funimation]"',
`-metadata:s:a:0 language=${getLanguageCode(audioSettings.language, argv.sub ? 'jpn' : 'eng')}`,
`-c:v copy`,
`-c:a copy`,
`-c:s mov_text`,
`-c:s ass`
)
args.push(...subtitles.map((sub, index) => `-metadata:s:${index + 2} language=${getLanguageCode(sub.language)}`))
args.push(`"${output}"`)
return args.join(" ")
}
'-c:v copy',
'-c:a copy',
'-c:s mov_text',
'-c:s ass'
);
args.push(...subtitles.map((sub, index) => `-metadata:s:${index + 2} language=${getLanguageCode(sub.language)}`));
args.push(`"${output}"`);
return args.join(' ');
};
/**
* @param {string} videoFile
@ -43,14 +43,14 @@ const buildCommandFFmpeg = (videoFile, audioSettings, subtitles, output) => {
* @returns {string}
*/
const buildCommandMkvMerge = (videoFile, audioSettings, subtitles, output) => {
let args = []
args.push(`-o "${output}"`)
let args = [];
args.push(`-o "${output}"`);
args.push(
'--no-date',
'--disable-track-statistics-tags',
'--engage no_variable_data',
'--track-name 0:[Funimation]'
)
);
if (audioSettings.uri) {
args.push(
@ -75,7 +75,7 @@ const buildCommandMkvMerge = (videoFile, audioSettings, subtitles, output) => {
if(subtitles.length > 0){
for (let index in subtitles) {
subObj = subtitles[index]
let subObj = subtitles[index];
args.push('--language',`${/*parseInt(index) + (audioSettings.uri ? 2 : 1)*/0}:${getLanguageCode(subObj.language)}`);
args.push(`"${subObj.file}"`);
}
@ -83,24 +83,24 @@ const buildCommandMkvMerge = (videoFile, audioSettings, subtitles, output) => {
args.push(
'--no-subtitles',
'--no-attachments'
)
);
}
return args.join(" ")
}
return args.join(' ');
};
const getLanguageCode = (from, _default = 'eng') => {
for (let lang in iso639.iso_639_2) {
let langObj = iso639.iso_639_2[lang];
if (langObj.hasOwnProperty('639-1') && langObj['639-1'] === from) {
if (Object.prototype.hasOwnProperty.call(langObj, '639-1') && langObj['639-1'] === from) {
return langObj['639-2'];
}
}
return _default
}
return _default;
};
module.exports = {
buildCommandFFmpeg,
getLanguageCode,
buildCommandMkvMerge
}
};

View file

@ -13,7 +13,7 @@ const appArgv = (cfg) => {
// init
const argv = yargs.parserConfiguration({
'duplicate-arguments-array': true,
"camel-case-expansion": false
'camel-case-expansion': false
})
// main
.wrap(Math.min(120)) // yargs.terminalWidth()
@ -217,8 +217,8 @@ const appArgv = (cfg) => {
// Resolve unwanted arrays
for (let key in argv) {
if (argv[key] instanceof Array && !(key === "subLang" || key === "dub")) {
argv[key] = argv[key].pop()
if (argv[key] instanceof Array && !(key === 'subLang' || key === 'dub')) {
argv[key] = argv[key].pop();
}
}
return argv;