2019-04-04 02:00:28 +00:00
|
|
|
'use strict';
|
|
|
|
|
2019-04-07 03:19:44 +00:00
|
|
|
/* eslint-disable newline-per-chained-call */
|
2020-02-22 22:25:10 +00:00
|
|
|
const Promise = require('bluebird');
|
2019-04-04 02:00:28 +00:00
|
|
|
const moment = require('moment');
|
|
|
|
|
2020-02-22 22:25:10 +00:00
|
|
|
const { get, post } = require('../utils/http');
|
|
|
|
const slugify = require('../utils/slugify');
|
|
|
|
|
|
|
|
const genderMap = {
|
|
|
|
F: 'female',
|
|
|
|
M: 'male',
|
|
|
|
T: 'transsexual', // not yet observed
|
|
|
|
};
|
|
|
|
|
2020-02-22 04:29:02 +00:00
|
|
|
function getPosterFallbacks(poster) {
|
|
|
|
return poster
|
|
|
|
.filter(image => /landscape/i.test(image.name))
|
|
|
|
.sort((imageA, imageB) => imageB.height - imageA.height)
|
|
|
|
.map((image) => {
|
|
|
|
const sources = [image.src, image.highdpi?.['2x'], image.highdpi?.['3x']];
|
|
|
|
// high DPI images for full HD source are huge, only prefer for smaller fallback sources
|
|
|
|
return image.height === 1080 ? sources : sources.reverse();
|
|
|
|
})
|
|
|
|
.flat();
|
|
|
|
}
|
|
|
|
|
2020-02-22 22:25:10 +00:00
|
|
|
function getTeaserFallbacks(teaser) {
|
|
|
|
return teaser
|
|
|
|
.filter(video => /landscape/i.test(video.name))
|
|
|
|
.map(video => ({
|
|
|
|
src: video.src,
|
|
|
|
type: video.type,
|
|
|
|
quality: Number(String(video.height).replace('353', '360')),
|
|
|
|
}));
|
|
|
|
}
|
2019-04-04 02:00:28 +00:00
|
|
|
|
2020-02-22 22:25:10 +00:00
|
|
|
function getAvatarFallbacks(avatar) {
|
|
|
|
return avatar
|
|
|
|
.sort((imageA, imageB) => imageB.height - imageA.height)
|
|
|
|
.map(image => [image.highdpi?.['3x'], image.highdpi?.['2x'], image.src])
|
|
|
|
.flat();
|
|
|
|
}
|
2019-04-04 02:00:28 +00:00
|
|
|
|
2020-02-22 22:25:10 +00:00
|
|
|
function scrapeAll(scenes, site, origin) {
|
2019-04-04 02:00:28 +00:00
|
|
|
return scenes.map((scene) => {
|
2020-02-22 22:25:10 +00:00
|
|
|
const release = {};
|
|
|
|
|
|
|
|
release.title = scene.title;
|
|
|
|
|
|
|
|
release.entryId = String(scene.newId);
|
|
|
|
release.url = `${site?.url || origin}${scene.targetUrl}`;
|
|
|
|
|
|
|
|
release.date = moment.utc(scene.releaseDate).toDate();
|
|
|
|
release.shootDate = moment.utc(scene.shootDate).toDate();
|
|
|
|
|
|
|
|
release.actors = scene.models;
|
|
|
|
release.stars = Number(scene.textRating) / 2;
|
|
|
|
|
|
|
|
release.poster = getPosterFallbacks(scene.images.poster);
|
|
|
|
release.teaser = getTeaserFallbacks(scene.previews.poster);
|
|
|
|
|
|
|
|
return release;
|
2019-04-04 02:00:28 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-02-22 22:25:10 +00:00
|
|
|
function scrapeUpcoming(scene, site) {
|
2020-02-22 04:29:02 +00:00
|
|
|
if (!scene || scene.isPreReleasePeriod) return null;
|
2020-02-22 03:37:48 +00:00
|
|
|
|
|
|
|
const release = {};
|
|
|
|
|
|
|
|
release.title = scene.targetUrl
|
|
|
|
.slice(1)
|
|
|
|
.split('-')
|
|
|
|
.map(component => `${component.charAt(0).toUpperCase()}${component.slice(1)}`)
|
|
|
|
.join(' ');
|
|
|
|
|
|
|
|
release.url = `${site.url}${scene.targetUrl}`;
|
|
|
|
|
2020-02-22 22:25:10 +00:00
|
|
|
release.date = moment.utc(scene.releaseDate).toDate();
|
|
|
|
release.shootDate = moment.utc(scene.shootDate).toDate();
|
|
|
|
|
2020-02-22 03:37:48 +00:00
|
|
|
release.actors = scene.models;
|
|
|
|
|
2020-02-22 04:29:02 +00:00
|
|
|
release.poster = getPosterFallbacks(scene.images.poster);
|
2020-02-22 22:25:10 +00:00
|
|
|
release.teaser = getTeaserFallbacks(scene.previews.poster);
|
2020-02-22 03:37:48 +00:00
|
|
|
|
|
|
|
release.entryId = (release.poster[0] || release.teaser[0])?.match(/\/(\d+)/)?.[1];
|
|
|
|
|
|
|
|
return [release];
|
|
|
|
}
|
|
|
|
|
2020-02-22 22:25:10 +00:00
|
|
|
async function scrapeScene(data, url, site, baseRelease) {
|
|
|
|
const scene = data.video;
|
2019-09-25 00:44:25 +00:00
|
|
|
|
2020-02-22 04:29:02 +00:00
|
|
|
const release = {
|
|
|
|
url,
|
|
|
|
title: scene.title,
|
|
|
|
description: scene.description,
|
|
|
|
actors: scene.models,
|
|
|
|
director: scene.directorNames,
|
|
|
|
duration: scene.runLength,
|
|
|
|
stars: scene.totalRateVal,
|
|
|
|
tags: scene.tags,
|
|
|
|
};
|
2020-02-22 03:37:48 +00:00
|
|
|
|
2020-02-22 22:25:10 +00:00
|
|
|
release.entryId = scene.newId;
|
2019-09-25 02:52:58 +00:00
|
|
|
|
2020-02-22 22:25:10 +00:00
|
|
|
release.date = moment.utc(scene.releaseDate).toDate();
|
|
|
|
release.shootDate = moment.utc(scene.shootDate).toDate();
|
2019-04-04 02:00:28 +00:00
|
|
|
|
2020-02-22 22:25:10 +00:00
|
|
|
release.actors = baseRelease?.actors || scene.models;
|
2019-04-04 02:00:28 +00:00
|
|
|
|
2020-02-22 22:25:10 +00:00
|
|
|
release.poster = getPosterFallbacks(scene.images.poster);
|
|
|
|
release.photos = data.pictureset.map(photo => photo.main[0].src);
|
2020-02-22 04:29:02 +00:00
|
|
|
|
2020-02-22 22:25:10 +00:00
|
|
|
release.teaser = getTeaserFallbacks(scene.previews.poster);
|
2020-02-22 04:29:02 +00:00
|
|
|
|
2020-02-22 22:25:10 +00:00
|
|
|
const qualities = [360, 480, 720, 1080, 2160];
|
|
|
|
const trailersUrl = `${site.url}/api/__tkn/${scene.previewVideoUrl1080P}/trailer/${qualities.join('+')}`;
|
|
|
|
const trailersRes = await post(trailersUrl, null, { headers: { referer: url } });
|
|
|
|
|
|
|
|
if (trailersRes.code === 200) {
|
|
|
|
release.trailer = qualities.map(quality => (trailersRes.body[quality] ? {
|
|
|
|
src: trailersRes.body[quality].token,
|
|
|
|
quality,
|
|
|
|
} : null)).filter(Boolean);
|
|
|
|
}
|
2020-02-22 04:29:02 +00:00
|
|
|
|
|
|
|
return release;
|
2019-04-04 02:00:28 +00:00
|
|
|
}
|
|
|
|
|
2020-02-22 22:25:10 +00:00
|
|
|
async function fetchActorReleases(pages, model, origin) {
|
|
|
|
const releasesPerPage = await Promise.map(pages, async (page) => {
|
|
|
|
const url = `${origin}/api${model.targetUrl}?page=${page}`;
|
|
|
|
const res = await get(url);
|
|
|
|
|
|
|
|
if (res.code === 200) {
|
|
|
|
return scrapeAll(res.body.data.videos.videos, null, origin);
|
|
|
|
}
|
|
|
|
|
|
|
|
return [];
|
|
|
|
}, { concurrency: 3 });
|
|
|
|
|
|
|
|
return releasesPerPage.flat();
|
|
|
|
}
|
|
|
|
|
|
|
|
async function scrapeProfile(data, origin, withReleases) {
|
|
|
|
const model = data.model;
|
|
|
|
const profile = {};
|
|
|
|
|
|
|
|
profile.birthdate = new Date(model.dateOfBirth);
|
|
|
|
profile.gender = genderMap[model.sex];
|
|
|
|
|
|
|
|
profile.hair = model.hairColour;
|
|
|
|
profile.nationality = model.nationality;
|
|
|
|
|
|
|
|
if (model.biography.trim().length > 0) profile.description = model.biography;
|
|
|
|
|
|
|
|
if (model.cupSize && model.bustMeasurment) profile.bust = `${model.bustMeasurment}${model.cupSize}`;
|
|
|
|
if (model.waistMeasurment) profile.waist = model.waistMeasurment;
|
|
|
|
if (model.hipMeasurment) profile.hip = model.hipMeasurment;
|
|
|
|
|
|
|
|
profile.avatar = getAvatarFallbacks(model.images.listing);
|
|
|
|
profile.poster = getAvatarFallbacks(model.images.profile);
|
|
|
|
profile.banner = getAvatarFallbacks(model.images.poster);
|
|
|
|
|
|
|
|
const releases = scrapeAll(data.videos.videos, null, origin);
|
|
|
|
|
|
|
|
if (withReleases) {
|
|
|
|
const pageCount = Math.ceil(data.videos.count / 6);
|
|
|
|
const otherReleases = await fetchActorReleases((Array.from({ length: pageCount - 1 }, (value, index) => index + 2)), model, origin);
|
|
|
|
|
|
|
|
profile.releases = [...releases, ...otherReleases];
|
|
|
|
} else {
|
|
|
|
profile.releases = releases;
|
|
|
|
}
|
|
|
|
|
|
|
|
return profile;
|
|
|
|
}
|
|
|
|
|
2019-04-05 01:45:40 +00:00
|
|
|
async function fetchLatest(site, page = 1) {
|
2020-02-22 22:25:10 +00:00
|
|
|
const url = `${site.url}/api/videos?page=${page}`;
|
|
|
|
const res = await get(url);
|
2020-01-27 02:07:06 +00:00
|
|
|
|
2020-02-22 22:25:10 +00:00
|
|
|
if (res.code === 200) {
|
|
|
|
return scrapeAll(res.body.data.videos, site);
|
2020-01-27 02:07:06 +00:00
|
|
|
}
|
2019-04-04 02:00:28 +00:00
|
|
|
|
2020-02-22 22:25:10 +00:00
|
|
|
return res.code;
|
2020-02-22 03:37:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
async function fetchUpcoming(site) {
|
2020-02-22 22:25:10 +00:00
|
|
|
const apiUrl = `${site.url}/api`;
|
|
|
|
const res = await get(apiUrl);
|
|
|
|
|
|
|
|
if (res.code === 200) {
|
|
|
|
return scrapeUpcoming(res.body.data.nextScene, site);
|
|
|
|
}
|
|
|
|
|
|
|
|
return res.code;
|
|
|
|
}
|
|
|
|
|
|
|
|
async function fetchScene(url, site, baseRelease) {
|
|
|
|
const { origin, pathname } = new URL(url);
|
|
|
|
const apiUrl = `${origin}/api${pathname}`;
|
|
|
|
|
|
|
|
const res = await get(apiUrl);
|
2020-02-22 03:37:48 +00:00
|
|
|
|
2020-02-22 22:25:10 +00:00
|
|
|
if (res.code === 200) {
|
|
|
|
return scrapeScene(res.body.data, url, site, baseRelease);
|
2020-02-22 03:37:48 +00:00
|
|
|
}
|
|
|
|
|
2020-02-22 22:25:10 +00:00
|
|
|
return res.code;
|
2019-04-04 02:00:28 +00:00
|
|
|
}
|
|
|
|
|
2020-02-22 22:25:10 +00:00
|
|
|
async function fetchProfile(actorName, scraperSlug, withReleases) {
|
|
|
|
const origin = `https://www.${scraperSlug}.com`;
|
|
|
|
const actorSlug = slugify(actorName);
|
|
|
|
const url = `${origin}/api/${actorSlug}`;
|
|
|
|
const res = await get(url);
|
2019-04-04 02:00:28 +00:00
|
|
|
|
2020-02-22 22:25:10 +00:00
|
|
|
if (res.code === 200) {
|
|
|
|
return scrapeProfile(res.body.data, origin, withReleases);
|
2020-01-27 02:07:06 +00:00
|
|
|
}
|
|
|
|
|
2020-02-22 22:25:10 +00:00
|
|
|
return null;
|
2019-04-04 02:00:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
fetchLatest,
|
2020-02-22 03:37:48 +00:00
|
|
|
fetchUpcoming,
|
2019-04-04 02:00:28 +00:00
|
|
|
fetchScene,
|
2020-02-22 22:25:10 +00:00
|
|
|
fetchProfile,
|
2019-04-04 02:00:28 +00:00
|
|
|
};
|