forked from DebaucheryLibrarian/traxxx
78 lines
2.3 KiB
JavaScript
78 lines
2.3 KiB
JavaScript
'use strict';
|
|
|
|
const { geta, ed } = require('../utils/q');
|
|
|
|
function scrapeBlockLatest(scenes) {
|
|
return scenes.map(({ html, qu }) => {
|
|
const release = {};
|
|
|
|
const entryId = qu.q('div[class*="videothumb"]', 'class').match(/videothumb_(\d+)/)
|
|
|| qu.q('div[id*="videothumb"]', 'id').match(/videothumb_(\d+)/);
|
|
|
|
release.entryId = entryId[1];
|
|
|
|
release.title = qu.q('h4 a', true);
|
|
release.url = qu.url('h4 a');
|
|
release.date = ed(html, 'MM/DD/YYYY', /\d{2}\/\d{2}\/\d{4}/);
|
|
|
|
release.actors = qu.all('.tour_update_models a', true);
|
|
|
|
release.poster = qu.q('div img').dataset.src;
|
|
release.photos = [qu.q('div img', 'src0_4x') || qu.q('div img', 'src0_3x') || qu.q('div img', 'src0_2x')];
|
|
|
|
release.teaser = qu.video();
|
|
|
|
return release;
|
|
});
|
|
}
|
|
|
|
function scrapeClassicLatest(scenes) {
|
|
return scenes.map(({ el, qu }) => {
|
|
const release = {};
|
|
|
|
release.entryId = el.dataset.setid;
|
|
release.url = qu.url('a');
|
|
|
|
release.title = qu.q('.update_title_small', true) || qu.q('a:nth-child(2)', true);
|
|
|
|
const description = qu.q('a', 'title');
|
|
if (description) release.description = description;
|
|
|
|
const date = qu.date('.date_small, .update_date', 'MM/DD/YYYY');
|
|
if (date) release.date = date;
|
|
|
|
const durationLine = qu.q('.update_counts', true);
|
|
if (durationLine) release.duration = Number(durationLine.match(/(\d+) min/i)[1]) * 60;
|
|
|
|
const actors = qu.all('.update_models a', true);
|
|
release.actors = actors.length > 0 ? actors : qu.q('.update_models', true).split(/,\s*/);
|
|
|
|
const photoCount = qu.q('.update_thumb', 'cnt');
|
|
[release.poster, ...release.photos] = Array.from({ length: photoCount })
|
|
.map((value, index) => qu.q('.update_thumb', `src${index}_3x`)
|
|
|| qu.q('.update_thumb', `src${index}_2x`)
|
|
|| qu.q('.update_thumb', `src${index}_1x`));
|
|
|
|
return release;
|
|
});
|
|
}
|
|
|
|
async function fetchLatest(site, page = 1) {
|
|
if (!site.parameters) {
|
|
return null;
|
|
}
|
|
|
|
const url = `${site.url}/tour_${site.parameters.siteId}/categories/movies_${page}_d.html`;
|
|
const res = await geta(url, '.updatesBlock .movieBlock, .updatesBlock .videoBlock, .latest_updates_block .update_details, .category_listing_block .update_details');
|
|
|
|
if (res.ok && site.parameters.block) {
|
|
return scrapeBlockLatest(res.items, site);
|
|
}
|
|
|
|
return res.ok ? scrapeClassicLatest(res.items, site) : res.status;
|
|
}
|
|
|
|
module.exports = {
|
|
fetchLatest,
|
|
};
|