manga.push(getDom(url).then(dom => { let summary = domutils.findOne(elem => elem.name == 'p' && elem.attribs.class && elem.attribs.class.indexOf('summary') >= 0, dom); let cover = domutils.findOne(elem => elem.name == 'img' && elem.parent.attribs.class && elem.parent.attribs.class.indexOf('cover') >= 0, dom); return { name: info[1], url: url, genre: info[3], author: info[4], image: cover ? cover.attribs.src : '', description: summary ? summary.children[0].data : '' }; }).catch(console.log));
DomFile.prototype.getElementByXPath = function (xPath) { // use DomUtils.findOne(testFn, DomTree) return DomUtils.findOne(function (element) { // compare the element's xPath with the required xPath return element.getXPath() === xPath; }, this.dom); };
return co(function *() { yield makePath(path); let info = null; while (!info) { let dom = yield getDom(`${link}/1.html`); info = domutils.findOne(elem => elem.name == 'div' && elem.parent.parent.attribs.id == 'top_bar', dom); } info = info.children; info = info[info.length - 1].data; let images = info.slice(info.indexOf("of") + 3, -3); volume.loading.total += (images * 1); let promises = []; for (let image = 1; image <= images; image++) { promises.push(new Promise(resolve => co(function *() { let img = null; while (!img) { let dom = yield getDom(`${link}/${image}.html`); img = domutils.findOne(elem => elem.name == 'img' && elem.attribs.id == 'image', dom); } let url = img.attribs.src; ++volume.loading.buffered; if (url.indexOf('.jpg') !== -1) { let file = `${path}/${pad(image, 2)}.jpg`; while(!(yield download(url, file))) {} } ++volume.loading.done; resolve(); }) )); } yield Promise.all(promises); //console.log(`Volume ${volume} Chapter ${chapter}`); })
promises.push(new Promise(resolve => co(function *() { let img = null; while (!img) { let dom = yield getDom(`${link}/${image}.html`); img = domutils.findOne(elem => elem.name == 'img' && elem.attribs.id == 'image', dom); } let url = img.attribs.src; ++volume.loading.buffered; if (url.indexOf('.jpg') !== -1) { let file = `${path}/${pad(image, 2)}.jpg`; while(!(yield download(url, file))) {} } ++volume.loading.done; resolve(); })