Skip to content

Commit

Permalink
Added silentAuth + set username and password as args
Browse files Browse the repository at this point in the history
  • Loading branch information
izu-co committed Jan 7, 2022
1 parent 05d65d3 commit d61bad8
Show file tree
Hide file tree
Showing 6 changed files with 279 additions and 174 deletions.
8 changes: 6 additions & 2 deletions crunchy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ export default (async () => {
argv.dlsubs = langsData.languages.map(a => a.code);
}
// select mode
if (argv.silentAuth && !argv.auth) {
await doAuth();
}
if(argv.dlFonts){
await getFonts();
}
Expand Down Expand Up @@ -140,8 +143,9 @@ async function getFonts(){

// auth method
async function doAuth(){
const iLogin = await shlp.question('[Q] LOGIN/EMAIL');
const iPsswd = await shlp.question('[Q] PASSWORD ');

const iLogin = argv.username ?? await shlp.question('[Q] LOGIN/EMAIL');
const iPsswd = argv.password ?? await shlp.question('[Q] PASSWORD ');
const authData = new URLSearchParams({
'username': iLogin,
'password': iPsswd,
Expand Down
7 changes: 5 additions & 2 deletions funi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ export default (async () => {
argv.dlsubs = langsData.languages.map(a => a.code);
}
// select mode
if (argv.silentAuth && !argv.auth) {
await auth();
}
if(argv.auth){
auth();
}
Expand All @@ -82,8 +85,8 @@ export default (async () => {
// auth
async function auth(){
const authOpts = {
user: await shlp.question('[Q] LOGIN/EMAIL'),
pass: await shlp.question('[Q] PASSWORD ')
user: argv.username ?? await shlp.question('[Q] LOGIN/EMAIL'),
pass: argv.password ?? await shlp.question('[Q] PASSWORD ')
};
const authData = await getData({
baseUrl: api_host,
Expand Down
2 changes: 1 addition & 1 deletion modules/module.app-args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { args, groups } from './module.args';

yargs(process.argv.slice(2));

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; };
let argvC: { [x: string]: unknown; username: string|undefined, password: string|undefined, silentAuth: boolean, 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;

Expand Down
40 changes: 38 additions & 2 deletions modules/module.args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type TAppArg<T extends boolean|string|number|unknown[]> = {
describe: string,
docDescribe: true|string, // true means use describe for the docs
default?: T|{
default: T,
default: T|undefined,
name?: string
},
service: 'funi'|'crunchy'|'both',
Expand Down Expand Up @@ -347,7 +347,7 @@ const args: TAppArg<boolean|number|string|unknown[]>[] = [
{
name: 'fileName',
group: 'fileName',
describe: `Set the filename template. Use \${variable_name} to insert variables.\nYou may use ${availableFilenameVars
describe: `Set the filename template. Use \${variable_name} to insert variables.\nYou can also create folders by inserting a path seperator in the filename\nYou may use ${availableFilenameVars
.map(a => `'${a}'`).join(', ')} as variables.`,
docDescribe: true,
service: 'both',
Expand Down Expand Up @@ -497,6 +497,42 @@ const args: TAppArg<boolean|number|string|unknown[]>[] = [
default: {
default: 10
}
},
{
name: 'username',
describe: 'Set the username to use for the authentication. If not provided, you will be prompted for the input',
docDescribe: true,
group: 'auth',
service: 'both',
type: 'string',
usage: '${username}',
default: {
default: undefined
}
},
{
name: 'password',
describe: 'Set the password to use for the authentication. If not provided, you will be prompted for the input',
docDescribe: true,
group: 'auth',
service: 'both',
type: 'string',
usage: '${password}',
default: {
default: undefined
}
},
{
name: 'silentAuth',
describe: 'Authenticate every time the script runns. Use at your own risk.',
docDescribe: true,
group: 'auth',
service: 'both',
type: 'boolean',
usage: '',
default: {
default: false
}
}
];

Expand Down
Loading

0 comments on commit d61bad8

Please sign in to comment.