traxxx/src/scrapers/template.js

52 lines
1.2 KiB
JavaScript

'use strict';
const { get, geta } = require('../utils/q');
function scrapeLatest(scenes, site) {
return scenes.map(({ qu }) => {
const release = {};
release.title = qu.q('.title a', true);
const pathname = qu.url('.title a');
release.entryId = pathname.split('/')[3];
release.url = `${site.url}${pathname}`;
release.date = qu.date('.date', 'MMM DD, YYYY');
release.actors = qu.all('.models a.model', true);
release.poster = qu.q('img').dataset.original;
release.stars = Number(qu.q('.rating', true));
release.likes = Number(qu.q('.likes', true));
console.log(release);
return release;
});
}
function scrapeScene({ qu }, _site) {
const release = {};
console.log(release);
return release;
}
async function fetchLatest(site, page = 1) {
const url = `${site.url}/${page}`;
const res = await geta(url, '.selector');
return res.ok ? scrapeLatest(res.items, site) : res.status;
}
async function fetchScene(url, site) {
const res = await get(url);
return res.ok ? scrapeScene(res.item, site) : res.status;
}
module.exports = {
fetchLatest,
fetchScene,
};