2019-09-28 01:26:04 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const bhttp = require('bhttp');
|
|
|
|
const cheerio = require('cheerio');
|
|
|
|
const moment = require('moment');
|
|
|
|
|
2020-01-22 21:25:58 +00:00
|
|
|
const { getPhotos } = require('./gamma');
|
|
|
|
|
2019-09-28 01:26:04 +00:00
|
|
|
async function scrape(json, site) {
|
|
|
|
return Promise.all(json.map(async (scene) => {
|
|
|
|
const {
|
|
|
|
title,
|
|
|
|
description,
|
|
|
|
length,
|
2019-12-11 04:15:23 +00:00
|
|
|
master_categories: tags,
|
2019-09-28 01:26:04 +00:00
|
|
|
ratings_up: likes,
|
|
|
|
ratings_down: dislikes,
|
|
|
|
} = scene;
|
|
|
|
|
|
|
|
const entryId = scene.clip_id;
|
|
|
|
const url = `https://evilangel.com/en/video/${scene.url_title}/${entryId}`;
|
|
|
|
const date = moment(scene.release_date, 'YYYY-MM-DD').toDate();
|
|
|
|
const actors = scene.actors.map(({ name }) => name);
|
|
|
|
const director = scene.directors[0].name;
|
|
|
|
|
|
|
|
const poster = `https://images-evilangel.gammacdn.com/movies${scene.pictures.resized}`;
|
2019-12-11 04:15:23 +00:00
|
|
|
const movie = `https://evilangel.com/en/movie/${scene.url_movie_title}/${scene.movie_id}`;
|
2019-09-28 01:26:04 +00:00
|
|
|
|
|
|
|
return {
|
|
|
|
url,
|
|
|
|
entryId,
|
|
|
|
title,
|
|
|
|
description,
|
|
|
|
length,
|
|
|
|
actors,
|
|
|
|
director,
|
|
|
|
date,
|
|
|
|
tags,
|
|
|
|
poster,
|
|
|
|
rating: {
|
|
|
|
likes,
|
|
|
|
dislikes,
|
|
|
|
},
|
2019-12-11 04:15:23 +00:00
|
|
|
movie,
|
2019-09-28 01:26:04 +00:00
|
|
|
site,
|
|
|
|
};
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
|
|
|
async function scrapeScene(html, url, site) {
|
|
|
|
const $ = cheerio.load(html, { normalizeWhitespace: true });
|
|
|
|
const json = $('script[type="application/ld+json"]').html();
|
|
|
|
const videoJson = $('script:contains("window.ScenePlayerOptions")').html();
|
|
|
|
|
|
|
|
const [data, data2] = JSON.parse(json);
|
|
|
|
const videoData = JSON.parse(videoJson.slice(videoJson.indexOf('{'), videoJson.indexOf('};') + 1));
|
|
|
|
const entryId = new URL(url).pathname.split('/').slice(-1)[0];
|
|
|
|
|
|
|
|
const {
|
|
|
|
name: title,
|
|
|
|
description,
|
|
|
|
} = data;
|
|
|
|
// date in data object is not the release date of the scene, but the date the entry was added
|
|
|
|
const date = moment.utc($('.updatedDate').first().text(), 'MM-DD-YYYY').toDate();
|
|
|
|
|
|
|
|
const actors = data.actor.map(actor => actor.name);
|
2019-10-28 01:12:11 +00:00
|
|
|
const hasTrans = data.actor.some(actor => actor.gender === 'shemale');
|
2019-09-28 01:26:04 +00:00
|
|
|
|
|
|
|
const director = (data.director && data.director[0].name) || (data2.director && data2.director[0].name) || null;
|
|
|
|
const stars = (data.aggregateRating.ratingValue / data.aggregateRating.bestRating) * 5;
|
|
|
|
|
|
|
|
const duration = moment.duration(data.duration.slice(2).split(':')).asSeconds();
|
|
|
|
|
|
|
|
const rawTags = data.keywords.split(', ');
|
2019-12-11 04:15:23 +00:00
|
|
|
const tags = hasTrans ? [...rawTags, 'transsexual'] : rawTags;
|
2019-09-28 01:26:04 +00:00
|
|
|
|
|
|
|
const poster = videoData.picPreview;
|
|
|
|
const trailer = `${videoData.playerOptions.host}${videoData.url}`;
|
|
|
|
|
2020-01-22 21:25:58 +00:00
|
|
|
const photos = await getPhotos($('.picturesItem a').attr('href'), 'evilangel.com', site);
|
|
|
|
|
2019-09-28 01:26:04 +00:00
|
|
|
return {
|
|
|
|
url,
|
|
|
|
entryId,
|
|
|
|
title,
|
|
|
|
date,
|
|
|
|
actors,
|
|
|
|
director,
|
|
|
|
description,
|
|
|
|
duration,
|
|
|
|
tags,
|
|
|
|
poster,
|
2020-01-22 21:25:58 +00:00
|
|
|
photos,
|
2019-09-28 01:26:04 +00:00
|
|
|
trailer: {
|
|
|
|
src: trailer,
|
|
|
|
quality: parseInt(videoData.sizeOnLoad, 10),
|
|
|
|
},
|
|
|
|
rating: {
|
|
|
|
stars,
|
|
|
|
},
|
|
|
|
site,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-01-22 21:25:58 +00:00
|
|
|
function scrapeActor(data) {
|
|
|
|
const actor = {};
|
|
|
|
|
|
|
|
if (data.male === 1) actor.gender = 'male';
|
|
|
|
if (data.female === 1) actor.gender = 'female';
|
|
|
|
if (data.shemale === 1 || data.trans === 1) actor.gender = 'transsexual';
|
|
|
|
|
|
|
|
if (data.description) actor.description = data.description.trim();
|
|
|
|
|
|
|
|
if (data.attributes.ethnicity) actor.ethnicity = data.attributes.ethnicity;
|
|
|
|
if (data.attributes.eye_color) actor.eyes = data.attributes.eye_color;
|
|
|
|
if (data.attributes.hair_color) actor.hair = data.attributes.hair_color;
|
|
|
|
|
|
|
|
const avatarPath = Object.values(data.pictures).reverse()[0];
|
|
|
|
actor.avatar = `https://images01-evilangel.gammacdn.com/actors${avatarPath}`;
|
|
|
|
|
|
|
|
return actor;
|
|
|
|
}
|
|
|
|
|
|
|
|
async function fetchApiCredentials() {
|
2019-09-28 01:26:04 +00:00
|
|
|
const res = await bhttp.get('https://evilangel.com/en/videos');
|
|
|
|
const body = res.body.toString();
|
|
|
|
|
|
|
|
const apiLine = body.split('\n').find(bodyLine => bodyLine.match('apiKey'));
|
|
|
|
const apiSerial = apiLine.slice(apiLine.indexOf('{'), apiLine.indexOf('};') + 1);
|
|
|
|
const apiData = JSON.parse(apiSerial);
|
|
|
|
|
|
|
|
const { applicationID: appId, apiKey } = apiData.api.algolia;
|
|
|
|
const userAgent = 'Algolia for vanilla JavaScript (lite) 3.27.0;instantsearch.js 2.7.4;JS Helper 2.26.0';
|
|
|
|
|
2020-01-22 21:25:58 +00:00
|
|
|
const apiUrl = `https://${appId.toLowerCase()}-dsn.algolia.net/1/indexes/*/queries?x-algolia-agent=${userAgent}&x-algolia-application-id=${appId}&x-algolia-api-key=${apiKey}`;
|
|
|
|
|
|
|
|
return {
|
|
|
|
appId,
|
|
|
|
apiKey,
|
|
|
|
userAgent,
|
|
|
|
apiUrl,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
async function fetchLatest(site, page = 1, upcoming = false) {
|
|
|
|
const { apiUrl } = await fetchApiCredentials();
|
|
|
|
|
|
|
|
const res = await bhttp.post(apiUrl, {
|
2019-09-28 01:26:04 +00:00
|
|
|
requests: [
|
|
|
|
{
|
|
|
|
indexName: 'all_scenes',
|
2020-01-10 01:43:04 +00:00
|
|
|
params: `query=&hitsPerPage=36&maxValuesPerFacet=100&page=${page - 1}&facetFilters=[["lesbian:"],["bisex:"],["shemale:"],["upcoming:${upcoming ? 1 : 0}"]]`,
|
2019-09-28 01:26:04 +00:00
|
|
|
},
|
|
|
|
],
|
|
|
|
}, {
|
|
|
|
headers: {
|
|
|
|
Referer: 'https://www.evilangel.com/en/videos',
|
|
|
|
},
|
|
|
|
encodeJSON: true,
|
|
|
|
});
|
|
|
|
|
2020-01-22 21:25:58 +00:00
|
|
|
return scrape(res.body.results[0].hits, site);
|
2019-09-28 01:26:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
async function fetchUpcoming(site) {
|
|
|
|
return fetchLatest(site, 1, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
async function fetchScene(url, site) {
|
|
|
|
const res = await bhttp.get(url);
|
|
|
|
|
|
|
|
return scrapeScene(res.body.toString(), url, site);
|
|
|
|
}
|
|
|
|
|
2020-01-22 21:25:58 +00:00
|
|
|
async function fetchProfile(actorName) {
|
|
|
|
const { apiUrl } = await fetchApiCredentials();
|
|
|
|
const actorSlug = encodeURI(actorName);
|
|
|
|
|
|
|
|
const res = await bhttp.post(apiUrl, {
|
|
|
|
requests: [
|
|
|
|
{
|
|
|
|
indexName: 'all_actors',
|
|
|
|
params: `query=${actorSlug}`,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
}, {
|
|
|
|
headers: {
|
|
|
|
Referer: `https://www.evilangel.com/en/search?query=${actorSlug}&tab=actors`,
|
|
|
|
},
|
|
|
|
encodeJSON: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
if (res.statusCode === 200 && res.body.results[0].hits.length > 0) {
|
|
|
|
const actorData = res.body.results[0].hits.find(actor => actor.name === actorName);
|
|
|
|
|
|
|
|
if (actorData) {
|
|
|
|
return scrapeActor(actorData);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2019-09-28 01:26:04 +00:00
|
|
|
module.exports = {
|
|
|
|
fetchLatest,
|
2020-01-22 21:25:58 +00:00
|
|
|
fetchProfile,
|
2019-09-28 01:26:04 +00:00
|
|
|
fetchScene,
|
2020-01-22 21:25:58 +00:00
|
|
|
fetchUpcoming,
|
2019-09-28 01:26:04 +00:00
|
|
|
};
|