traxxx/src/scrapers/template.js

52 lines
1.1 KiB
JavaScript
Raw Normal View History

'use strict';
2020-02-12 22:00:32 +00:00
const { get, geta } = require('../utils/q');
2020-02-12 22:00:32 +00:00
function scrapeLatest(scenes, site) {
return scenes.map(({ q, qa, qu, qd }) => {
const release = {};
2020-02-12 22:00:32 +00:00
release.title = q('.title a', true);
2020-02-12 22:00:32 +00:00
const pathname = qu('.title a');
release.entryId = pathname.split('/')[3];
release.url = `${site.url}${pathname}`;
2020-02-12 22:00:32 +00:00
release.date = qd('.date', 'MMM DD, YYYY');
release.actors = qa('.models a.model', true);
2020-02-12 22:00:32 +00:00
release.poster = q('img').dataset.original;
2020-02-12 22:00:32 +00:00
release.stars = Number(q('.rating', true));
release.likes = Number(q('.likes', true));
2020-02-12 22:00:32 +00:00
console.log(release);
return release;
});
}
2020-02-13 02:44:04 +00:00
function scrapeScene({ q }, _site) {
2020-02-12 22:00:32 +00:00
const release = {};
2020-02-12 22:00:32 +00:00
console.log(release);
return release;
}
async function fetchLatest(site, page = 1) {
2020-02-12 22:00:32 +00:00
const url = `${site.url}/${page}`;
const qLatest = await geta(url, '.selector');
2020-02-12 22:00:32 +00:00
return qLatest && scrapeLatest(qLatest, site);
}
async function fetchScene(url, site) {
2020-02-12 22:00:32 +00:00
const qScene = await get(url);
2020-02-12 22:00:32 +00:00
return qScene && scrapeScene(qScene, site);
}
module.exports = {
fetchLatest,
2020-02-13 02:44:04 +00:00
fetchScene,
};