traxxx/src/scrapers/julesjordan.js

418 lines
14 KiB
JavaScript
Raw Normal View History

'use strict';
2020-03-01 04:28:08 +00:00
const util = require('util');
2020-02-28 02:56:58 +00:00
const Promise = require('bluebird');
const bhttp = require('bhttp');
const cheerio = require('cheerio');
const { JSDOM } = require('jsdom');
const moment = require('moment');
2020-02-28 02:56:58 +00:00
const logger = require('../logger')(__filename);
const { get, geta, ctxa } = require('../utils/q');
const { heightToCm } = require('../utils/convert');
const slugify = require('../utils/slugify');
async function fetchPhotos(url) {
const res = await bhttp.get(url);
return res.body.toString();
}
function scrapePhotos(html, type) {
const $ = cheerio.load(html, { normalizeWhitespace: true });
const photos = $('.photo_gallery_thumbnail_wrapper .thumbs')
.toArray()
.map((photoElement) => {
const src = $(photoElement).attr('src');
// high res often available in alternative directories, but not always, provide original as fallback
if (type === 'caps') {
return [
src.replace('capthumbs/', 'caps/'),
src,
];
}
return [
src.replace('thumbs/', 'photos/'),
src.replace('thumbs/', '1600watermarked/'),
src.replace('thumbs/', '1280watermarked/'),
src.replace('thumbs/', '1024watermarked/'),
src,
];
});
return photos;
}
async function getPhotosLegacy(entryId, site, type = 'highres', page = 1) {
const albumUrl = `${site.url}/trial/gallery.php?id=${entryId}&type=${type}&page=${page}`;
2020-02-12 22:49:22 +00:00
logger.warn(`Jules Jordan is using legacy photo scraper for ${albumUrl} (page ${page})`);
const html = await fetchPhotos(albumUrl);
const $ = cheerio.load(html, { normalizeWhitespace: true });
// don't add first URL to pages to prevent unnecessary duplicate request
const photos = scrapePhotos(html, type);
const pages = Array.from(new Set($('.page_numbers a').toArray().map(el => $(el).attr('href'))));
const otherPhotos = pages
? await Promise.map(pages, async (pageX) => {
const pageUrl = `https://www.julesjordan.com/trial/${pageX}`;
const pageHtml = await fetchPhotos(pageUrl);
return scrapePhotos(pageHtml, type);
}, {
concurrency: 2,
})
: [];
const allPhotos = photos.concat(otherPhotos.flat());
if (allPhotos.length === 0 && type === 'highres') {
// photos not available, try for screencaps instead
return getPhotosLegacy(entryId, site, 'caps', 1);
}
return allPhotos;
}
async function getPhotos(entryId, site, type = 'highres', page = 1) {
2020-03-01 04:28:08 +00:00
const albumUrl = `${site.parameters?.photos || `${site.url}/gallery.php`}?id=${entryId}&type=${type}&page=${page}`;
const res = await bhttp.get(albumUrl);
const html = res.body.toString();
const sourceLines = html.split(/\n/).filter(line => line.match(/ptx\["\w+"\]/));
const sources = sourceLines.reduce((acc, sourceLine) => {
const quality = sourceLine.match(/\["\w+"\]/)[0].slice(2, -2);
2020-03-01 04:28:08 +00:00
const sourceStart = sourceLine.match(/\/trial|\/tour|\/content/);
if (!sourceStart) return acc;
const source = sourceLine.slice(sourceStart.index, sourceLine.indexOf('.jpg') + 4);
if (!source) return acc;
if (!acc[quality]) acc[quality] = [];
acc[quality].push(`${site.url}${source}`);
return acc;
}, {});
if (type === 'highres') {
if (sources['1600'] && sources['1600'].length > 0) return sources['1600'];
if (sources['1280'] && sources['1280'].length > 0) return sources['1280'];
if (sources['1024'] && sources['1024'].length > 0) return sources['1024'];
if (sources.Thumbs && sources.Thumbs.length > 0) return sources.Thumbs;
// no photos available, try for screencaps instead
return getPhotos(entryId, site, 'caps', 1);
}
if (sources.jpg && sources.jpg.length > 0) return sources.jpg;
if (sources['Video Cap Thumbs'] && sources['Video Cap Thumbs'].length > 0) return sources['Video Cap Thumbs'];
// no screencaps available either, try legacy scraper just in case
return getPhotosLegacy(entryId, site, 'highres', 1);
}
function scrapeAll(scenes, site) {
return scenes.map(({ el, q, qa, qh, qu, qd, qi, qis }) => {
2020-02-12 22:49:22 +00:00
const release = {};
release.entryId = el.dataset.setid || q('.rating_box')?.dataset.id;
2020-02-12 22:49:22 +00:00
release.url = qu('.update_title, .dvd_info > a, a ~ a');
release.title = q('.update_title, .dvd_info > a, a ~ a', true);
release.date = qd('.update_date', 'MM/DD/YYYY');
2020-02-12 22:49:22 +00:00
release.actors = qa('.update_models a', true);
2020-02-12 22:49:22 +00:00
const dvdPhotos = qis('.dvd_preview_thumb');
const photoCount = Number(q('a img.thumbs', 'cnt')) || 1;
2020-02-12 22:49:22 +00:00
[release.poster, ...release.photos] = dvdPhotos.length
? dvdPhotos
: Array.from({ length: photoCount }).map((value, index) => {
const src = qi('a img.thumbs', `src${index}_1x`) || qi('a img.thumbs', `src${index}`) || qi('a img.thumbs');
return src ? {
src: /^http/.test(src) ? src : `${site.url}${src}`,
referer: site.url,
} : null;
}).filter(Boolean);
2019-05-08 03:50:13 +00:00
const teaserScript = qh('script');
2020-02-12 22:49:22 +00:00
if (teaserScript) {
const src = teaserScript.slice(teaserScript.indexOf('http'), teaserScript.indexOf('.mp4') + 4);
if (src) release.teaser = { src };
}
2020-02-12 22:49:22 +00:00
return release;
});
}
function scrapeUpcoming(html, site) {
const $ = cheerio.load(html, { normalizeWhitespace: true });
const scenesElements = $('#coming_soon_carousel').find('.table').toArray();
return scenesElements.map((element) => {
const entryId = $(element).find('.upcoming_updates_thumb').attr('id').match(/\d+/)[0];
const details = $(element).find('.update_details_comingsoon')
.eq(1)
.children()
.remove();
const title = details
.end()
.text()
.trim();
const actors = details
.text()
.trim()
.split(', ');
const date = moment
.utc($(element).find('.update_date_comingsoon').text().slice(7), 'MM/DD/YYYY')
.toDate();
const photoElement = $(element).find('a img.thumbs');
const posterPath = photoElement.attr('src');
const poster = posterPath.match(/^http/) ? posterPath : `${site.url}${posterPath}`;
const videoClass = $(element).find('.update_thumbnail div').attr('class');
const videoScript = $(element).find(`script:contains(${videoClass})`).html();
const teaser = videoScript.slice(videoScript.indexOf('https://'), videoScript.indexOf('.mp4') + 4);
return {
url: null,
entryId,
title,
date,
2019-05-08 03:50:13 +00:00
actors,
poster,
teaser: {
src: teaser,
},
rating: null,
site,
};
});
}
async function scrapeScene(html, url, site) {
const $ = cheerio.load(html, { normalizeWhitespace: true });
const release = { url, site };
release.title = $('.title_bar_hilite').text().trim();
2020-02-12 22:49:22 +00:00
const entryId = html.match(/showtagform\((\d+)\)/);
if (entryId) release.entryId = entryId[1];
else {
const setIdIndex = html.indexOf('setid:"');
if (setIdIndex) release.entryId = html.slice(setIdIndex, html.indexOf(',', setIdIndex)).match(/\d+/)[0];
}
const dateElement = $('.update_date').text().trim();
const dateComment = $('*')
.contents()
.toArray()
.find(({ type, data }) => type === 'comment' && data.match('Date OFF'));
if (dateElement) {
release.date = moment
.utc($('.update_date').text(), 'MM/DD/YYYY')
.toDate();
}
if (dateComment) {
release.date = moment
.utc(dateComment.nodeValue.match(/\d{2}\/\d{2}\/\d{4}/), 'MM/DD/YYYY')
.toDate();
}
release.description = $('.update_description').text().trim();
2020-02-12 22:49:22 +00:00
release.actors = $('.backgroundcolor_info > .update_models a, .item .update_models a')
.map((_actorIndex, actorElement) => $(actorElement).text())
.toArray();
const infoLines = $('script:contains("useimage")')
.html()
.split('\n');
const posterPath = infoLines.find(line => line.match('useimage')).replace('useimage = "', '').slice(0, -2);
2020-03-01 04:28:08 +00:00
if (posterPath) {
const poster = /^http/.test(posterPath) ? posterPath : `${site.url}${posterPath}`;
if (poster) {
release.poster = {
src: poster,
referer: site.url,
};
}
}
if (site.slug !== 'manuelferrara') {
2020-03-01 04:28:08 +00:00
const trailerLines = infoLines.filter(line => /movie\["Trailer\w*"\]\[/.test(line));
if (trailerLines.length) {
release.trailer = trailerLines.map((trailerLine) => {
const src = trailerLine.match(/path:"([\w:/.&=?%]+)"/)?.[1];
const quality = trailerLine.match(/movie_height:'(\d+)/)?.[1];
return src && {
src: /^http/.test(src) ? src : `${site.url}${src}`,
quality: quality && Number(quality),
};
}).filter(Boolean);
}
}
release.photos = await getPhotos(release.entryId, site);
release.tags = $('.update_tags a').map((tagIndex, tagElement) => $(tagElement).text()).toArray();
2020-03-01 04:28:08 +00:00
const movie = $('.update_dvds a').attr('href');
if (movie) release.movie = movie;
release.stars = Number($('.avg_rating').text().trim().replace(/[\s|Avg Rating:]/g, ''));
return release;
}
function scrapeMovie({ el, q, qus }, url, site) {
const movie = { url, site };
movie.entryId = q('.dvd_details_overview .rating_box').dataset.id;
movie.title = q('.title_bar span', true);
movie.covers = qus('#dvd-cover-flip > a');
movie.channel = q('.update_date a', true);
// movie.releases = Array.from(document.querySelectorAll('.cell.dvd_info > a'), el => el.href);
const sceneQs = ctxa(el, '.dvd_details');
const scenes = scrapeAll(sceneQs, site);
const curatedScenes = scenes
.map(scene => ({ ...scene, movie }))
.sort((sceneA, sceneB) => sceneA.date - sceneB.date);
movie.date = curatedScenes[0].date;
return {
...movie,
scenes: curatedScenes,
};
}
function scrapeProfile(html, url, actorName) {
const { document } = new JSDOM(html).window;
const bio = document.querySelector('.model_bio').textContent;
const avatarEl = document.querySelector('.model_bio_pic');
const profile = {
name: actorName,
};
const heightString = bio.match(/\d+ feet \d+ inches/);
const ageString = bio.match(/Age:\s*\d{2}/);
const measurementsString = bio.match(/\w+-\d+-\d+/);
if (heightString) profile.height = heightToCm(heightString[0]);
if (ageString) profile.age = Number(ageString[0].match(/\d{2}/)[0]);
if (measurementsString) [profile.bust, profile.waist, profile.hip] = measurementsString[0].split('-');
if (avatarEl) {
const avatarSources = [
avatarEl.innerHTML.slice(avatarEl.innerHTML.indexOf('src0_3x') + 9, avatarEl.innerHTML.indexOf('3x.jpg') + 6).trim(),
avatarEl.innerHTML.slice(avatarEl.innerHTML.indexOf('src0_2x') + 9, avatarEl.innerHTML.indexOf('2x.jpg') + 6).trim(),
avatarEl.innerHTML.slice(avatarEl.innerHTML.indexOf('src0_1x') + 9, avatarEl.innerHTML.indexOf('1x.jpg') + 6).trim(),
avatarEl.innerHTML.slice(avatarEl.innerHTML.indexOf('src0') + 6, avatarEl.innerHTML.indexOf('set.jpg') + 7).trim(),
avatarEl.innerHTML.slice(avatarEl.innerHTML.indexOf('src') + 5, avatarEl.innerHTML.indexOf('set.jpg') + 7).trim(),
].filter(Boolean);
if (avatarSources.length) profile.avatar = avatarSources;
}
profile.releases = Array.from(document.querySelectorAll('.category_listing_block .update_details > a:first-child'), el => el.href);
return profile;
}
async function fetchLatest(site, page = 1) {
const url = site.parameters?.latest
? util.format(site.parameters.latest, page)
: `${site.url}/trial/categories/movies_${page}_d.html`;
2020-03-01 04:28:08 +00:00
// const res = await bhttp.get(url);
const res = await geta(url, '.update_details');
return res.ok ? scrapeAll(res.items, site) : res.status;
}
async function fetchUpcoming(site) {
2020-03-01 04:28:08 +00:00
if (site.parameters?.upcoming === false) return null;
const url = site.parameters?.upcoming ? util.format(site.parameters.upcoming) : `${site.url}/trial/index.php`;
const res = await bhttp.get(url);
if (res.statusCode === 200) {
return scrapeUpcoming(res.body.toString(), site);
}
2020-03-01 04:28:08 +00:00
return res.statusCode;
}
async function fetchScene(url, site) {
const res = await bhttp.get(url);
return scrapeScene(res.body.toString(), url, site);
}
async function fetchMovie(url, site) {
const res = await get(url);
return res.ok ? scrapeMovie(res.item, url, site) : res.status;
}
async function fetchProfile(actorName) {
const actorSlugA = slugify(actorName, { delimiter: '-' });
const actorSlugB = slugify(actorName, { delimiter: '' });
const urlA = `https://julesjordan.com/trial/models/${actorSlugA}.html`;
const urlB = `https://julesjordan.com/trial/models/${actorSlugB}.html`;
const resA = await bhttp.get(urlA);
if (resA.statusCode === 200) {
const profile = scrapeProfile(resA.body.toString(), urlA, actorName);
return profile;
}
const resB = await bhttp.get(urlB);
if (resB.statusCode === 200) {
const profile = scrapeProfile(resB.body.toString(), urlB, actorName);
return profile;
}
return null;
}
module.exports = {
fetchLatest,
fetchMovie,
fetchProfile,
fetchUpcoming,
fetchScene,
};