2019-03-23 21:48:39 +00:00
|
|
|
'use strict';
|
2019-03-24 00:29:22 +00:00
|
|
|
|
|
|
|
const bhttp = require('bhttp');
|
2019-11-20 03:53:36 +00:00
|
|
|
const { JSDOM } = require('jsdom');
|
2019-03-24 00:29:22 +00:00
|
|
|
const cheerio = require('cheerio');
|
|
|
|
const moment = require('moment');
|
2019-03-25 02:57:33 +00:00
|
|
|
|
2019-03-24 00:29:22 +00:00
|
|
|
function extractTitle(originalTitle) {
|
|
|
|
const titleComponents = originalTitle.split(' ');
|
2019-09-23 16:32:47 +00:00
|
|
|
const sceneIdMatch = titleComponents.slice(-1)[0].match(/(AB|AF|GP|SZ|IV|GIO|RS|TW|MA|FM|SAL|NR|AA|GL|BZ|FS)\d+/); // detect studio prefixes
|
2019-03-26 00:26:47 +00:00
|
|
|
const shootId = sceneIdMatch ? sceneIdMatch[0] : null;
|
2019-03-24 00:29:22 +00:00
|
|
|
const title = sceneIdMatch ? titleComponents.slice(0, -1).join(' ') : originalTitle;
|
|
|
|
|
2019-03-26 00:26:47 +00:00
|
|
|
return { shootId, title };
|
2019-03-24 00:29:22 +00:00
|
|
|
}
|
|
|
|
|
2019-10-29 00:47:16 +00:00
|
|
|
function getPoster(posterElement, sceneId) {
|
|
|
|
const posterStyle = posterElement.attr('style');
|
|
|
|
|
|
|
|
if (posterStyle) {
|
|
|
|
return posterStyle.slice(posterStyle.indexOf('(') + 1, -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
const posterRange = posterElement.attr('data-casting');
|
|
|
|
const posterRangeData = posterRange ? JSON.parse(posterRange) : null;
|
|
|
|
const posterTimeRange = posterRangeData[Math.floor(Math.random() * posterRangeData.length)];
|
|
|
|
|
2019-12-11 01:25:25 +00:00
|
|
|
if (!posterTimeRange) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2019-10-29 00:47:16 +00:00
|
|
|
if (typeof posterTimeRange === 'number') {
|
|
|
|
// poster time is already a single time value
|
|
|
|
return `https://legalporno.com/casting/${sceneId}/${posterTimeRange}`;
|
|
|
|
}
|
|
|
|
|
|
|
|
const [max, min] = posterTimeRange.split('-');
|
|
|
|
const posterTime = Math.floor(Math.random() * (Number(max) - Number(min) + 1) + Number(min));
|
|
|
|
|
|
|
|
return `https://legalporno.com/casting/${sceneId}/${posterTime}`;
|
|
|
|
}
|
|
|
|
|
2019-03-24 00:29:22 +00:00
|
|
|
function scrapeLatest(html, site) {
|
|
|
|
const $ = cheerio.load(html, { normalizeWhitespace: true });
|
|
|
|
const scenesElements = $('.thumbnails > div').toArray();
|
|
|
|
|
|
|
|
return scenesElements.map((element) => {
|
|
|
|
const sceneLinkElement = $(element).find('.thumbnail-title a');
|
|
|
|
const url = sceneLinkElement.attr('href');
|
|
|
|
|
2019-04-05 01:45:40 +00:00
|
|
|
const originalTitle = sceneLinkElement.text().trim(); // title attribute breaks when they use \\ escaping
|
2019-03-26 00:26:47 +00:00
|
|
|
const { shootId, title } = extractTitle(originalTitle);
|
2019-04-06 21:24:26 +00:00
|
|
|
const entryId = new URL(url).pathname.split('/')[2];
|
2019-03-24 00:29:22 +00:00
|
|
|
|
|
|
|
const date = moment.utc($(element).attr('release'), 'YYYY/MM/DD').toDate();
|
|
|
|
|
2019-10-29 00:47:16 +00:00
|
|
|
const sceneId = $(element).attr('data-content');
|
|
|
|
const posterElement = $(element).find('.thumbnail-avatar');
|
|
|
|
|
|
|
|
const poster = getPoster(posterElement, sceneId);
|
|
|
|
|
2019-03-24 00:29:22 +00:00
|
|
|
return {
|
|
|
|
url,
|
2019-04-06 21:24:26 +00:00
|
|
|
shootId,
|
|
|
|
entryId,
|
2019-03-24 00:29:22 +00:00
|
|
|
title,
|
|
|
|
date,
|
2019-10-29 00:47:16 +00:00
|
|
|
poster,
|
2019-03-24 00:29:22 +00:00
|
|
|
site,
|
|
|
|
};
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-10-29 00:47:16 +00:00
|
|
|
async function scrapeScene(html, url, site, useGallery) {
|
2019-03-24 00:29:22 +00:00
|
|
|
const $ = cheerio.load(html, { normalizeWhitespace: true });
|
2019-10-29 00:47:16 +00:00
|
|
|
const playerObject = $('script:contains("new VideoPlayer")').html();
|
|
|
|
const data = JSON.parse(playerObject.slice(playerObject.indexOf('{"swf":'), playerObject.indexOf('} );') + 1));
|
2019-03-24 00:29:22 +00:00
|
|
|
|
|
|
|
const originalTitle = $('h1.watchpage-title').text().trim();
|
2019-03-26 00:26:47 +00:00
|
|
|
const { shootId, title } = extractTitle(originalTitle);
|
2019-04-06 21:24:26 +00:00
|
|
|
const entryId = new URL(url).pathname.split('/')[2];
|
2019-03-24 00:29:22 +00:00
|
|
|
|
|
|
|
const date = moment.utc($('span[title="Release date"] a').text(), 'YYYY-MM-DD').toDate();
|
|
|
|
|
2020-01-29 02:19:38 +00:00
|
|
|
const [actorsElement, tagsElement, descriptionElement] = $('.scene-description__row').toArray();
|
2019-03-24 00:29:22 +00:00
|
|
|
const actors = $(actorsElement)
|
|
|
|
.find('a[href*="com/model"]')
|
|
|
|
.map((actorIndex, actorElement) => $(actorElement).text()).toArray();
|
|
|
|
|
2020-01-29 02:19:38 +00:00
|
|
|
const description = $('meta[name="description"]')?.attr('content')?.trim() || (descriptionElement && $(descriptionElement).find('dd').text().trim());
|
2019-03-24 04:28:18 +00:00
|
|
|
const duration = moment.duration($('span[title="Runtime"]').text().trim()).asSeconds();
|
2019-03-24 00:29:22 +00:00
|
|
|
|
2019-10-29 00:47:16 +00:00
|
|
|
const posterStyle = $('#player').attr('style');
|
|
|
|
const poster = posterStyle.slice(posterStyle.indexOf('(') + 1, -1);
|
|
|
|
|
|
|
|
const photos = useGallery
|
|
|
|
? $('.gallery a img').map((photoIndex, photoElement) => $(photoElement).attr('src')).toArray()
|
|
|
|
: $('.screenshots img').map((photoIndex, photoElement) => $(photoElement).attr('src')).toArray();
|
|
|
|
|
|
|
|
const trailer = data.clip.qualities.find(clip => clip.quality === 'vga' || clip.quality === 'hd');
|
|
|
|
|
2019-10-30 03:45:42 +00:00
|
|
|
const studioName = $('.watchpage-studioname').first().text().trim();
|
2020-01-06 04:19:38 +00:00
|
|
|
const studio = studioName.replace(/[\s.']+/g, '').toLowerCase();
|
|
|
|
const tags = $(tagsElement).find('a').map((tagIndex, tagElement) => $(tagElement).text()).toArray();
|
2019-03-24 00:29:22 +00:00
|
|
|
|
|
|
|
return {
|
|
|
|
url,
|
2019-03-26 00:26:47 +00:00
|
|
|
shootId,
|
2019-04-06 21:24:26 +00:00
|
|
|
entryId,
|
2019-03-24 00:29:22 +00:00
|
|
|
title,
|
2020-01-29 02:19:38 +00:00
|
|
|
description,
|
2019-03-24 00:29:22 +00:00
|
|
|
date,
|
|
|
|
actors,
|
|
|
|
duration,
|
2019-10-29 00:47:16 +00:00
|
|
|
poster,
|
|
|
|
photos,
|
|
|
|
trailer: {
|
|
|
|
src: trailer.src,
|
|
|
|
type: trailer.type,
|
|
|
|
quality: trailer.quality === 'vga' ? 480 : 720,
|
|
|
|
},
|
2019-03-24 00:29:22 +00:00
|
|
|
tags,
|
|
|
|
site,
|
2019-10-30 03:45:42 +00:00
|
|
|
studio,
|
2019-03-24 00:29:22 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-11-29 04:46:06 +00:00
|
|
|
async function scrapeProfile(html, _url, actorName) {
|
|
|
|
const { document } = new JSDOM(html).window;
|
|
|
|
|
|
|
|
const profile = {
|
|
|
|
name: actorName,
|
|
|
|
};
|
|
|
|
|
|
|
|
const avatarEl = document.querySelector('.model--avatar img[src^="http"]');
|
|
|
|
const entries = Array.from(document.querySelectorAll('.model--description tr'), el => el.textContent.replace(/\n/g, '').split(':'));
|
|
|
|
|
|
|
|
const bio = entries
|
|
|
|
.filter(entry => entry.length === 2) // ignore entries without ':' (About section, see Blanche Bradburry)
|
|
|
|
.reduce((acc, [key, value]) => ({ ...acc, [key.trim()]: value.trim() }), {});
|
|
|
|
|
|
|
|
profile.birthPlace = bio.Nationality;
|
|
|
|
|
|
|
|
if (bio.Age) profile.age = bio.Age;
|
|
|
|
if (avatarEl) profile.avatar = avatarEl.src;
|
|
|
|
|
|
|
|
return profile;
|
|
|
|
}
|
|
|
|
|
2019-04-05 01:45:40 +00:00
|
|
|
async function fetchLatest(site, page = 1) {
|
|
|
|
const res = await bhttp.get(`${site.url}/new-videos/${page}`);
|
2019-03-24 00:29:22 +00:00
|
|
|
|
|
|
|
return scrapeLatest(res.body.toString(), site);
|
|
|
|
}
|
|
|
|
|
|
|
|
async function fetchScene(url, site) {
|
2019-10-29 00:47:16 +00:00
|
|
|
const useGallery = true;
|
|
|
|
|
|
|
|
const res = useGallery
|
|
|
|
? await bhttp.get(`${url}/gallery#gallery`)
|
|
|
|
: await bhttp.get(`${url}/screenshots#screenshots`);
|
2019-03-24 00:29:22 +00:00
|
|
|
|
2019-10-29 00:47:16 +00:00
|
|
|
return scrapeScene(res.body.toString(), url, site, useGallery);
|
2019-03-24 00:29:22 +00:00
|
|
|
}
|
|
|
|
|
2019-11-20 03:53:36 +00:00
|
|
|
async function fetchProfile(actorName) {
|
|
|
|
const res = await bhttp.get(`https://www.legalporno.com/api/autocomplete/search?q=${actorName.replace(' ', '+')}`);
|
|
|
|
const data = res.body;
|
|
|
|
|
|
|
|
const result = data.terms.find(item => item.type === 'model');
|
|
|
|
|
|
|
|
if (result) {
|
|
|
|
const bioRes = await bhttp.get(result.url);
|
|
|
|
const html = bioRes.body.toString();
|
|
|
|
|
|
|
|
return scrapeProfile(html, result.url, actorName);
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2019-03-24 00:29:22 +00:00
|
|
|
module.exports = {
|
|
|
|
fetchLatest,
|
2019-11-20 03:53:36 +00:00
|
|
|
fetchProfile,
|
2019-03-24 00:29:22 +00:00
|
|
|
fetchScene,
|
|
|
|
};
|