Added generic Gamma photo and actor scraper for XEmpire, 21Sextury, Blowpass and Evil Angel.

This commit is contained in:
2020-01-22 22:25:58 +01:00
parent 4e4323704a
commit f8175f6054
17 changed files with 347 additions and 290 deletions

View File

@@ -4,6 +4,8 @@ const bhttp = require('bhttp');
const cheerio = require('cheerio');
const moment = require('moment');
const { getPhotos } = require('./gamma');
async function scrape(json, site) {
return Promise.all(json.map(async (scene) => {
const {
@@ -75,6 +77,8 @@ async function scrapeScene(html, url, site) {
const poster = videoData.picPreview;
const trailer = `${videoData.playerOptions.host}${videoData.url}`;
const photos = await getPhotos($('.picturesItem a').attr('href'), 'evilangel.com', site);
return {
url,
entryId,
@@ -86,6 +90,7 @@ async function scrapeScene(html, url, site) {
duration,
tags,
poster,
photos,
trailer: {
src: trailer,
quality: parseInt(videoData.sizeOnLoad, 10),
@@ -97,7 +102,26 @@ async function scrapeScene(html, url, site) {
};
}
async function fetchLatest(site, page = 1, upcoming = false) {
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() {
const res = await bhttp.get('https://evilangel.com/en/videos');
const body = res.body.toString();
@@ -108,7 +132,20 @@ async function fetchLatest(site, page = 1, upcoming = false) {
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';
const apiRes = await bhttp.post(`https://${appId.toLowerCase()}-dsn.algolia.net/1/indexes/*/queries?x-algolia-agent=${userAgent}&x-algolia-application-id=${appId}&x-algolia-api-key=${apiKey}`, {
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, {
requests: [
{
indexName: 'all_scenes',
@@ -122,7 +159,7 @@ async function fetchLatest(site, page = 1, upcoming = false) {
encodeJSON: true,
});
return scrape(apiRes.body.results[0].hits, site);
return scrape(res.body.results[0].hits, site);
}
async function fetchUpcoming(site) {
@@ -135,8 +172,38 @@ async function fetchScene(url, site) {
return scrapeScene(res.body.toString(), url, site);
}
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;
}
module.exports = {
fetchLatest,
fetchUpcoming,
fetchProfile,
fetchScene,
fetchUpcoming,
};