1.0.5 • Published 3 years ago
hi.la v1.0.5
MIT licensed
javascript implementation of download from https://hitomi.la intended to be easier to use and set up for js developers
installation:
npm install hi.la
or
npm i hi.la
or
yarn add hi.la
usage (nodejs):
you may optionally install cli-progress
from npm to run this example.
const cliProgress = require('cli-progress');
const { Engine } = require('hi.la');
// async wrapper to execute promises w/ await.
(async _ => {
// create an instance of Downloader Engine
const e = new Engine();
// search for IDs under conditions
const ids = await Engine.getIdsList({
startOffset: 0, galleryCount: 2,
search: {
artist: 'takei ooki'
//only one of
// artist, group, series, character, type, language, tag
// are supported for search.
}})
.catch(console.log);
console.log(ids);
// queue IDs as an array to engine instance.
e.queueIds(ids);
let g, itv, bar;
// repeat until engine depletes of queued galleries.
while ((g = e.nextGallery()) != null) {
bar = new cliProgress.SingleBar({ etaBuffer: 100 }, cliProgress.Presets.rect);
itv = setInterval(_ => bar.update((g.Progress)), 50);
// population of gallery instance is required before any action.
await g.populate();
// g.Metadata consists of metadata and properties.
const { title, artists } = g.Metadata;
console.log(g.id + ': ' + title + ' - ' + artists.map(a => a.name).join(', '));
bar.start(g.Images.length, 0);
//download whole gallery to destination directory
await g.download({ saveTo: './galleries/' + g.id }).catch(console.log);
clearInterval(itv);
bar.update(g.Images.length);
bar.stop();
itv = undefined;
}
})();