2020-01-14 03:50:42 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
/* eslint-disable newline-per-chained-call */
|
|
|
|
const Promise = require('bluebird');
|
|
|
|
const bhttp = require('bhttp');
|
|
|
|
const { CookieJar } = Promise.promisifyAll(require('tough-cookie'));
|
|
|
|
const moment = require('moment');
|
|
|
|
|
2020-07-20 23:44:51 +00:00
|
|
|
const qu = require('../utils/qu');
|
2020-02-29 04:00:50 +00:00
|
|
|
const slugify = require('../utils/slugify');
|
2020-01-27 21:54:14 +00:00
|
|
|
const { inchesToCm, lbsToKg } = require('../utils/convert');
|
2020-01-14 03:50:42 +00:00
|
|
|
const { cookieToData } = require('../utils/cookies');
|
|
|
|
|
|
|
|
function getThumbs(scene) {
|
2020-05-14 02:26:05 +00:00
|
|
|
if (scene.images.poster) {
|
|
|
|
return scene.images.poster.map(image => image.xl.url);
|
|
|
|
}
|
2020-01-14 03:50:42 +00:00
|
|
|
|
2020-05-14 02:26:05 +00:00
|
|
|
if (scene.images.card_main_rect) {
|
|
|
|
return scene.images.card_main_rect
|
|
|
|
.concat(scene.images.card_secondary_rect || [])
|
|
|
|
.map(image => image.xl.url.replace('.thumb', ''));
|
|
|
|
}
|
2020-01-14 03:50:42 +00:00
|
|
|
|
2020-05-14 02:26:05 +00:00
|
|
|
return [];
|
2020-01-14 03:50:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function scrapeLatestX(data, site) {
|
2020-05-14 02:26:05 +00:00
|
|
|
if (site.parameters?.extract === true && data.collections.length > 0) {
|
|
|
|
// release should not belong to any channel
|
|
|
|
return null;
|
|
|
|
}
|
2020-02-04 02:12:09 +00:00
|
|
|
|
2020-05-14 02:26:05 +00:00
|
|
|
if (typeof site.parameters?.extract === 'string' && !data.collections.some(collection => collection.shortName === site.parameters.extract)) {
|
|
|
|
// release should belong to specific channel
|
|
|
|
return null;
|
|
|
|
}
|
2020-02-04 02:12:09 +00:00
|
|
|
|
2020-05-14 02:26:05 +00:00
|
|
|
const release = {
|
|
|
|
entryId: data.id,
|
|
|
|
title: data.title,
|
|
|
|
description: data.description,
|
|
|
|
};
|
2020-02-19 03:41:53 +00:00
|
|
|
|
2020-06-28 20:29:18 +00:00
|
|
|
const hostname = site.parameters?.native ? site.url : site.parent.url;
|
2020-02-19 03:41:53 +00:00
|
|
|
|
2020-05-14 02:26:05 +00:00
|
|
|
release.url = `${hostname}/scene/${release.entryId}/`;
|
|
|
|
release.date = new Date(data.dateReleased);
|
|
|
|
release.actors = data.actors.map(actor => ({ name: actor.name, gender: actor.gender }));
|
2020-02-19 03:41:53 +00:00
|
|
|
|
2020-05-14 02:26:05 +00:00
|
|
|
release.tags = data.tags.map(tag => tag.name);
|
2020-02-19 03:41:53 +00:00
|
|
|
|
2020-05-14 02:26:05 +00:00
|
|
|
release.duration = data.videos.mediabook?.length;
|
|
|
|
[release.poster, ...release.photos] = getThumbs(data);
|
2020-02-19 03:41:53 +00:00
|
|
|
|
2020-05-14 02:26:05 +00:00
|
|
|
const teaserSources = data.videos.mediabook?.files;
|
2020-02-19 03:41:53 +00:00
|
|
|
|
2020-05-14 02:26:05 +00:00
|
|
|
if (teaserSources) {
|
|
|
|
release.teaser = Object.values(teaserSources).map(teaser => ({
|
|
|
|
src: teaser.urls.view,
|
|
|
|
quality: parseInt(teaser.format, 10),
|
|
|
|
}));
|
|
|
|
}
|
2020-02-19 03:41:53 +00:00
|
|
|
|
2020-05-14 02:26:05 +00:00
|
|
|
return release;
|
2020-01-14 03:50:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
async function scrapeLatest(items, site) {
|
2020-05-14 02:26:05 +00:00
|
|
|
const latestReleases = await Promise.all(items.map(async data => scrapeLatestX(data, site)));
|
2020-02-04 02:12:09 +00:00
|
|
|
|
2020-05-14 02:26:05 +00:00
|
|
|
return latestReleases.filter(Boolean);
|
2020-01-14 03:50:42 +00:00
|
|
|
}
|
|
|
|
|
2020-02-09 02:09:06 +00:00
|
|
|
function scrapeScene(data, url, _site, networkName) {
|
2020-05-14 02:26:05 +00:00
|
|
|
const release = {};
|
2020-02-01 03:42:35 +00:00
|
|
|
|
2020-05-14 02:26:05 +00:00
|
|
|
const { id: entryId, title, description } = data;
|
2020-01-14 03:50:42 +00:00
|
|
|
|
2020-05-14 02:26:05 +00:00
|
|
|
release.entryId = data.id;
|
|
|
|
release.title = title;
|
|
|
|
release.description = description;
|
2020-01-14 03:50:42 +00:00
|
|
|
|
2020-05-14 02:26:05 +00:00
|
|
|
release.date = new Date(data.dateReleased);
|
|
|
|
release.actors = data.actors.map(actor => ({ name: actor.name, gender: actor.gender }));
|
2020-01-14 03:50:42 +00:00
|
|
|
|
2020-05-14 02:26:05 +00:00
|
|
|
release.tags = data.tags.map(tag => tag.name);
|
2020-01-14 03:50:42 +00:00
|
|
|
|
2020-05-14 02:26:05 +00:00
|
|
|
[release.poster, ...release.photos] = getThumbs(data);
|
2020-02-01 03:42:35 +00:00
|
|
|
|
2020-05-14 02:26:05 +00:00
|
|
|
const teaserSources = data.videos.mediabook?.files;
|
2020-02-19 03:41:53 +00:00
|
|
|
|
2020-05-14 02:26:05 +00:00
|
|
|
if (teaserSources) {
|
|
|
|
release.teaser = Object.values(teaserSources).map(teaser => ({
|
|
|
|
src: teaser.urls.view,
|
|
|
|
quality: parseInt(teaser.format, 10),
|
|
|
|
}));
|
|
|
|
}
|
2020-02-01 03:42:35 +00:00
|
|
|
|
2020-05-14 02:26:05 +00:00
|
|
|
const siteName = data.collections[0]?.name || data.brand;
|
|
|
|
release.channel = slugify(siteName, '');
|
2020-02-01 03:42:35 +00:00
|
|
|
|
2020-05-14 02:26:05 +00:00
|
|
|
release.url = url || `https://www.${networkName || data.brand}.com/scene/${entryId}/`;
|
2020-02-01 03:42:35 +00:00
|
|
|
|
2020-05-14 02:26:05 +00:00
|
|
|
return release;
|
2020-01-14 03:50:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function getUrl(site) {
|
2020-05-14 02:26:05 +00:00
|
|
|
const { search } = new URL(site.url);
|
2020-01-14 03:50:42 +00:00
|
|
|
|
2020-05-14 02:26:05 +00:00
|
|
|
if (search.match(/\?site=\d+/)) {
|
|
|
|
return site.url;
|
|
|
|
}
|
2020-01-14 03:50:42 +00:00
|
|
|
|
2020-05-14 02:26:05 +00:00
|
|
|
if (site.parameters?.native) {
|
|
|
|
return `${site.url}/scenes`;
|
|
|
|
}
|
2020-01-30 00:14:31 +00:00
|
|
|
|
2020-05-14 02:26:05 +00:00
|
|
|
if (site.parameters?.extract) {
|
|
|
|
return `${site.url}/scenes`;
|
|
|
|
}
|
2020-01-30 00:14:31 +00:00
|
|
|
|
2020-05-14 02:26:05 +00:00
|
|
|
if (site.parameters?.siteId) {
|
2020-06-28 20:29:18 +00:00
|
|
|
return `${site.parent.url}/scenes?site=${site.parameters.siteId}`;
|
2020-05-14 02:26:05 +00:00
|
|
|
}
|
2020-01-14 03:50:42 +00:00
|
|
|
|
2020-05-14 02:26:05 +00:00
|
|
|
throw new Error(`Mind Geek site '${site.name}' (${site.url}) not supported`);
|
2020-01-14 03:50:42 +00:00
|
|
|
}
|
|
|
|
|
2020-01-27 21:54:14 +00:00
|
|
|
async function getSession(url) {
|
2020-05-14 02:26:05 +00:00
|
|
|
const cookieJar = new CookieJar();
|
|
|
|
const session = bhttp.session({ cookieJar });
|
2020-01-14 03:50:42 +00:00
|
|
|
|
2020-05-14 02:26:05 +00:00
|
|
|
await session.get(url);
|
2020-01-14 03:50:42 +00:00
|
|
|
|
2020-05-14 02:26:05 +00:00
|
|
|
const cookieString = await cookieJar.getCookieStringAsync(url);
|
|
|
|
const { instance_token: instanceToken } = cookieToData(cookieString);
|
2020-01-14 03:50:42 +00:00
|
|
|
|
2020-05-14 02:26:05 +00:00
|
|
|
return { session, instanceToken };
|
2020-01-27 21:54:14 +00:00
|
|
|
}
|
|
|
|
|
2020-02-09 02:09:06 +00:00
|
|
|
function scrapeProfile(data, html, releases = [], networkName) {
|
2020-07-20 23:44:51 +00:00
|
|
|
const { query } = qu.extract(html);
|
2020-01-27 21:54:14 +00:00
|
|
|
|
2020-05-14 02:26:05 +00:00
|
|
|
const profile = {
|
|
|
|
description: data.bio,
|
|
|
|
aliases: data.aliases,
|
|
|
|
};
|
2020-01-27 21:54:14 +00:00
|
|
|
|
2020-05-14 02:26:05 +00:00
|
|
|
const [bust, waist, hip] = data.measurements.split('-');
|
2020-01-27 21:54:14 +00:00
|
|
|
|
2020-05-14 02:26:05 +00:00
|
|
|
profile.gender = data.gender === 'other' ? 'transsexual' : data.gender;
|
2020-01-30 23:25:51 +00:00
|
|
|
|
2020-05-14 02:26:05 +00:00
|
|
|
if (profile.gender === 'female') {
|
|
|
|
if (bust) profile.bust = bust.toUpperCase();
|
|
|
|
if (waist) profile.waist = waist;
|
|
|
|
if (hip) profile.hip = hip;
|
|
|
|
}
|
2020-01-27 21:54:14 +00:00
|
|
|
|
2020-05-14 02:26:05 +00:00
|
|
|
if (data.birthPlace) profile.birthPlace = data.birthPlace;
|
|
|
|
if (data.height) profile.height = inchesToCm(data.height);
|
|
|
|
if (data.weight) profile.weight = lbsToKg(data.weight);
|
2020-01-27 21:54:14 +00:00
|
|
|
|
2020-05-14 02:26:05 +00:00
|
|
|
if (data.images.card_main_rect?.[0]) {
|
|
|
|
profile.avatar = data.images.card_main_rect[0].xl?.url
|
2020-01-29 01:31:55 +00:00
|
|
|
|| data.images.card_main_rect[0].lg?.url
|
|
|
|
|| data.images.card_main_rect[0].md?.url
|
|
|
|
|| data.images.card_main_rect[0].sm?.url
|
|
|
|
|| data.images.card_main_rect[0].xs?.url;
|
2020-05-14 02:26:05 +00:00
|
|
|
}
|
2020-01-27 21:54:14 +00:00
|
|
|
|
2020-07-20 23:44:51 +00:00
|
|
|
const birthdate = query.all('li').find(el => /Date of Birth/.test(el.textContent));
|
|
|
|
if (birthdate) profile.birthdate = query.date(birthdate, 'span', 'MMMM Do, YYYY');
|
2020-01-27 21:54:14 +00:00
|
|
|
|
2020-05-14 02:26:05 +00:00
|
|
|
profile.releases = releases.map(release => scrapeScene(release, null, null, networkName));
|
2020-02-01 03:42:35 +00:00
|
|
|
|
2020-05-14 02:26:05 +00:00
|
|
|
return profile;
|
2020-01-27 21:54:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
async function fetchLatest(site, page = 1) {
|
2020-05-14 02:26:05 +00:00
|
|
|
const url = getUrl(site);
|
|
|
|
const { search } = new URL(url);
|
|
|
|
const siteId = new URLSearchParams(search).get('site');
|
|
|
|
|
|
|
|
const { session, instanceToken } = await getSession(url);
|
|
|
|
|
|
|
|
const beforeDate = moment().add('1', 'day').format('YYYY-MM-DD');
|
|
|
|
const limit = 10;
|
|
|
|
const apiUrl = site.parameters?.native || site.parameters?.extract
|
|
|
|
? `https://site-api.project1service.com/v2/releases?dateReleased=<${beforeDate}&limit=${limit}&offset=${limit * (page - 1)}&orderBy=-dateReleased&type=scene`
|
|
|
|
: `https://site-api.project1service.com/v2/releases?collectionId=${siteId}&dateReleased=<${beforeDate}&limit=${limit}&offset=${limit * (page - 1)}&orderBy=-dateReleased&type=scene`;
|
|
|
|
|
|
|
|
const res = await session.get(apiUrl, {
|
|
|
|
headers: {
|
|
|
|
Instance: instanceToken,
|
|
|
|
Origin: site.url,
|
|
|
|
Referer: url,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
if (res.statusCode === 200 && res.body.result) {
|
|
|
|
return scrapeLatest(res.body.result, site);
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
2020-01-14 03:50:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
async function fetchScene(url, site) {
|
2020-05-14 02:26:05 +00:00
|
|
|
const entryId = url.match(/\d+/)[0];
|
|
|
|
const { session, instanceToken } = await getSession(url);
|
2020-01-14 03:50:42 +00:00
|
|
|
|
2020-05-14 02:26:05 +00:00
|
|
|
const res = await session.get(`https://site-api.project1service.com/v2/releases/${entryId}`, {
|
|
|
|
headers: {
|
|
|
|
Instance: instanceToken,
|
|
|
|
},
|
|
|
|
});
|
2020-01-14 03:50:42 +00:00
|
|
|
|
2020-05-14 02:26:05 +00:00
|
|
|
if (res.statusCode === 200 && res.body.result) {
|
|
|
|
return scrapeScene(res.body.result, url, site);
|
|
|
|
}
|
2020-01-30 00:14:31 +00:00
|
|
|
|
2020-05-14 02:26:05 +00:00
|
|
|
return null;
|
2020-01-27 21:54:14 +00:00
|
|
|
}
|
2020-01-14 03:50:42 +00:00
|
|
|
|
2020-07-20 23:44:51 +00:00
|
|
|
async function fetchProfile({ name: actorName }, networkSlug, actorPath = 'model') {
|
2020-05-18 01:22:03 +00:00
|
|
|
const url = `https://www.${networkSlug}.com`;
|
2020-05-14 02:26:05 +00:00
|
|
|
const { session, instanceToken } = await getSession(url);
|
|
|
|
|
|
|
|
const res = await session.get(`https://site-api.project1service.com/v1/actors/?search=${encodeURI(actorName)}`, {
|
|
|
|
headers: {
|
|
|
|
Instance: instanceToken,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
if (res.statusCode === 200) {
|
|
|
|
const actorData = res.body.result.find(actor => actor.name.toLowerCase() === actorName.toLowerCase());
|
|
|
|
|
|
|
|
if (actorData) {
|
2020-05-18 01:22:03 +00:00
|
|
|
const actorUrl = `https://www.${networkSlug}.com/${actorPath}/${actorData.id}/`;
|
2020-05-14 02:26:05 +00:00
|
|
|
const actorReleasesUrl = `https://site-api.project1service.com/v2/releases?actorId=${actorData.id}&limit=100&offset=0&orderBy=-dateReleased&type=scene`;
|
|
|
|
|
|
|
|
const [actorRes, actorReleasesRes] = await Promise.all([
|
|
|
|
bhttp.get(actorUrl),
|
|
|
|
session.get(actorReleasesUrl, {
|
|
|
|
headers: {
|
|
|
|
Instance: instanceToken,
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
]);
|
|
|
|
|
|
|
|
if (actorRes.statusCode === 200 && actorReleasesRes.statusCode === 200 && actorReleasesRes.body.result) {
|
2020-05-18 01:22:03 +00:00
|
|
|
return scrapeProfile(actorData, actorRes.body.toString(), actorReleasesRes.body.result, networkSlug);
|
2020-05-14 02:26:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (actorRes.statusCode === 200) {
|
2020-05-18 01:22:03 +00:00
|
|
|
return scrapeProfile(actorData, actorRes.body.toString(), null, networkSlug);
|
2020-05-14 02:26:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
2020-01-14 03:50:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
2020-05-14 02:26:05 +00:00
|
|
|
scrapeLatestX,
|
|
|
|
fetchLatest,
|
|
|
|
fetchScene,
|
|
|
|
fetchProfile,
|
2020-01-14 03:50:42 +00:00
|
|
|
};
|