Fixing eslint errors

This commit is contained in:
KX-Apple 2021-05-04 14:46:06 +02:00
parent db5a607f74
commit b68d942b52
5 changed files with 208 additions and 208 deletions

68
funi.js
View file

@ -17,11 +17,11 @@ const shlp = require('sei-helper');
const { lookpath } = require('lookpath'); const { lookpath } = require('lookpath');
const m3u8 = require('m3u8-parsed'); const m3u8 = require('m3u8-parsed');
const streamdl = require('hls-download'); const streamdl = require('hls-download');
const crypto = require("crypto"); const crypto = require('crypto');
const got = require('got'); const got = require('got');
// extra // extra
const moduleFolder = path.join(__dirname, "/modules") const moduleFolder = path.join(__dirname, '/modules');
const appYargs = require(path.join(moduleFolder, 'module.app-args')); const appYargs = require(path.join(moduleFolder, 'module.app-args'));
const getYamlCfg = require(path.join(moduleFolder, 'module.cfg-loader')); const getYamlCfg = require(path.join(moduleFolder, 'module.cfg-loader'));
const getData = require(path.join(moduleFolder, 'module.getdata.js')); const getData = require(path.join(moduleFolder, 'module.getdata.js'));
@ -414,16 +414,16 @@ async function downloadStreams(){
plStreams = {}, plStreams = {},
plLayersStr = [], plLayersStr = [],
plLayersRes = {}, plLayersRes = {},
plMaxLayer = 1; plMaxLayer = 1,
plNewIds = 1; plNewIds = 1,
plAud = { uri: '' }; plAud = { uri: '' };
// new uris // new uris
let vplReg = /streaming_video_(\d+)_(\d+)_(\d+)_index\.m3u8/; let vplReg = /streaming_video_(\d+)_(\d+)_(\d+)_index\.m3u8/;
if(plQualityLinkList.playlists[0].uri.match(vplReg)){ if(plQualityLinkList.playlists[0].uri.match(vplReg)){
if(plQualityLinkList.mediaGroups.AUDIO['audio-aacl-128']){ if(plQualityLinkList.mediaGroups.AUDIO['audio-aacl-128']){
let audioData = plQualityLinkList.mediaGroups.AUDIO['audio-aacl-128']; let audioData = plQualityLinkList.mediaGroups.AUDIO['audio-aacl-128'],
audioEl = Object.keys(audioData); audioEl = Object.keys(audioData);
audioData = audioData[audioEl[0]]; audioData = audioData[audioEl[0]];
plAud = { ...audioData, ...{ langStr: audioEl[0] } }; plAud = { ...audioData, ...{ langStr: audioEl[0] } };
} }
@ -437,7 +437,7 @@ async function downloadStreams(){
return -1; return -1;
} }
return 0; return 0;
}) });
} }
for(let s of plQualityLinkList.playlists){ for(let s of plQualityLinkList.playlists){
@ -541,7 +541,7 @@ async function downloadStreams(){
let tsFile = path.join(cfg.dir.content, fnOutput); let tsFile = path.join(cfg.dir.content, fnOutput);
if (chunkList.segments[0].uri.match(/streaming_video_(\d+)_(\d+)_(\d+)\.ts/)) { if (chunkList.segments[0].uri.match(/streaming_video_(\d+)_(\d+)_(\d+)\.ts/)) {
await downloadFile(tsFile, chunkList) await downloadFile(tsFile, chunkList);
} else { } else {
let proxyHLS = false; let proxyHLS = false;
if (argv.proxy && !argv.ssp) { if (argv.proxy && !argv.ssp) {
@ -592,10 +592,10 @@ async function downloadStreams(){
let tsFileA = path.join(cfg.dir.content, fnOutput + `.${plAud.language}`); let tsFileA = path.join(cfg.dir.content, fnOutput + `.${plAud.language}`);
await downloadFile(tsFileA, chunkListA) await downloadFile(tsFileA, chunkListA);
} }
// add subs // add subs
let subsUrl = stDlPath; let subsUrl = stDlPath;
let subsExt = !argv.mp4 || argv.mp4 && !argv.mks && argv.ass ? '.ass' : '.srt'; let subsExt = !argv.mp4 || argv.mp4 && !argv.mks && argv.ass ? '.ass' : '.srt';
let addSubs = argv.mks && subsUrl ? true : false; let addSubs = argv.mks && subsUrl ? true : false;
@ -633,7 +633,7 @@ async function downloadStreams(){
let muxTrg = path.join(cfg.dir.content, fnOutput); let muxTrg = path.join(cfg.dir.content, fnOutput);
let muxTrgA = ''; let muxTrgA = '';
let tshTrg = path.join(cfg.dir.trash, fnOutput); let tshTrg = path.join(cfg.dir.trash, fnOutput);
let tshTrgA = '' let tshTrgA = '';
if(!fs.existsSync(`${muxTrg}.ts`) || !fs.statSync(`${muxTrg}.ts`).isFile()){ if(!fs.existsSync(`${muxTrg}.ts`) || !fs.statSync(`${muxTrg}.ts`).isFile()){
console.log('\n[INFO] TS file not found, skip muxing video...\n'); console.log('\n[INFO] TS file not found, skip muxing video...\n');
@ -642,7 +642,7 @@ async function downloadStreams(){
if(plAud.uri){ if(plAud.uri){
muxTrgA = path.join(cfg.dir.content, fnOutput + `.${plAud.language}`); muxTrgA = path.join(cfg.dir.content, fnOutput + `.${plAud.language}`);
tshTrgA = path.join(cfg.dir.trash, fnOutput + `.${plAud.language}`) tshTrgA = path.join(cfg.dir.trash, fnOutput + `.${plAud.language}`);
if(!fs.existsSync(`${muxTrgA}.ts`) || !fs.statSync(`${muxTrgA}.ts`).isFile()){ if(!fs.existsSync(`${muxTrgA}.ts`) || !fs.statSync(`${muxTrgA}.ts`).isFile()){
console.log('\n[INFO] TS file not found, skip muxing video...\n'); console.log('\n[INFO] TS file not found, skip muxing video...\n');
return; return;
@ -728,7 +728,7 @@ async function downloadStreams(){
else if(argv.nocleanup){ else if(argv.nocleanup){
fs.renameSync(muxTrg+'.ts', tshTrg + '.ts'); fs.renameSync(muxTrg+'.ts', tshTrg + '.ts');
if (plAud.uri) if (plAud.uri)
fs.renameSync(muxTrgA+'.ts', tshTrgA + '.ts') fs.renameSync(muxTrgA+'.ts', tshTrgA + '.ts');
if(subsUrl && addSubs){ if(subsUrl && addSubs){
fs.renameSync(muxTrg +subsExt, tshTrg +subsExt); fs.renameSync(muxTrg +subsExt, tshTrg +subsExt);
} }
@ -736,7 +736,7 @@ async function downloadStreams(){
else{ else{
fs.unlinkSync(muxTrg+'.ts'); fs.unlinkSync(muxTrg+'.ts');
if (plAud.uri) if (plAud.uri)
fs.unlinkSync(muxTrgA+'.ts') fs.unlinkSync(muxTrgA+'.ts');
if(subsUrl && addSubs){ if(subsUrl && addSubs){
fs.unlinkSync(muxTrg +subsExt); fs.unlinkSync(muxTrg +subsExt);
} }
@ -748,9 +748,9 @@ async function downloadFile(filename, chunkList) {
let offset = 0; let offset = 0;
fileCheck: if (fs.existsSync(filename + '.ts')) { fileCheck: if (fs.existsSync(filename + '.ts')) {
if (fs.existsSync(filename + '.ts.resume')) { if (fs.existsSync(filename + '.ts.resume')) {
const resume = JSON.parse(fs.readFileSync(`${filename}.ts.resume`)) const resume = JSON.parse(fs.readFileSync(`${filename}.ts.resume`));
if (resume.total === chunkList.segments.length) { if (resume.total === chunkList.segments.length) {
offset = resume.downloaded offset = resume.downloaded;
break fileCheck; break fileCheck;
} }
} }
@ -759,45 +759,45 @@ async function downloadFile(filename, chunkList) {
if (!['Y', 'y'].includes(rwts[0])) { if (!['Y', 'y'].includes(rwts[0])) {
return; return;
} }
fs.unlinkSync(filename + '.ts') fs.unlinkSync(filename + '.ts');
} }
start = Date.now(); let start = Date.now();
console.log(`[INFO] Started ${filename}.ts`) console.log(`[INFO] Started ${filename}.ts`);
for (let i = offset; i < chunkList.segments.length; i+=argv.partsize) { for (let i = offset; i < chunkList.segments.length; i+=argv.partsize) {
let cur = [] let cur = [];
for (let a = 0; a < Math.min(argv.partsize, chunkList.segments.length - i); a++) { for (let a = 0; a < Math.min(argv.partsize, chunkList.segments.length - i); a++) {
cur.push(downloadPart(chunkList.segments[i + a], i + a, chunkList.segments.length) cur.push(downloadPart(chunkList.segments[i + a], i + a, chunkList.segments.length)
.catch(e => e)) .catch(e => e));
} }
let p = await Promise.all(cur); let p = await Promise.all(cur);
if (p.some(el => el instanceof Error)) { if (p.some(el => el instanceof Error)) {
console.log(`[ERROR] An error occured while downloading ${filename}.ts`) console.log(`[ERROR] An error occured while downloading ${filename}.ts`);
return; return;
} }
fs.writeFileSync(`${filename}.ts.resume`, JSON.stringify({ total: chunkList.segments.length, downloaded: i + argv.partsize }, null, 4)) fs.writeFileSync(`${filename}.ts.resume`, JSON.stringify({ total: chunkList.segments.length, downloaded: i + argv.partsize }, null, 4));
for (let a = 0; a < p.length; a++) { for (let a = 0; a < p.length; a++) {
fs.writeFileSync(filename + '.ts', p[a].content, { flag: 'a' }) fs.writeFileSync(filename + '.ts', p[a].content, { flag: 'a' });
} }
logDownloadInfo(start, i + Math.min(argv.partsize, chunkList.segments.length - i), logDownloadInfo(start, i + Math.min(argv.partsize, chunkList.segments.length - i),
chunkList.segments.length, i + Math.min(argv.partsize, chunkList.segments.length - i), chunkList.segments.length, i + Math.min(argv.partsize, chunkList.segments.length - i),
chunkList.segments.length) chunkList.segments.length);
} }
if (fs.existsSync(`${filename}.ts.resume`)) if (fs.existsSync(`${filename}.ts.resume`))
fs.unlinkSync(`${filename}.ts.resume`) fs.unlinkSync(`${filename}.ts.resume`);
console.log(`[INFO] Finished ${filename}.ts`) console.log(`[INFO] Finished ${filename}.ts`);
} }
async function downloadPart(chunk, index) { async function downloadPart(chunk, index) {
let key = await generateCrypto(chunk, index) let key = await generateCrypto(chunk, index);
let res = (await got({ let res = (await got({
url: chunk.uri, url: chunk.uri,
@ -806,25 +806,25 @@ async function downloadPart(chunk, index) {
'Range': `bytes=${chunk.byterange.offset}-${chunk.byterange.offset+chunk.byterange.length-1}` 'Range': `bytes=${chunk.byterange.offset}-${chunk.byterange.offset+chunk.byterange.length-1}`
}, },
responseType: 'buffer' responseType: 'buffer'
}).catch(error => console.log(`[ERROR] ${error.name}: ${error.code||error.message}`))) }).catch(error => console.log(`[ERROR] ${error.name}: ${error.code||error.message}`)));
if (!res.body) { return; } if (!res.body) { return; }
let dec = key.update(res.body); let dec = key.update(res.body);
dec = Buffer.concat([dec, key.final()]); dec = Buffer.concat([dec, key.final()]);
return { content: dec, index: index} return { content: dec, index: index};
} }
let keys = {} let keys = {};
async function generateCrypto(chunk, index) { async function generateCrypto(chunk, index) {
let key = keys[chunk.key.uri] let key = keys[chunk.key.uri];
if (!key) { if (!key) {
let reqKey = await getData({ let reqKey = await getData({
url: chunk.key.uri, url: chunk.key.uri,
responseType: 'buffer' responseType: 'buffer'
}) });
if (!reqKey.ok) { console.log("[ERROR] Can't get key"); return; } if (!reqKey.ok) { console.log('[ERROR] Can\'t get key'); return; }
key = reqKey.res.body; key = reqKey.res.body;
keys[chunk.key.uri] = key; keys[chunk.key.uri] = key;
} }

View file

@ -1,195 +1,195 @@
const yargs = require('yargs'); const yargs = require('yargs');
const appArgv = (cfg, langsData) => { const appArgv = (cfg) => {
// init // init
return yargs.parserConfiguration({ return yargs.parserConfiguration({
"duplicate-arguments-array": false, 'duplicate-arguments-array': false,
}) })
// main // main
.wrap(Math.min(120)) // yargs.terminalWidth() .wrap(Math.min(120)) // yargs.terminalWidth()
.help(false).version(false) .help(false).version(false)
.usage('Usage: $0 [options]') .usage('Usage: $0 [options]')
// auth // auth
.option('auth', { .option('auth', {
group: 'Authentication:', group: 'Authentication:',
describe: 'Enter authentication mode', describe: 'Enter authentication mode',
type: 'boolean', type: 'boolean',
}) })
// search // search
.option('search', { .option('search', {
alias: 'f', alias: 'f',
group: 'Search:', group: 'Search:',
describe: 'Search show ids', describe: 'Search show ids',
type: 'string', type: 'string',
}) })
// select show and eps // select show and eps
.option('s', { .option('s', {
group: 'Downloading:', group: 'Downloading:',
describe: 'Sets the show id', describe: 'Sets the show id',
type: 'number', type: 'number',
}) })
.option('e', { .option('e', {
group: 'Downloading:', group: 'Downloading:',
describe: 'Select episode ids (comma-separated, hyphen-sequence)', describe: 'Select episode ids (comma-separated, hyphen-sequence)',
type: 'string', type: 'string',
}) })
// quality // quality
.option('q', { .option('q', {
group: 'Downloading:', group: 'Downloading:',
describe: 'Select video layer (0 is max)', describe: 'Select video layer (0 is max)',
choices: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], choices: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
default: cfg.videoLayer || 7, default: cfg.videoLayer || 7,
type: 'number', type: 'number',
}) })
// alt listing // alt listing
.option('alt', { .option('alt', {
group: 'Downloading:', group: 'Downloading:',
describe: 'Alternative episode listing (if available)', describe: 'Alternative episode listing (if available)',
default: cfg.altList || false, default: cfg.altList || false,
type: 'boolean', type: 'boolean',
}) })
// switch to subs // switch to subs
.option('dub', { .option('dub', {
group: 'Downloading:', group: 'Downloading:',
describe: 'Download non-Japanese Dub (English Dub mode by default)', describe: 'Download non-Japanese Dub (English Dub mode by default)',
choices: [ 'enUS', 'esLA', 'ptBR' ], choices: [ 'enUS', 'esLA', 'ptBR' ],
default: cfg.dub || 'enUS', default: cfg.dub || 'enUS',
type: 'string', type: 'string',
}) })
.option('sub', { .option('sub', {
group: 'Downloading:', group: 'Downloading:',
describe: 'Japanese Dub with subtitles mode (English Dub mode by default)', describe: 'Japanese Dub with subtitles mode (English Dub mode by default)',
default: cfg.subsMode || false, default: cfg.subsMode || false,
type: 'boolean', type: 'boolean',
}) })
// simulcast // simulcast
.option('simul', { .option('simul', {
group: 'Downloading:', group: 'Downloading:',
describe: 'Force downloading simulcast ver. instead of uncut ver. (if uncut ver. available)', describe: 'Force downloading simulcast ver. instead of uncut ver. (if uncut ver. available)',
default: cfg.forceSimul || false, default: cfg.forceSimul || false,
type: 'boolean', type: 'boolean',
}) })
// server number // server number
.option('x', { .option('x', {
alias: 'server', alias: 'server',
group: 'Downloading:', group: 'Downloading:',
describe: 'Select server', describe: 'Select server',
choices: [1, 2, 3, 4], choices: [1, 2, 3, 4],
default: cfg.nServer || 1, default: cfg.nServer || 1,
type: 'number', type: 'number',
}) })
// skip // skip
.option('novids', { .option('novids', {
group: 'Downloading:', group: 'Downloading:',
alias: 'skipdl', alias: 'skipdl',
describe: 'Skip downloading video (for downloading subtitles only)', describe: 'Skip downloading video (for downloading subtitles only)',
type: 'boolean', type: 'boolean',
}) })
.option('nosubs', { .option('nosubs', {
group: 'Downloading:', group: 'Downloading:',
describe: 'Skip downloading subtitles for English Dub (if available)', describe: 'Skip downloading subtitles for English Dub (if available)',
type: 'boolean', type: 'boolean',
}) })
// proxy // proxy
.option('proxy', { .option('proxy', {
group: 'Proxy:', group: 'Proxy:',
describe: 'Set http(s)/socks proxy WHATWG url', describe: 'Set http(s)/socks proxy WHATWG url',
default: cfg.proxy || false, default: cfg.proxy || false,
hidden: true, hidden: true,
}) })
.option('proxy-auth', { .option('proxy-auth', {
group: 'Proxy:', group: 'Proxy:',
describe: 'Colon-separated username and password for proxy', describe: 'Colon-separated username and password for proxy',
default: cfg.proxy_auth || false, default: cfg.proxy_auth || false,
hidden: true, hidden: true,
}) })
.option('ssp', { .option('ssp', {
group: 'Proxy:', group: 'Proxy:',
describe: 'Don\'t use proxy for stream and subtitles downloading', describe: 'Don\'t use proxy for stream and subtitles downloading',
default: cfg.proxy_ssp || false, default: cfg.proxy_ssp || false,
hidden: true, hidden: true,
type: 'boolean', type: 'boolean',
}) })
// muxing // muxing
.option('skipmux', { .option('skipmux', {
group: 'Muxing:', group: 'Muxing:',
describe: 'Skip muxing video and subtitles', describe: 'Skip muxing video and subtitles',
type: 'boolean', type: 'boolean',
}) })
.option('mp4', { .option('mp4', {
group: 'Muxing:', group: 'Muxing:',
describe: 'Mux into mp4', describe: 'Mux into mp4',
default: cfg.mp4mux || false, default: cfg.mp4mux || false,
type: 'boolean' type: 'boolean'
}) })
.option('mks', { .option('mks', {
group: 'Muxing:', group: 'Muxing:',
describe: 'Add subtitles to mkv/mp4 (if available)', describe: 'Add subtitles to mkv/mp4 (if available)',
default: cfg.muxSubs || false, default: cfg.muxSubs || false,
type: 'boolean' type: 'boolean'
}) })
// filenaming // filenaming
.option('a', { .option('a', {
alias: 'grouptag', alias: 'grouptag',
group: 'Filename Template:', group: 'Filename Template:',
describe: 'Release group', describe: 'Release group',
default: cfg.releaseGroup || 'Funimation', default: cfg.releaseGroup || 'Funimation',
type: 'string' type: 'string'
}) })
.option('t', { .option('t', {
alias: 'title', alias: 'title',
group: 'Filename Template:', group: 'Filename Template:',
describe: 'Series title override', describe: 'Series title override',
type: 'string' type: 'string'
}) })
.option('ep', { .option('ep', {
group: 'Filename Template:', group: 'Filename Template:',
describe: 'Episode number override (ignored in batch mode)', describe: 'Episode number override (ignored in batch mode)',
type: 'string' type: 'string'
}) })
.option('suffix', { .option('suffix', {
group: 'Filename Template:', group: 'Filename Template:',
describe: 'Filename suffix override (first "SIZEp" will be replaced with actual video size)', describe: 'Filename suffix override (first "SIZEp" will be replaced with actual video size)',
default: cfg.fileSuffix || 'SIZEp', default: cfg.fileSuffix || 'SIZEp',
type: 'string' type: 'string'
}) })
// util // util
.option('nocleanup', { .option('nocleanup', {
group: 'Utilities:', group: 'Utilities:',
describe: 'Move temporary files to trash folder instead of deleting', describe: 'Move temporary files to trash folder instead of deleting',
default: cfg.noCleanUp || false, default: cfg.noCleanUp || false,
type: 'boolean' type: 'boolean'
}) })
.option('notrashfolder', { .option('notrashfolder', {
implies: ['nocleanup'], implies: ['nocleanup'],
group: 'Utilities:', group: 'Utilities:',
describe: 'Don\'t move temporary files to trash folder (Used with --nocleanup)', describe: 'Don\'t move temporary files to trash folder (Used with --nocleanup)',
default: cfg.noTrashFolder || false, default: cfg.noTrashFolder || false,
type: 'boolean' type: 'boolean'
}) })
// help // help
.option('help', { .option('help', {
alias: 'h', alias: 'h',
group: 'Help:', group: 'Help:',
describe: 'Show this help', describe: 'Show this help',
type: 'boolean' type: 'boolean'
}) })
.option('partsize', { .option('partsize', {
group: 'Downloading:', group: 'Downloading:',
describe: 'The amount of parts that should be downloaded in paralell', describe: 'The amount of parts that should be downloaded in paralell',
type: 'number', type: 'number',
default: 10 default: 10
}) })
// usage // usage
.example([ .example([
['$0 --search "My Hero"', 'search "My Hero" in title'], ['$0 --search "My Hero"', 'search "My Hero" in title'],
['$0 -s 124389 -e 1,2,3', 'download episodes 1-3 from show with id 124389'], ['$0 -s 124389 -e 1,2,3', 'download episodes 1-3 from show with id 124389'],
['$0 -s 124389 -e 1-3,2-7,s1-2', 'download episodes 1-7 and "S"-episodes 1-2 from show with id 124389'], ['$0 -s 124389 -e 1-3,2-7,s1-2', 'download episodes 1-7 and "S"-episodes 1-2 from show with id 124389'],
]) ])
// -- // --
.argv; .argv;
} };
const showHelp = yargs.showHelp; const showHelp = yargs.showHelp;

View file

@ -4,7 +4,7 @@ const existsFile = fs.existsSync;
const loadYamlFile = (file) => { const loadYamlFile = (file) => {
return yaml.parse(fs.readFileSync(file, 'utf8')); return yaml.parse(fs.readFileSync(file, 'utf8'));
} };
const loadYamlCfg = (file) => { const loadYamlCfg = (file) => {
if(existsFile(`${file}.user.yml`)){ if(existsFile(`${file}.user.yml`)){
@ -21,6 +21,6 @@ const loadYamlCfg = (file) => {
} }
} }
return {}; return {};
} };
module.exports = loadYamlCfg; module.exports = loadYamlCfg;

View file

@ -10,7 +10,7 @@ const getData = async (options) => {
} }
}; };
if(options.responseType) { if(options.responseType) {
gOptions.responseType = options.responseType gOptions.responseType = options.responseType;
} }
if(options.baseUrl){ if(options.baseUrl){
gOptions.prefixUrl = options.baseUrl; gOptions.prefixUrl = options.baseUrl;
@ -71,6 +71,6 @@ const getData = async (options) => {
error, error,
}; };
} }
} };
module.exports = getData; module.exports = getData;

View file

@ -141,7 +141,7 @@ function toSubsTime(str, srtFormat) {
let hLen = srtFormat ? 2 : 1; let hLen = srtFormat ? 2 : 1;
x[3] = '0.' + ('' + x[3]).padStart(3, '0'); x[3] = '0.' + ('' + x[3]).padStart(3, '0');
sx = x[0]*60*60 + x[1]*60 + x[2] + Number(x[3]) sx = x[0]*60*60 + x[1]*60 + x[2] + Number(x[3]);
sx = sx.toFixed(msLen).split('.'); sx = sx.toFixed(msLen).split('.');