Refactored 21Sextury module to use Gamma API.

This commit is contained in:
2020-02-06 23:51:13 +01:00
parent ee8994582c
commit 65f98c6387
5 changed files with 45 additions and 166 deletions

View File

@@ -6,6 +6,8 @@ const { JSDOM } = require('jsdom');
const cheerio = require('cheerio');
const moment = require('moment');
const { ex } = require('../utils/q');
async function fetchPhotos(url) {
const res = await bhttp.get(url);
@@ -237,39 +239,45 @@ function scrapeActorSearch(html, url, actorName) {
function scrapeProfile(html, url, actorName, siteSlug) {
const { document } = new JSDOM(html).window;
const { q, qu } = ex(html);
const avatarEl = document.querySelector('img.actorPicture');
const descriptionEl = document.querySelector('.actorBio p:not(.bioTitle)');
const hairEl = document.querySelector('.actorProfile .attribute_hair_color');
const heightEl = document.querySelector('.actorProfile .attribute_height');
const weightEl = document.querySelector('.actorProfile .attribute_weight');
const aliasEl = document.querySelector('.actorProfile .attribute_alternate_names');
const nationalityEl = document.querySelector('.actorProfile .attribute_home');
const avatar = q('img.actorPicture');
const hair = q('.actorProfile .attribute_hair_color', true);
const height = q('.actorProfile .attribute_height', true);
const weight = q('.actorProfile .attribute_weight', true);
const alias = q('.actorProfile .attribute_alternate_names', true);
const nationality = q('.actorProfile .attribute_home', true);
const profile = {
name: actorName,
};
if (avatarEl) {
if (avatar) {
// larger sizes usually available, provide fallbacks
const avatars = [
avatarEl.src.replace(/\d+x\d+/, '500x750'),
avatarEl.src.replace(/\d+x\d+/, '240x360'),
avatarEl.src.replace(/\d+x\d+/, '200x300'),
avatarEl.src,
avatar.src.replace(/\d+x\d+/, '500x750'),
avatar.src.replace(/\d+x\d+/, '240x360'),
avatar.src.replace(/\d+x\d+/, '200x300'),
avatar.src,
];
profile.avatar = avatars;
}
if (descriptionEl) profile.description = descriptionEl.textContent.trim();
if (hairEl) profile.hair = hairEl.textContent.split(':')[1].trim();
if (heightEl) profile.height = Number(heightEl.textContent.match(/\d+/)[0]);
if (weightEl) profile.weight = Number(weightEl.textContent.match(/\d+/)[0]);
if (aliasEl) profile.aliases = aliasEl.textContent.split(':')[1].trim().split(', ');
if (nationalityEl) profile.nationality = nationalityEl.textContent.split(':')[1].trim();
profile.description = q('.actorBio p:not(.bioTitle)', true);
if (hair) profile.hair = hair.split(':')[1].trim();
if (height) profile.height = Number(height.match(/\d+/)[0]);
if (weight) profile.weight = Number(weight.match(/\d+/)[0]);
if (alias) profile.aliases = alias.split(':')[1].trim().split(', ');
if (nationality) profile.nationality = nationality.split(':')[1].trim();
/* not fetching all releases
profile.releases = Array.from(document.querySelectorAll('.sceneList .scene a.imgLink'), el => `https://${siteSlug}.com${el.href}`);
const moreReleases = qu('.seeAllTop a');
console.log(moreReleases);
*/
return profile;
}
@@ -322,7 +330,7 @@ async function fetchApiCredentials(referer) {
}
async function fetchApiLatest(site, page = 1, upcoming = false) {
const referer = `${site.url}/en/videos`;
const referer = `${site.parameters?.networkReferer ? site.network.url : site.url}/en/videos`;
const { apiUrl } = await fetchApiCredentials(referer);
const res = await bhttp.post(apiUrl, {
@@ -339,7 +347,7 @@ async function fetchApiLatest(site, page = 1, upcoming = false) {
encodeJSON: true,
});
if (res.statuscode === 200 && res.body.results?.[0]?.hits) {
if (res.statusCode === 200 && res.body.results?.[0]?.hits) {
return scrapeApiReleases(res.body.results[0].hits, site);
}