419 lines
13 KiB
JavaScript
419 lines
13 KiB
JavaScript
'use strict';
|
|
|
|
const util = require('util');
|
|
const Promise = require('bluebird');
|
|
const bhttp = require('bhttp');
|
|
const cheerio = require('cheerio');
|
|
const { JSDOM } = require('jsdom');
|
|
const moment = require('moment');
|
|
|
|
const logger = require('../logger')(__filename);
|
|
const { get, geta, ctxa, parseDate } = 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}`;
|
|
|
|
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) {
|
|
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);
|
|
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 getEntryId(html) {
|
|
const entryId = html.match(/showtagform\((\d+)\)/);
|
|
|
|
if (entryId) {
|
|
return entryId[1];
|
|
}
|
|
|
|
const setIdIndex = html.indexOf('setid:"');
|
|
|
|
if (setIdIndex) {
|
|
return html.slice(setIdIndex, html.indexOf(',', setIdIndex)).match(/\d+/)[0];
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
function scrapeAll(scenes, site) {
|
|
return scenes.map(({ el, qu }) => {
|
|
const release = {};
|
|
|
|
release.entryId = el.dataset.setid || qu.q('.rating_box')?.dataset.id;
|
|
|
|
release.url = qu.url('.update_title, .dvd_info > a, a ~ a');
|
|
release.title = qu.q('.update_title, .dvd_info > a, a ~ a', true);
|
|
release.date = qu.date('.update_date', 'MM/DD/YYYY');
|
|
|
|
release.actors = qu.all('.update_models a', true);
|
|
|
|
const dvdPhotos = qu.imgs('.dvd_preview_thumb');
|
|
const photoCount = Number(qu.q('a img.thumbs', 'cnt')) || 1;
|
|
|
|
[release.poster, ...release.photos] = dvdPhotos.length
|
|
? dvdPhotos
|
|
: Array.from({ length: photoCount }).map((value, index) => {
|
|
const src = qu.img('a img.thumbs', `src${index}_1x`) || qu.img('a img.thumbs', `src${index}`) || qu.img('a img.thumbs');
|
|
|
|
return src ? {
|
|
src: /^http/.test(src) ? src : `${site.url}${src}`,
|
|
referer: site.url,
|
|
} : null;
|
|
}).filter(Boolean);
|
|
|
|
const teaserScript = qu.html('script');
|
|
if (teaserScript) {
|
|
const src = teaserScript.slice(teaserScript.indexOf('http'), teaserScript.indexOf('.mp4') + 4);
|
|
if (src) release.teaser = { src };
|
|
}
|
|
|
|
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,
|
|
actors,
|
|
poster,
|
|
teaser: {
|
|
src: teaser,
|
|
},
|
|
rating: null,
|
|
site,
|
|
};
|
|
});
|
|
}
|
|
|
|
async function scrapeScene({ html, qu }, url, site, include) {
|
|
const release = { url, site };
|
|
|
|
release.entryId = getEntryId(html);
|
|
release.title = qu.q('.title_bar_hilite', true);
|
|
release.description = qu.q('.update_description', true);
|
|
|
|
release.date = qu.date('.update_date', 'MM/DD/YYYY', null, 'innerHTML');
|
|
|
|
release.actors = qu.all('.backgroundcolor_info > .update_models a, .item .update_models a', true);
|
|
release.tags = qu.all('.update_tags a', true);
|
|
|
|
const posterPath = html.match(/useimage = "(.*)"/)?.[1];
|
|
|
|
if (posterPath) {
|
|
const poster = /^http/.test(posterPath) ? posterPath : `${site.url}${posterPath}`;
|
|
|
|
if (poster) {
|
|
release.poster = {
|
|
src: poster,
|
|
referer: site.url,
|
|
};
|
|
}
|
|
}
|
|
|
|
if (include.trailer && site.slug !== 'manuelferrara') {
|
|
const trailerLines = html.split('\n').filter(line => /movie\["trailer\w*"\]\[/i.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.replace('558', '540')),
|
|
};
|
|
}).filter(Boolean);
|
|
}
|
|
}
|
|
|
|
if (include.photos) release.photos = await getPhotos(release.entryId, site);
|
|
|
|
if (qu.exists('.update_dvds a')) {
|
|
release.movie = {
|
|
url: qu.url('.update_dvds a'),
|
|
title: qu.q('.update_dvds a', true),
|
|
};
|
|
}
|
|
|
|
const stars = Number(qu.q('.avg_rating', true)?.replace(/[\s|Avg Rating:]/g, ''));
|
|
if (stars) release.stars = stars;
|
|
|
|
return release;
|
|
}
|
|
|
|
function scrapeMovie({ el, qu }, url, site) {
|
|
const movie = { url, site };
|
|
|
|
movie.entryId = qu.q('.dvd_details_overview .rating_box').dataset.id;
|
|
movie.title = qu.q('.title_bar span', true);
|
|
movie.covers = qu.urls('#dvd-cover-flip > a');
|
|
movie.channel = slugify(qu.q('.update_date a', true), '');
|
|
|
|
// movie.releases = Array.from(document.querySelectorAll('.cell.dvd_info > a'), el => el.href);
|
|
const sceneQus = ctxa(el, '.dvd_details');
|
|
const scenes = scrapeAll(sceneQus, site);
|
|
|
|
const curatedScenes = scenes
|
|
?.map(scene => ({ ...scene, movie }))
|
|
.sort((sceneA, sceneB) => sceneA.date - sceneB.date);
|
|
|
|
movie.date = curatedScenes?.[0].date;
|
|
|
|
return {
|
|
...movie,
|
|
...(curatedScenes && { 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 img');
|
|
|
|
const profile = {
|
|
name: actorName,
|
|
};
|
|
|
|
const heightString = bio.match(/\d+ feet \d+ inches/);
|
|
const ageString = bio.match(/Age:\s*(\d{2})/);
|
|
const birthDateString = bio.match(/Age:\s*(\w+ \d{1,2}, \d{4})/);
|
|
const measurementsString = bio.match(/\w+-\d+-\d+/);
|
|
|
|
if (birthDateString) profile.birthdate = parseDate(birthDateString[1], 'MMMM D, YYYY');
|
|
if (ageString) profile.age = Number(ageString[1]);
|
|
|
|
if (heightString) profile.height = heightToCm(heightString[0]);
|
|
|
|
if (measurementsString) {
|
|
const [bust, waist, hip] = measurementsString[0].split('-');
|
|
|
|
if (bust) profile.bust = bust;
|
|
if (waist) profile.waist = Number(waist);
|
|
if (hip) profile.hip = Number(hip);
|
|
}
|
|
|
|
if (avatarEl) {
|
|
const avatarSources = [
|
|
avatarEl.getAttribute('src0_3x'),
|
|
avatarEl.getAttribute('src0_2x'),
|
|
avatarEl.getAttribute('src0_1x'),
|
|
avatarEl.getAttribute('src0'),
|
|
avatarEl.getAttribute('src'),
|
|
].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);
|
|
|
|
console.log(profile);
|
|
|
|
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`;
|
|
|
|
// 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) {
|
|
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);
|
|
}
|
|
|
|
return res.statusCode;
|
|
}
|
|
|
|
async function fetchScene(url, site, baseRelease, preflight, include) {
|
|
const res = await get(url);
|
|
|
|
return res.ok ? scrapeScene(res.item, url, site, include) : res.status;
|
|
}
|
|
|
|
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, '-');
|
|
const actorSlugB = slugify(actorName, '');
|
|
|
|
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,
|
|
};
|