Added --rawoutput

WIP, only works with --new so far - it saves the output from --raw to a given file
This commit is contained in:
AnimeDL 2025-08-02 10:44:14 -07:00
parent 206c8e8075
commit 0ca39bed6e
3 changed files with 23 additions and 2 deletions

View file

@ -113,7 +113,7 @@ export default class Crunchy implements ServiceClass {
}
else if(argv.new){
await this.refreshToken();
await this.getNewlyAdded(argv.page, argv.raw);
await this.getNewlyAdded(argv.page, argv.raw, argv.rawoutput);
}
else if(argv.search && argv.search.length > 2){
await this.refreshToken();
@ -1028,7 +1028,7 @@ export default class Crunchy implements ServiceClass {
}
}
public async getNewlyAdded(page?: number, raw: boolean = false) {
public async getNewlyAdded(page?: number, raw: boolean = false, rawoutput?: string) {
if(!this.token.access_token){
console.error('Authentication required!');
return;
@ -1054,6 +1054,14 @@ export default class Crunchy implements ServiceClass {
if (raw) {
console.info(JSON.stringify(newlyAddedResults, null, 2));
if (rawoutput) {
try {
fs.writeFileSync(rawoutput, JSON.stringify(newlyAddedResults), { encoding: 'utf-8' });
console.info(`Raw output saved to ${rawoutput}`);
} catch (e) {
console.error(`Failed to save raw output to ${rawoutput}:`, e);
}
}
return;
}

View file

@ -71,6 +71,7 @@ let argvC: {
nosess: string;
debug: boolean | undefined;
raw: boolean;
rawoutput: string;
nocleanup: boolean;
help: boolean | undefined;
service: 'crunchy' | 'hidive' | 'ao' | 'adn';

View file

@ -843,6 +843,18 @@ const args: TAppArg<boolean|number|string|unknown[]>[] = [
default: false
}
},
{
name: 'rawoutput',
describe: 'Provide a path to output the raw data from the API into a file (Where applicable, the feature is a WIP)',
docDescribe: true,
group: 'util',
service: ['all'],
type: 'string',
usage: '',
default: {
default: ''
}
},
{
name: 'force',
describe: 'Set the default option for the \'alredy exists\' prompt',