traxxx/src/scrapers/firstanalquest.js

213 lines
6.4 KiB
JavaScript

'use strict';
const qu = require('../utils/qu');
const slugify = require('../utils/slugify');
function scrapeAllA(scenes, channel) {
return scenes.map(({ query }) => {
const release = {};
release.url = query.url('a.thumb-img, a.thumb', 'href', { origin: channel.url });
release.entryId = new URL(release.url).pathname.match(/(\d+)\/?$/)?.[1];
release.title = query.text('.thumb-title, .title');
release.date = query.date('.thumb-added, .date', ['MMM D, YYYY', 'MMMM DD, YYYY'], /\w+ \d{1,2}, \d{4}/);
release.duration = query.dur('.thumb-duration');
release.actors = query.all('.thumb-models a, .models a').map((actorEl) => ({
name: query.cnt(actorEl),
url: query.url(actorEl, null, 'href', { origin: channel.url }),
}));
const [, photoUrl, photoCount] = query.q('.thumb-img img', 'onmouseover')?.match(/'(.*)', (\d+)\)/) || [];
if (photoUrl && photoCount) {
[release.poster, ...release.photos] = Array.from({ length: 5 }, (value, index) => `${photoUrl}${index + 1}.jpg`);
} else {
release.poster = query.img('.thumb-img img, .thumb img', 'src', { origin: channel.url });
}
release.tags = query.cnts('.tags a');
release.rating = query.number('.thumb-rating');
return release;
});
}
function scrapeAllB(scenes, channel) {
return scenes.map(({ query }) => {
const release = {};
release.title = query.cnt('.title, h2');
release.description = query.cnt('.description, p textarea');
release.duration = query.dur('.time');
const previewHtml = query.html('script')?.match(/document.write\("(.*)"\);/)?.[1];
const previewEl = qu.extract(previewHtml);
const previewQuery = previewEl?.query.q('param[name="flashvars"]', 'value') || query.q('param[name="flashvars"]', 'value');
const previewParams = previewQuery && new URLSearchParams(previewQuery);
if (previewParams) {
release.poster = qu.prefixUrl(previewParams.get('image') || previewParams.get('poster'), channel.url);
release.trailer = previewParams.get('file');
}
release.photos = query.imgs('img[src*="sets/"], img[src*="thumbnails/"]', 'src', { origin: channel.url });
release.entryId = release.poster?.match(/\/sets\/(.*)\//)?.[1] || slugify(release.title);
return release;
});
}
function scrapeSceneA({ query }, url, channel) {
const release = {};
release.entryId = new URL(url).pathname.match(/(\d+)\/?$/)?.[1];
release.title = query.cnt('.title, .scene-title h3').replace(/:$/, '');
release.description = query.cnt('.text-desc p, .info-description p');
release.duration = query.dur('.media-body li span, .duration');
release.actors = query.all('.media-body a[href*="models/"], .models a').map((actorEl) => ({
name: query.cnt(actorEl),
url: query.url(actorEl, null, 'href', { origin: channel.url }),
}));
release.tags = query.cnts('.media-body a[href*="tags/"], .tags a');
release.poster = [
query.img('.player-preview'),
qu.prefixUrl(`/contents/videos_screenshots/0/${release.entryId}/preview_trailer.mp4.jpg`, channel.url),
qu.prefixUrl(query.q('param[name="flashvars"]', 'value')?.match(/poster=(.*\.jpg)/)?.[1], channel.url),
qu.prefixUrl(`/contents/scenes/${release.entyId}/thumbnails/920x518.jpg`, channel.url),
];
release.photos = query.urls('.thumb-album a:not([href="#"]), .thumbs-photo a:not([href*="signup"])', 'href', { origin: channel.url })
.concat(query.imgs('.thumb-album a[href="#"] img, .thumbs-photo a[href*="signup"] img', 'src', { origin: channel.url }));
release.trailer = query.url('a[href*="get_file/"], .download a');
return release;
}
function scrapeProfileA({ query, el }, entity) {
const profile = {};
const bio = query.all('.list-model-info li, .profile-info li').reduce((acc, bioEl) => ({
...acc,
[slugify(query.cnt(bioEl, '.title, span'), '_')]: query.cnt(bioEl, ':nth-child(2)') || query.q(bioEl, ':nth-child(2)', 'title') || query.text(bioEl),
}), {});
profile.dateOfBirth = qu.parseDate(bio.birth_date || bio.date_of_birth, 'DD MMMM, YYYY');
profile.birthPlace = bio.nationality || bio.place_of_birth || null;
profile.weight = Number(bio.weight?.match(/\d+/)?.[0]);
profile.height = Number(bio.height?.match(/\d+/)?.[0]);
profile.eyes = bio.eye_color;
profile.hairColor = bio.hair || bio.hair_color;
profile.aliases = query.text('.sub-title')?.replace(/:\s*/, '').split(/,\s*/);
if (bio.measurements || bio.body_shape_dimensions) {
const [, bust, cup, waist, hip] = (bio.measurements || bio.body_shape_dimensions).match(/(\d+)(\w+)-(\d+)-(\d+)/);
profile.bust = Number(bust);
profile.cup = cup;
profile.waist = Number(waist);
profile.hip = Number(hip);
}
const description = query.cnt('.model-biography p');
const avatar = query.img('.model-box img, .profile-model-photo', 'src', { origin: entity.url });
if (!/there is no description/.test(description)) {
profile.description = description;
}
if (avatar) {
profile.avatar = [
avatar,
avatar.replace('s2_', 's1_'),
];
}
profile.scenes = scrapeAllA(qu.initAll(el, '.list-thumbs .thumb, .main-thumbs > li'), entity);
return profile;
}
async function fetchLatestA(channel, page) {
const url = channel.parameters?.latest
? `${channel.parameters.latest}/${page}`
: `${channel.url}/latest-updates/${page}/`;
const res = await qu.getAll(url, '.list-thumbs ul > li, .main-thumbs > li');
if (res.ok) {
return scrapeAllA(res.items, channel);
}
return res.status;
}
async function fetchLatestB(channel, page) {
const url = channel.parameters?.paginated
? `${channel.url}/page/${page}`
: channel.url;
const res = await qu.getAll(url, '#container, article:not(.sortby)');
if (res.ok) {
return scrapeAllB(res.items, channel);
}
return res.status;
}
async function fetchSceneA(url, channel) {
const res = await qu.get(url, '.main, .main-content');
if (res.ok) {
return scrapeSceneA(res.item, url, channel);
}
return res.status;
}
async function fetchProfileA({ name, slug }, { entity }) {
const searchRes = await qu.getAll(`${entity.url}/models/search/?q=${name}`, '.thumb-modal, .big-thumb');
if (!searchRes.ok) {
return searchRes.status;
}
const actor = searchRes.items.find(({ query }) => slugify(query.cnt('.thumb-title a, .title')) === slug);
if (!actor) {
return null;
}
const actorUrl = actor.query.url('a', 'href', { origin: entity.url });
const actorRes = await qu.get(actorUrl);
if (actorRes.ok) {
return scrapeProfileA(actorRes.item, entity);
}
return null;
}
module.exports = {
a: {
fetchLatest: fetchLatestA,
fetchScene: fetchSceneA,
fetchProfile: fetchProfileA,
},
b: {
fetchLatest: fetchLatestB,
},
};