traxxx/src/scrapers/spizoo.js

152 lines
4.5 KiB
JavaScript
Executable File

'use strict';
const unprint = require('unprint');
const format = require('template-format');
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.content('.title-label a, .thumb-title a, .p-7, .text h3');
release.date = query.date('.date-label', 'MM/DD/YYYY');
release.actors = query.all(['.update_models a', '.tour_update_models a', '.pornstar-label span']).map((el) => ({
name: unprint.query.content(el),
url: unprint.query.url(el, null),
}));
release.poster = query.img('a img');
release.teaser = query.video('.leVideo source');
return release;
});
}
function scrapeScene({ query }, { url, entity }) {
const release = {};
release.entryId = getEntryId(url);
release.title = query.content(['#media-holder .title', '.content-holder h1', '#scene h1', 'h2.titular', 'title'])?.replace(/\s+-$/, '');
release.date = query.date('#sceneInfo .date, #trailer-data .date', 'YYYY-MM-DD');
release.duration = query.duration('#sceneInfo .data-others, #trailer-data', /\d+:\d+/);
release.description = query.content('#sceneInfo .description, #trailer-data > div:first-child p');
release.actors = query.all('#sceneInfo .data-others a[href*="/models"], #trailer-data a[href*="/models"]').map((el) => ({
name: unprint.query.attribute(el, null, 'title'),
url: unprint.query.url(el, null, { origin: entity.url }),
}));
release.tags = query.contents('.categories-holder a, #sceneInfo a[href*="/categories"], #trailer-data a[href*="/categories"]').map((tag) => tag.trim());
const poster = query.img(['#video-holder .update_thumb', '#video-holder .thumb', '#noMore .update_thumb', '#hpromo .update_thumb', '.trailer-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[type="video/mp4"], #FulsSizeVideo source[type="video/mp4"]'); // sic
release.teaser = query.video('#trailer-video source[src*="/videothumbs"]');
return release;
}
function scrapeProfile({ query }) {
const profile = {};
const bioKeys = query.contents('.statsText b');
const bioValues = query.text('.statsText', { join: false });
const bio = bioKeys.reduce((acc, key, index) => ({
...acc,
[slugify(key, '_')]: bioValues[index],
}), {});
profile.description = query.contents('.descriptionText');
profile.avatar = [
query.img('.model-bio-pic img', { attribute: 'src0_2x' }),
query.img('.model-bio-pic img', { attribute: 'src0_3x' }), // unnecessarily big
query.img('.model-bio-pic img', { attribute: 'src0_1x' }),
];
profile.height = Number(bio.height?.match(/(\d+)\s?cm/i)?.[1]);
profile.dateOfBirth = unprint.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;
}
return profile;
}
async function fetchLatest(channel, page) {
const res = await unprint.get(`${channel.url}${format(channel.parameters?.latest || '/categories/movies_{page}_d.html', { page })}`, {
selectAll: '.thumb-big, .thumb-video, .thumbnail, .thumbnail-popular, .full-thumbnail',
});
if (res.ok) {
return scrapeAll(res.context, channel);
}
return res.status;
}
async function fetchProfile(actor, channel) {
if (actor.url) {
const res = await unprint.get(actor.url);
if (res.ok) {
return scrapeProfile(res.context);
}
}
const resA = await unprint.get(`${channel.url}/models/${slugify(actor.name)}.html`);
if (resA.ok) {
return scrapeProfile(resA.context, channel);
}
const resB = await unprint.get(`${channel.url}/models/${slugify(actor.name, '')}.html`);
if (resB.ok) {
return scrapeProfile(resB.context, channel);
}
return resB.status;
}
module.exports = {
fetchLatest,
fetchProfile,
scrapeScene,
};