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 m3u8 = require('m3u8-parsed');
const streamdl = require('hls-download');
const crypto = require("crypto");
const crypto = require('crypto');
const got = require('got');
// extra
const moduleFolder = path.join(__dirname, "/modules")
const moduleFolder = path.join(__dirname, '/modules');
const appYargs = require(path.join(moduleFolder, 'module.app-args'));
const getYamlCfg = require(path.join(moduleFolder, 'module.cfg-loader'));
const getData = require(path.join(moduleFolder, 'module.getdata.js'));
@ -414,16 +414,16 @@ async function downloadStreams(){
plStreams = {},
plLayersStr = [],
plLayersRes = {},
plMaxLayer = 1;
plNewIds = 1;
plMaxLayer = 1,
plNewIds = 1,
plAud = { uri: '' };
// new uris
let vplReg = /streaming_video_(\d+)_(\d+)_(\d+)_index\.m3u8/;
if(plQualityLinkList.playlists[0].uri.match(vplReg)){
if(plQualityLinkList.mediaGroups.AUDIO['audio-aacl-128']){
let audioData = plQualityLinkList.mediaGroups.AUDIO['audio-aacl-128'];
audioEl = Object.keys(audioData);
let audioData = plQualityLinkList.mediaGroups.AUDIO['audio-aacl-128'],
audioEl = Object.keys(audioData);
audioData = audioData[audioEl[0]];
plAud = { ...audioData, ...{ langStr: audioEl[0] } };
}
@ -437,7 +437,7 @@ async function downloadStreams(){
return -1;
}
return 0;
})
});
}
for(let s of plQualityLinkList.playlists){
@ -541,7 +541,7 @@ async function downloadStreams(){
let tsFile = path.join(cfg.dir.content, fnOutput);
if (chunkList.segments[0].uri.match(/streaming_video_(\d+)_(\d+)_(\d+)\.ts/)) {
await downloadFile(tsFile, chunkList)
await downloadFile(tsFile, chunkList);
} else {
let proxyHLS = false;
if (argv.proxy && !argv.ssp) {
@ -592,10 +592,10 @@ async function downloadStreams(){
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 subsExt = !argv.mp4 || argv.mp4 && !argv.mks && argv.ass ? '.ass' : '.srt';
let addSubs = argv.mks && subsUrl ? true : false;
@ -633,7 +633,7 @@ async function downloadStreams(){
let muxTrg = path.join(cfg.dir.content, fnOutput);
let muxTrgA = '';
let tshTrg = path.join(cfg.dir.trash, fnOutput);
let tshTrgA = ''
let tshTrgA = '';
if(!fs.existsSync(`${muxTrg}.ts`) || !fs.statSync(`${muxTrg}.ts`).isFile()){
console.log('\n[INFO] TS file not found, skip muxing video...\n');
@ -642,7 +642,7 @@ async function downloadStreams(){
if(plAud.uri){
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()){
console.log('\n[INFO] TS file not found, skip muxing video...\n');
return;
@ -728,7 +728,7 @@ async function downloadStreams(){
else if(argv.nocleanup){
fs.renameSync(muxTrg+'.ts', tshTrg + '.ts');
if (plAud.uri)
fs.renameSync(muxTrgA+'.ts', tshTrgA + '.ts')
fs.renameSync(muxTrgA+'.ts', tshTrgA + '.ts');
if(subsUrl && addSubs){
fs.renameSync(muxTrg +subsExt, tshTrg +subsExt);
}
@ -736,7 +736,7 @@ async function downloadStreams(){
else{
fs.unlinkSync(muxTrg+'.ts');
if (plAud.uri)
fs.unlinkSync(muxTrgA+'.ts')
fs.unlinkSync(muxTrgA+'.ts');
if(subsUrl && addSubs){
fs.unlinkSync(muxTrg +subsExt);
}
@ -748,9 +748,9 @@ async function downloadFile(filename, chunkList) {
let offset = 0;
fileCheck: if (fs.existsSync(filename + '.ts')) {
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) {
offset = resume.downloaded
offset = resume.downloaded;
break fileCheck;
}
}
@ -759,45 +759,45 @@ async function downloadFile(filename, chunkList) {
if (!['Y', 'y'].includes(rwts[0])) {
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) {
let cur = []
let cur = [];
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)
.catch(e => e))
.catch(e => e));
}
let p = await Promise.all(cur);
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;
}
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++) {
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),
chunkList.segments.length, i + Math.min(argv.partsize, chunkList.segments.length - i),
chunkList.segments.length)
chunkList.segments.length);
}
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) {
let key = await generateCrypto(chunk, index)
let key = await generateCrypto(chunk, index);
let res = (await got({
url: chunk.uri,
@ -806,25 +806,25 @@ async function downloadPart(chunk, index) {
'Range': `bytes=${chunk.byterange.offset}-${chunk.byterange.offset+chunk.byterange.length-1}`
},
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; }
let dec = key.update(res.body);
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) {
let key = keys[chunk.key.uri]
let key = keys[chunk.key.uri];
if (!key) {
let reqKey = await getData({
url: chunk.key.uri,
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;
keys[chunk.key.uri] = key;
}

View file

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

View file

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

View file

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

View file

@ -141,7 +141,7 @@ function toSubsTime(str, srtFormat) {
let hLen = srtFormat ? 2 : 1;
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('.');