traxxx/src/scrapers/brazzers-legacy.js

213 lines
6.7 KiB
JavaScript

'use strict';
/* eslint-disable newline-per-chained-call */
const qu = require('../utils/qu');
const slugify = require('../utils/slugify');
const { heightToCm, lbsToKg } = require('../utils/convert');
function scrapeAll(items, channel, upcoming) {
return items.reduce((acc, { query }) => {
const isUpcoming = query.exists('.icon-upcoming.active');
if ((upcoming && !isUpcoming) || (!upcoming && isUpcoming)) {
return acc;
}
const release = {};
const pathname = query.url('a');
release.url = `https://www.brazzers.com${pathname}`;
release.entryId = pathname.match(/(\/view\/id\/|\/episode\/)(\d+)/)[2];
release.title = query.q('a', 'title');
release.date = query.date('time', 'MMMM DD, YYYY');
release.actors = query.all('.model-names a', 'title');
release.likes = query.number('.label-rating .like-amount');
release.dislikes = query.number('.label-rating .dislike-amount');
release.poster = query.img('.card-main-img');
release.photos = query.imgs('.card-overlay .image-under');
release.channel = slugify(query.q('.collection', 'title'), '');
return acc.concat(release);
}, []);
}
function getVideoData(html) {
try {
const videoScriptStart = html.indexOf('window.videoUiOptions');
const videoScript = html.slice(videoScriptStart, html.indexOf('};', videoScriptStart));
const videoString = videoScript.slice(videoScript.indexOf('{"stream_info"'), videoScript.lastIndexOf('},') + 1);
return JSON.parse(videoString);
} catch (error) {
return null;
}
}
async function scrapeScene({ query, html }, url, _site) {
const release = {};
release.entryId = new URL(url).pathname.match(/(\/view\/id\/|\/episode\/)(\d+)/)[2];
release.title = query.q('.scene-title[itemprop="name"]', true);
release.description = query.text('#scene-description p[itemprop="description"]');
release.date = query.date('.more-scene-info .scene-date', 'MMMM DD, YYYY');
release.duration = query.number('#trailer-player-container', 'data-duration') // more accurate
|| query.number('.scene-length[itemprop="duration"]', 'content') * 60; // fallback
// actor cards have avatar, but truncated name
const actorImagesByActorId = query.imgs('.featured-model .card-image img').reduce((acc, img) => ({
...acc,
[img.match(/\/models\/(\d+)/)[1]]: [
img.replace('medium', 'large'),
img,
],
}), {});
release.actors = query.all('.related-model a').map((actorEl) => {
const name = query.q(actorEl, null, 'title');
const avatar = actorImagesByActorId[query.url(actorEl, null).match(/\/view\/id\/(\d+)/)?.[1]];
return { name, avatar };
});
release.likes = query.number('.label-rating .like');
release.dislikes = query.number('.label-rating .dislike');
const tags = query.all('.tag-card-container a', true);
const categories = query.all('.timeline a[href*="/categories"]', 'title');
release.tags = tags.concat(categories);
release.channel = slugify(query.q('.scene-site .label-text', true) || query.q('.niche-site-logo', 'title'), '');
const videoData = getVideoData(html);
const poster = videoData?.poster || query.meta('itemprop="thumbnailUrl"') || query.q('#trailer-player-container', 'data-player-img');
release.poster = qu.prefixUrl(poster);
release.photos = query.urls('.carousel-thumb a');
if (videoData) {
release.trailer = Object.entries(videoData.stream_info.http.paths).map(([quality, path]) => ({
src: qu.prefixUrl(path),
quality: Number(quality.match(/\d{3,}/)[0]),
}));
}
return release;
}
async function fetchActorReleases({ query }, accReleases = []) {
const releases = scrapeAll(qu.initAll(query.all('.release-card.scene')));
const next = query.url('.pagination .next a');
if (next) {
const url = `https://www.brazzers.com${next}`;
const res = await qu.get(url);
if (res.ok) {
return fetchActorReleases(res.item, accReleases.concat(releases));
}
}
return accReleases.concat(releases);
}
async function scrapeProfile({ query }, url, actorName, include) {
const bioKeys = query.all('.profile-spec-list label', true).map(key => key.replace(/\n+|\s{2,}/g, '').trim());
const bioValues = query.all('.profile-spec-list var', true).map(value => value.replace(/\n+|\s{2,}/g, '').trim());
const bio = bioKeys.reduce((acc, key, index) => ({ ...acc, [key]: bioValues[index] }), {});
const profile = {
name: actorName,
};
profile.description = query.q('.model-profile-specs p', true);
if (bio.Ethnicity) profile.ethnicity = bio.Ethnicity;
if (bio.Measurements && bio.Measurements.match(/\d+[A-Z]+-\d+-\d+/)) [profile.bust, profile.waist, profile.hip] = bio.Measurements.split('-');
if (bio['Date of Birth'] && bio['Date of Birth'] !== 'Unknown') profile.birthdate = qu.extractDate(bio['Date of Birth'], 'MMMM DD, YYYY');
if (bio['Birth Location']) profile.birthPlace = bio['Birth Location'];
if (bio['Pussy Type']) profile.pussy = bio['Pussy Type'].split(',').slice(-1)[0].toLowerCase();
if (bio.Height) profile.height = heightToCm(bio.Height);
if (bio.Weight) profile.weight = lbsToKg(bio.Weight.match(/\d+/)[0]);
if (bio['Hair Color']) profile.hair = bio['Hair Color'].toLowerCase();
if (bio['Tits Type'] && bio['Tits Type'].match('Natural')) profile.naturalBoobs = true;
if (bio['Tits Type'] && bio['Tits Type'].match('Enhanced')) profile.naturalBoobs = false;
if (bio['Body Art'] && bio['Body Art'].match('Tattoo')) profile.hasTattoos = true;
if (bio['Body Art'] && bio['Body Art'].match('Piercing')) profile.hasPiercings = true;
const avatarEl = query.q('.big-pic-model-container img');
if (avatarEl) profile.avatar = `https:${avatarEl.src}`;
if (include.releases) {
profile.releases = await fetchActorReleases({ query });
}
return profile;
}
async function fetchLatest(channel, page = 1) {
const res = await qu.getAll(`${channel.url}/page/${page}/`, '.release-card.scene');
if (res.ok) {
return scrapeAll(res.items, channel, false);
}
return res.status;
}
async function fetchUpcoming(channel) {
const res = await qu.getAll(`${channel.url}/page/1`, '.release-card.scene');
if (res.ok) {
return scrapeAll(res.items, channel, true);
}
return res.status;
}
async function fetchScene(url, site) {
const res = await qu.get(url);
if (res.ok) {
return scrapeScene(res.item, url, site);
}
return res.status;
}
async function fetchProfile({ name: actorName }, context, include) {
const searchRes = await qu.get('https://brazzers.com/pornstars-search/', `a[title="${actorName}" i]`, {
Cookie: `textSearch=${encodeURIComponent(actorName)};`,
});
const actorLink = searchRes.ok && searchRes.item.qu.url(null);
if (actorLink) {
const url = `https://brazzers.com${actorLink}`;
const res = await qu.get(url);
if (res.ok) {
return scrapeProfile(res.item, url, actorName, include);
}
}
return null;
}
module.exports = {
fetchLatest,
fetchProfile,
fetchScene,
fetchUpcoming,
};