traxxx/src/scrapers/spizoo.js

168 lines
4.1 KiB
JavaScript

'use strict';
const qu = require('../utils/qu');
const slugify = require('../utils/slugify');
function getEntryId(url) {
return slugify(new URL(url).pathname.match(/\/updates\/(.*)\.html/)?.[1], '-');
}
function scrapeAll(scenes) {
return scenes.map(({ query }) => {
const release = {};
release.url = query.url('a');
release.entryId = getEntryId(release.url);
release.title = query.cnt('.title-label a');
release.actors = query.all('.update_models a').map((el) => ({
name: query.cnt(el),
url: query.url(el, null),
}));
release.poster = query.img('a img');
return release;
});
}
function scrapeScene({ query }, url) {
const release = {};
release.entryId = getEntryId(url);
release.title = query.cnt('#media-holder .title');
release.date = query.date('#sceneInfo .date', 'YYYY-MM-DD');
release.duration = query.duration('#sceneInfo .data-others', /\d+:\d+/);
release.description = query.cnt('#sceneInfo .description');
release.actors = query.all('#sceneInfo .data-others a[href*="/models"]').map((el) => ({
name: query.el(el, null, 'title'),
url: query.url(el, null),
}));
release.tags = query.cnts('.categories-holder a');
const poster = query.img('#video-holder .update_thumb') || query.poster('#trailervideo');
const posterPathname = poster && new URL(poster)?.pathname;
release.poster = [poster, poster?.replace(/imgw=\w+/, 'imgw=680')];
release.photos = query.imgs('.photos-holder img')
.filter((src) => new URL(src).pathname !== posterPathname)
.map((src) => [
src.replace(/imgw=\d+/, 'imgw=1284'),
src,
]);
release.trailer = query.video('#trailervideo source');
return release;
}
function scrapeProfileScenes(scenes) {
return scenes.map(({ query }) => {
const release = {};
release.url = query.url('a[href*="/updates"]');
release.entryId = getEntryId(release.url);
release.title = query.cnt('.titular, h3 a');
release.date = query.date('.date-label', 'YYYY-MM-DD');
release.duration = query.number('.length-label') * 60;
release.description = query.cnt('.model-update-description');
release.actors = query.all('.model-labels a').map((el) => ({
name: query.cnt(el),
url: query.url(el, null),
}));
const poster = query.img('.update_thumb');
release.poster = [poster, poster?.replace(/imgw=\w+/, 'imgw=680')];
release.tags = query.cnts('.categories-holder a');
return release;
});
}
function scrapeProfile({ query, el }) {
const profile = {};
const bioKeys = query.cnts('.statsText b');
const bioValues = query.texts('.statsText');
const bio = bioKeys.reduce((acc, key, index) => ({
...acc,
[slugify(key, '_')]: bioValues[index],
}), {});
profile.description = query.cnt('.descriptionText');
profile.avatar = query.img('.model-bio-pic img');
profile.height = Number(bio.height?.match(/(\d+)\s?cm/i)?.[1]);
profile.dateOfBirth = qu.extractDate(bio.date_of_birth, 'MMMM D, YYYY');
profile.measurements = bio.measurements;
profile.butt = bio.ass_type;
profile.pussy = bio.pussy_type;
profile.ethnicity = bio.ethnicity;
profile.hairColor = bio.hair_color;
profile.eyes = bio.eye_color;
profile.nationality = bio.nationality;
if (/tattoo/i.test(bio.body_art)) {
profile.hasTattoos = true;
}
if (/piercing/i.test(bio.body_art)) {
profile.hasPiercings = true;
}
profile.scenes = scrapeProfileScenes(qu.initAll(el, '.model-update'));
return profile;
}
async function fetchLatest(channel, page) {
const res = await qu.getAll(`${channel.url}/categories/movies_${page}_d.html`, '.thumb-big');
if (res.ok) {
return scrapeAll(res.items, channel);
}
return res.status;
}
async function fetchProfile(actor, channel) {
if (actor.url) {
const res = await qu.get(actor.url);
if (res.ok) {
return scrapeProfile(res.item);
}
}
const resA = await qu.get(`${channel.url}/models/${slugify(actor.name)}.html`);
if (resA.ok) {
return scrapeProfile(resA.item, channel);
}
const resB = await qu.get(`${channel.url}/models/${slugify(actor.name, '')}.html`);
if (resB.ok) {
return scrapeProfile(resB.item, channel);
}
return resB.status;
}
module.exports = {
fetchLatest,
fetchProfile,
scrapeScene,
};