Full list + implementation

This commit is contained in:
Izuco 2021-12-26 22:25:30 +01:00
parent 50075dfbe3
commit fde01a049a
No known key found for this signature in database
GPG key ID: E9CBE9E4EF3A1BFA
6 changed files with 391 additions and 293 deletions

View file

@ -45,6 +45,7 @@ import parseFileName, { Variable } from './modules/module.filename';
import { PlaybackData } from './@types/playbackData';
import { downloaded } from './modules/module.downloadArchive';
import parseSelect from './modules/module.parseSelect';
import { AvailableFilenameVars } from './modules/module.args';
const req = new reqModule.Req(domain, argv);
// select
@ -1150,7 +1151,7 @@ async function downloadMediaList(medias: CrunchyEpMeta) : Promise<{
['service', 'CR'],
['showTitle', medias.seasonTitle],
['season', medias.season]
] as [yargs.AvailableFilenameVars, string|number][]).map((a): Variable => {
] as [AvailableFilenameVars, string|number][]).map((a): Variable => {
return {
name: a[0],
replaceWith: a[1],

View file

@ -39,6 +39,7 @@ import { downloaded } from './modules/module.downloadArchive';
import { FunimationMediaDownload } from './@types/funiTypes';
import * as langsData from './modules/module.langsData';
import { TitleElement } from './@types/episode';
import { AvailableFilenameVars } from './modules/module.args';
// check page
argv.p = 1;
@ -609,7 +610,7 @@ async function downloadStreams(epsiode: FunimationMediaDownload){
['width', plLayersRes[selectedQuality].width],
['height', plLayersRes[selectedQuality].height],
['service', 'Funimation']
] as [appYargs.AvailableFilenameVars, string|number][]).map((a): Variable => {
] as [AvailableFilenameVars, string|number][]).map((a): Variable => {
return {
name: a[0],
replaceWith: a[1],

View file

@ -1,4 +1,4 @@
import { appArgv, overrideArguments } from './modules/module.app-args';
import { appArgv, overrideArguments, showHelp } from './modules/module.app-args';
import * as yamlCfg from './modules/module.cfg-loader';
import { makeCommand, addToArchive } from './modules/module.downloadArchive';
@ -52,6 +52,8 @@ import update from './modules/module.updater';
(await import('./funi')).default();
} else if (argv.service === 'crunchy') {
(await import('./crunchy')).default();
} else {
showHelp();
}
}
})();

View file

@ -1,31 +1,8 @@
import yargs from 'yargs';
import * as langsData from './module.langsData';
import yargs, { Choices } from 'yargs';
import { args, groups } from './module.args';
yargs(process.argv.slice(2));
const groups = {
'auth': 'Authentication:',
'fonts': 'Fonts:',
'search': 'Search:',
'dl': 'Downloading:',
'mux': 'Muxing:',
'fileName': 'Filename Template:',
'debug': 'Debug:',
'util': 'Utilities:'
};
export type AvailableFilenameVars = 'title' | 'episode' | 'showTitle' | 'season' | 'width' | 'height' | 'service'
const availableFilenameVars: AvailableFilenameVars[] = [
'title',
'episode',
'showTitle',
'season',
'width',
'height',
'service'
];
let argvC: { [x: string]: unknown; skipSubMux: boolean, downloadArchive: boolean, addArchive: boolean, but: boolean, auth: boolean | undefined; dlFonts: boolean | undefined; search: string | undefined; 'search-type': string; page: number | undefined; 'search-locale': string; new: boolean | undefined; 'movie-listing': string | undefined; series: string | undefined; s: string | undefined; e: string | undefined; q: number; x: number; kstream: number; partsize: number; hslang: string; dlsubs: string[]; novids: boolean | undefined; noaudio: boolean | undefined; nosubs: boolean | undefined; dubLang: string[]; all: boolean; fontSize: number; allSubs: boolean; allDubs: boolean; timeout: number; simul: boolean; mp4: boolean; skipmux: boolean | undefined; fileName: string; numbers: number; nosess: string; debug: boolean | undefined; nocleanup: boolean; help: boolean | undefined; service: 'funi' | 'crunchy'; update: boolean; fontName: string | undefined; _: (string | number)[]; $0: string; };
export type ArgvType = typeof argvC;
@ -57,7 +34,6 @@ const showHelp = yargs.showHelp;
export {
appArgv,
showHelp,
availableFilenameVars,
overrideArguments
};
@ -75,266 +51,21 @@ const getArgv = (cfg: { [key:string]: unknown }) => {
})
.wrap(yargs.terminalWidth())
.usage('Usage: $0 [options]')
.help(false).version(false)
.option('auth', {
group: groups.auth,
describe: 'Enter authentication mode',
type: 'boolean'
})
.option('dlFonts', {
group: groups.fonts,
describe: 'Download all required fonts for mkv muxing',
type: 'boolean'
})
.option('search', {
group: groups.search,
alias: 'f',
describe: 'Search for an anime',
type: 'string'
})
.option('search-type', {
group: groups.search,
describe: 'Search type used for crunchyroll',
choices: [ '', 'top_results', 'series', 'movie_listing', 'episode' ],
default: '',
type: 'string',
})
.option('page', {
group: groups.search,
alias: 'p',
describe: 'Page number for search results',
type: 'number',
})
.option('search-locale', {
group: groups.search,
describe: 'Search locale used for crunchyroll',
choices: langsData.searchLocales,
default: '',
type: 'string',
})
.option('new', {
group: groups.dl,
describe: 'Get last updated series list from crunchyroll',
type: 'boolean',
})
.option('movie-listing', {
group: groups.dl,
alias: 'flm',
describe: 'Get video list by Movie Listing ID',
type: 'string',
})
.option('series', {
group: groups.dl,
alias: 'srz',
describe: 'Get season list by Series ID',
type: 'string',
})
.option('s', {
group: groups.dl,
describe: 'Set the season ID',
type: 'string'
})
.option('e', {
group: groups.dl,
alias: 'episode',
describe: 'Sets the Episode Number/IDs (comma-separated, hyphen-sequence)',
type: 'string',
})
.option('q', {
group: groups.dl,
describe: 'Set the quality layer. Use 0 to get the best quality.',
default: parseDefault<number>('videoLayer', 7),
type: 'number'
})
.option('x', {
group: groups.dl,
alias: 'server',
describe: 'Select server',
choices: [1, 2, 3, 4],
default: parseDefault<number>('nServer', 1),
type: 'number',
})
.option('kstream', {
group: groups.dl,
alias: 'k',
describe: 'Select specific stream for crunchyroll',
choices: [1, 2, 3, 4, 5, 6, 7],
default: parseDefault<number>('kStream', 1),
type: 'number',
})
.option('partsize', {
group: groups.dl,
describe: 'Set the amount of parts that should be downloaded in paralell',
type: 'number',
default: parseDefault<number>('partsize', 10)
})
.option('hslang', {
group: groups.dl,
describe: 'Download video with specific hardsubs',
choices: langsData.subtitleLanguagesFilter.slice(1),
default: parseDefault<string>('hsLang', 'none'),
type: 'string',
})
.option('dlsubs', {
group: groups.dl,
describe: 'Download subtitles by language tag (space-separated)'
+ `\nFuni Only: ${langsData.languages.filter(a => a.funi_locale && !a.cr_locale).map(a => a.locale).join(', ')}`
+ `\nCrunchy Only: ${langsData.languages.filter(a => a.cr_locale && !a.funi_locale).map(a => a.locale).join(', ')}`,
choices: langsData.subtitleLanguagesFilter,
default: parseDefault<string[]>('dlSubs', ['all']),
type: 'array',
})
.option('novids', {
group: groups.dl,
describe: 'Skip downloading videos',
type: 'boolean'
})
.option('noaudio', {
group: groups.dl,
describe: 'Skip downloading audio',
type: 'boolean'
})
.option('nosubs', {
group: groups.dl,
describe: 'Skip downloading subtitles',
type: 'boolean'
})
.option('dubLang', {
group: groups.dl,
describe: 'Set the language to download: '
+ `\nFuni Only: ${langsData.languages.filter(a => a.funi_locale && !a.cr_locale).map(a => a.code).join(', ')}`
+ `\nCrunchy Only: ${langsData.languages.filter(a => a.cr_locale && !a.funi_locale).map(a => a.code).join(', ')}`,
choices: langsData.dubLanguageCodes,
default: parseDefault<string[]>('dubLanguage', [langsData.dubLanguageCodes.slice(-1)[0]]),
array: true,
})
.option('all', {
group: groups.dl,
describe: 'Used to download all episodes from the show',
type: 'boolean',
default: parseDefault<boolean>('all', false)
})
.option('fontSize', {
group: groups.dl,
describe: 'Used to set the fontsize of the subtitles',
default: parseDefault<number>('fontSize', 55),
type: 'number'
})
.option('allSubs', {
group: groups.dl,
describe: 'If set to true, all available subs will get downloaded',
default: false,
type: 'boolean'
})
.option('allDubs', {
group: groups.dl,
describe: 'If set to true, all available dubs will get downloaded',
default: false,
type: 'boolean'
})
.option('timeout', {
group: groups.dl,
describe: 'Set the timeout of all download reqests. Set in millisecods',
type: 'number',
default: parseDefault('timeout', 60 * 1000)
})
.option('simul', {
group: groups.dl,
describe: 'Force downloading simulcast ver. instead of uncut ver. (if uncut ver. available) (Funi only)',
default: parseDefault<boolean>('forceSimul', false),
type: 'boolean',
})
.option('mp4', {
group: groups.mux,
describe: 'Mux video into mp4',
default: parseDefault<boolean>('mp4mux', false),
type: 'boolean'
})
.option('skipmux', {
group: groups.mux,
describe: 'Skip muxing video and subtitles',
type: 'boolean'
})
.option('fileName', {
group: groups.fileName,
describe: `Set the filename template. Use \${variable_name} to insert variables.\nYou may use ${availableFilenameVars
.map(a => `'${a}'`).join(', ')} as variables.`,
type: 'string',
default: parseDefault<string>('fileName', '[${service}] ${showTitle} - S${season}E${episode} [${height}p]')
})
.option('numbers', {
group: groups.fileName,
describe: `Set how long a number in the title should be at least.\n${[[3, 5, '005'], [2, 1, '01'], [1, 20, '20']]
.map(val => `Set in config: ${val[0]}; Episode number: ${val[1]}; Output: ${val[2]}`).join('\n')}`,
type: 'number',
default: parseDefault<number>('numbers', 2)
})
.option('nosess', {
group: groups.debug,
type: 'boolean',
default: 'Reset session cookie for testing purposes'
})
.option('debug', {
group: groups.debug,
describe: 'Debug mode (tokens may be revield in the console output)',
type: 'boolean'
})
.option('nocleanup', {
group: groups.util,
describe: 'Don\'t delete subtitles and videos after muxing',
default: parseDefault<boolean>('noCleanUp', false),
type: 'boolean'
})
.option('help', {
alias: 'h',
group: 'Help:',
describe: 'Show this help',
type: 'boolean'
})
.option('service', {
group: groups.util,
describe: 'Set the service to use',
choices: ['funi', 'crunchy'],
demandOption: true,
default: parseDefault<'crunchy'|'funi'|undefined>('service', undefined)
})
.option('update', {
group: groups.util,
describe: 'Force the tool to check for updates',
type: 'boolean',
default: false
})
.option('fontName', {
group: groups.fonts,
describe: 'Set the font to use in subtiles (Funi only)',
type: 'string',
default: parseDefault<string|undefined>('fontName', undefined)
})
.option('but', {
group: groups.dl,
describe: 'Download everything but',
type: 'boolean',
default: false
})
.option('downloadArchive', {
group: groups.dl,
desc: 'Used to download all archived shows',
type: 'boolean',
default: false
})
.option('addArchive', {
group: groups.dl,
desc: 'Used to add the `-s` and `--srz` to downloadArchive',
type: 'boolean',
default: false
})
.option('skipSubMux', {
group: groups.mux,
desc: 'Skip muxing the subtitles',
type: 'boolean',
default: parseDefault<boolean>('skipSubMux', false)
.help(false).version(false);
const data = args.map(a => {
return {
...a,
group: groups[a.group],
default: typeof a.default === 'object' && !Array.isArray(a.default) ?
parseDefault(a.default.name || a.name, a.default.default) : a.default
}
});
for (const item of data)
argv.option(item.name, {
...item,
choices: item.choices as unknown as Choices
});
return argv;
return argv as unknown as yargs.Argv<typeof argvC>;
};

View file

@ -1,4 +1,4 @@
import { searchLocales } from "./module.langsData";
import { dubLanguageCodes, languages, searchLocales, subtitleLanguagesFilter } from "./module.langsData";
const groups = {
'auth': 'Authentication:',
@ -8,9 +8,22 @@ const groups = {
'mux': 'Muxing:',
'fileName': 'Filename Template:',
'debug': 'Debug:',
'util': 'Utilities:'
'util': 'Utilities:',
'help': 'Help:'
};
export type AvailableFilenameVars = 'title' | 'episode' | 'showTitle' | 'season' | 'width' | 'height' | 'service'
const availableFilenameVars: AvailableFilenameVars[] = [
'title',
'episode',
'showTitle',
'season',
'width',
'height',
'service'
];
type TAppArg<T extends boolean|string|number|unknown[]> = {
name: string,
group: keyof typeof groups,
@ -24,7 +37,8 @@ type TAppArg<T extends boolean|string|number|unknown[]> = {
name?: string
},
service: 'funi'|'crunchy'|'both',
usage: string // -(-)${name} will be added for each command
usage: string // -(-)${name} will be added for each command,
demandOption?: true
}
const args: TAppArg<boolean|number|string|unknown[]>[] = [
@ -129,5 +143,354 @@ const args: TAppArg<boolean|number|string|unknown[]>[] = [
docDescribe: 'Used to set the season ID to download from',
service: 'both',
usage: '${ID}'
},
{
name: 'e',
group: 'dl',
describe: 'Set the episode(s) to download from any given show',
docDescribe: 'Set the episode(s) to download from any given show.'
+ '\nFor multiple selection: 1-4 OR 1,2,3,4 '
+ '\nFor special episodes: S1-4 OR S1,S2,S3,S4 where S is the special letter',
service: 'both',
type: 'string',
usage: '${selection}',
alias: 'epsisode'
},
{
name: 'q',
group: 'dl',
describe: 'Set the quality level. Use 0 to use the maximum quality.',
default: {
default: 7
},
docDescribe: true,
service: 'both',
type: 'number',
usage: '${qualityLevel}'
},
{
name: 'x',
group: 'dl',
describe: 'Select the server to use',
choices: [1, 2, 3, 4],
default: {
default: 1
},
type: 'number',
alias: 'server',
docDescribe: true,
service: 'both',
usage: '${server}'
},
{
name: 'kstream',
group: 'dl',
alias: 'k',
describe: 'Select specific stream',
choices: [1, 2, 3, 4, 5, 6, 7],
default: {
default: 1
},
docDescribe: true,
service: 'crunchy',
type: 'number',
usage: '${stream}'
},
{
name: 'hslang',
group: 'dl',
describe: 'Download video with specific hardsubs',
choices: subtitleLanguagesFilter.slice(1),
default: {
default: 'none'
},
type: 'string',
usage: '${hslang}',
docDescribe: true,
service: 'crunchy'
},
{
name: 'dlsubs',
group: 'dl',
describe: 'Download subtitles by language tag (space-separated)'
+ `\nFuni Only: ${languages.filter(a => a.funi_locale && !a.cr_locale).map(a => a.locale).join(', ')}`
+ `\nCrunchy Only: ${languages.filter(a => a.cr_locale && !a.funi_locale).map(a => a.locale).join(', ')}`,
docDescribe: true,
service: 'both',
type: 'array',
choices: subtitleLanguagesFilter,
default: {
default: 'all'
},
usage: '${sub1} ${sub2}'
},
{
name: 'novids',
group: 'dl',
describe: 'Skip downloading videos',
docDescribe: true,
service: 'both',
type: 'boolean',
usage: ''
},
{
name: 'noaudio',
group: 'dl',
describe: 'Skip downloading audio',
docDescribe: true,
service: 'both',
type: 'boolean',
usage: ''
},
{
name: 'nosubs',
group: 'dl',
describe: 'Skip downloading subtitles',
docDescribe: true,
service: 'both',
type: 'boolean',
usage: ''
},
{
name: 'dubLang',
describe: 'Set the language to download: '
+ `\nFuni Only: ${languages.filter(a => a.funi_locale && !a.cr_locale).map(a => a.code).join(', ')}`
+ `\nCrunchy Only: ${languages.filter(a => a.cr_locale && !a.funi_locale).map(a => a.code).join(', ')}`,
docDescribe: true,
group: 'dl',
choices: dubLanguageCodes,
default: {
default: [dubLanguageCodes.slice(-1)[0]]
},
service: 'both',
type: 'array',
usage: '${dub1} ${dub2}',
},
{
name: 'all',
describe: 'Used to download all episodes from the show',
docDescribe: true,
group: 'dl',
service: 'both',
default: {
default: false
},
type: 'boolean',
usage: ''
},
{
name: 'fontSize',
describe: 'Used to set the fontsize of the subtitles',
default: {
default: 55
},
docDescribe: true,
group: 'dl',
service: 'both',
type: 'number',
usage: '${fontSize}'
},
{
name: 'allDubs',
describe: 'If selected, all available dubs will get downloaded',
docDescribe: true,
group: 'dl',
service: 'both',
type: 'boolean',
usage: ''
},
{
name: 'timeout',
group: 'dl',
type: 'number',
describe: 'Set the timeout of all download reqests. Set in millisecods',
docDescribe: true,
service: 'both',
usage: '${timeout}',
default: {
default: 60 * 1000
}
},
{
name: 'simul',
group: 'dl',
describe: 'Force downloading simulcast version instead of uncut version (if available).',
docDescribe: true,
service: 'funi',
type: 'boolean',
usage: '',
default: {
default: false
}
},
{
name: 'mp4',
group: 'mux',
describe: 'Mux video into mp4',
docDescribe: 'If selected, the output file will be an mp4 file (not recommened tho)',
service: 'both',
type: 'boolean',
usage: '',
default: {
default: false
}
},
{
name: 'skipmux',
describe: 'Skip muxing video, audio and subtitles',
docDescribe: true,
group: 'mux',
service: 'both',
type: 'boolean',
usage: ''
},
{
name: 'fileName',
group: 'fileName',
describe: `Set the filename template. Use \${variable_name} to insert variables.\nYou may use ${availableFilenameVars
.map(a => `'${a}'`).join(', ')} as variables.`,
docDescribe: true,
service: 'both',
type: 'string',
usage: '${fileName}',
default: {
default: '[${service}] ${showTitle} - S${season}E${episode} [${height}p]'
}
},
{
name: 'numbers',
group: 'fileName',
describe: `Set how long a number in the title should be at least.\n${[[3, 5, '005'], [2, 1, '01'], [1, 20, '20']]
.map(val => `Set in config: ${val[0]}; Episode number: ${val[1]}; Output: ${val[2]}`).join('\n')}`,
type: 'number',
default: {
default: 2
},
docDescribe: true,
service: 'both',
usage: '${number}'
},
{
name: 'nosess',
group: 'debug',
describe: 'Reset session cookie for testing purposes',
docDescribe: true,
service: 'both',
type: 'boolean',
usage: '',
default: {
default: false
}
},
{
name: 'debug',
group: 'debug',
describe: 'Debug mode (tokens may be revield in the console output)',
docDescribe: true,
service: 'both',
type: 'boolean',
usage: '',
default: {
default: false
}
},
{
name: 'nocleanup',
describe: 'Don\'t delete subtitle, audio and video files after muxing',
docDescribe: true,
group: 'mux',
service: 'both',
type: 'boolean',
default: {
default: false
},
usage: ''
},
{
name: 'help',
alias: 'h',
describe: 'Show the help output',
docDescribe: true,
group: 'help',
service: 'both',
type: 'boolean',
usage: ''
},
{
name: 'service',
describe: 'Set the service you want to use',
docDescribe: true,
group: 'util',
service: 'both',
type: "string",
choices: ['funi', 'crunchy'],
usage: '${service}',
default: {
default: ''
}
},
{
name: 'update',
group: 'util',
describe: 'Force the tool to check for updates (code version only)',
docDescribe: true,
service: 'both',
type: 'boolean',
usage: ''
},
{
name: 'fontName',
group: 'fonts',
describe: 'Set the font to use in subtiles',
docDescribe: true,
service: 'funi',
type: 'string',
usage: '${fontName}',
},
{
name: 'but',
describe: 'Download everything but the -e selection',
docDescribe: true,
group: 'dl',
service: 'both',
type: 'boolean',
usage: ''
},
{
name: 'downloadArchive',
describe: 'Used to download all archived shows',
group: 'dl',
docDescribe: true,
service: 'both',
type: 'boolean',
usage: ''
},
{
name: 'addArchive',
describe: 'Used to add the `-s` and `--srz` to downloadArchive',
group: 'dl',
docDescribe: true,
service: 'both',
type: 'boolean',
usage: ''
},
{
name: 'skipSubMux',
describe: 'Skip muxing the subtitles',
docDescribe: true,
group: 'mux',
service: 'both',
type: 'boolean',
usage: '',
default: {
default: false
}
}
];
];
export {
TAppArg,
args,
groups,
availableFilenameVars
};

View file

@ -1,6 +1,6 @@
import * as shlp from 'sei-helper';
import path from 'path';
import { AvailableFilenameVars } from './module.app-args';
import { AvailableFilenameVars } from './module.args';
export type Variable = ({