1
0
Fork 0
This commit is contained in:
lightling 2024-02-09 20:43:24 -05:00
parent eb908dd8f0
commit 121452e1c9
6 changed files with 6 additions and 6 deletions

26
lib/args.js Normal file
View file

@ -0,0 +1,26 @@
let argRegex = new RegExp('(\-\-[a-zA-Z0-9]+)(=)(.*)');
const parseArgs = () => {
let _args = { '_': [] };
[...process.argv.slice(2)].forEach(arg => {
let result = argRegex.exec(arg);
if (!!result) {
_args[result[1].replace('--','')] = result[3];
} else {
_args['_'].push(arg);
}
});
return _args;
}
export const args = parseArgs();
export const getArg = (argName) => {
let arg = args[argName];
if (!!arg) {
return arg;
} else {
throw(`${argName} was not supplied!`);
}
}

34
lib/dl.js Normal file
View file

@ -0,0 +1,34 @@
import { spawn } from 'child_process';
import { getArg } from './args.js';
import { error, log } from './log.js';
const ctx = 'getUser.js';
export const getUser = (user, path) => {
const url = `https://twitter.com/${user}/media`;
let args;
try {
args = getArg('args');
} catch (err) {
log(ctx, 'No args being provided to gallery-dl');
}
log(ctx, `python3 ~/.local/bin/gallery-dl -c ./config.json${!!args ? ' ' + args + ' ' : ' '}-d ${path} ${url}`);
const proc = spawn(`python3 ~/.local/bin/gallery-dl -c ./config.json${!!args ? ' ' + args + ' ' : ' '}-d ${path} ${url}`, { shell: true });
proc.stdout.on('data', data => {
//log(ctx, data);
});
proc.stderr.on('data', data => {
error(ctx, data);
});
proc.on('error', err => {
error(ctx, err);
});
proc.on('close', code => {
log(ctx, `child process exited with code ${code}`);
});
return proc;
};

6
lib/io.js Normal file
View file

@ -0,0 +1,6 @@
import { readdir } from 'fs/promises'
export const getChildren = async source =>
(await readdir(source, { withFileTypes: true }))
.filter(dirent => dirent.isDirectory())
.map(dirent => dirent.name)

17
lib/log.js Normal file
View file

@ -0,0 +1,17 @@
const options = { year: 'numeric', day: '2-digit', month: '2-digit', hour: '2-digit', 'minute': '2-digit', second: '2-digit' };
const osLocale = (process.env.LANG || process.env.LANGUAGE || process.env.LC_ALL || process.env.LC_MESSAGES).split('.')[0].replace('_', '-');
const dtFormat = Intl.DateTimeFormat(osLocale, options);
export const getTime = () => {
return dtFormat.format(new Date());
}
export const log = (src, msg) => {
const time = getTime();
console.log(`${time} : ${src} : ${msg}`);
};
export const error = (src, msg) => {
const time = new Date().toISOString();
console.error(`${time} : ${src} : ${msg}`);
}