2019-04-07 18:51:14 +00:00
|
|
|
'use strict';
|
|
|
|
|
2019-12-09 04:00:49 +00:00
|
|
|
const Promise = require('bluebird');
|
2019-04-07 18:51:14 +00:00
|
|
|
const bhttp = require('bhttp');
|
|
|
|
const cheerio = require('cheerio');
|
|
|
|
const moment = require('moment');
|
|
|
|
|
2019-12-09 04:00:49 +00:00
|
|
|
async function fetchPhotos(photoPath) {
|
|
|
|
const res = await bhttp.get(`https://21sextury.com${photoPath}`);
|
|
|
|
|
|
|
|
return res.body.toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
function scrapePhotos(html) {
|
|
|
|
const $ = cheerio.load(html, { normalizeWhitespace: true });
|
|
|
|
|
|
|
|
const unlockedPhotos = $('.preview .imgLink.pgUnlocked')
|
|
|
|
.map((photoIndex, photoElement) => $(photoElement).attr('href')).toArray();
|
|
|
|
|
|
|
|
const lockedThumbnails = $('.preview .imgLink.lockedPicture img')
|
|
|
|
.map((photoIndex, photoElement) => $(photoElement)
|
|
|
|
.attr('src'))
|
|
|
|
// .replace('_tb.jpg', '.jpg')) does not always work
|
|
|
|
.toArray();
|
|
|
|
|
|
|
|
return unlockedPhotos.concat(lockedThumbnails);
|
|
|
|
}
|
|
|
|
|
|
|
|
async function getPhotos(photoPath) {
|
|
|
|
if (!photoPath || photoPath.match('join')) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
|
|
|
const html = await fetchPhotos(photoPath);
|
|
|
|
const $ = cheerio.load(html, { normalizeWhitespace: true });
|
|
|
|
const photos = scrapePhotos(html);
|
|
|
|
const pages = $('.paginatorPages a').map((pageIndex, pageElement) => $(pageElement).attr('href')).toArray();
|
|
|
|
|
|
|
|
const otherPhotos = await Promise.map(pages, async (pagePath) => {
|
|
|
|
const pageHtml = await fetchPhotos(pagePath);
|
|
|
|
|
|
|
|
return scrapePhotos(pageHtml);
|
|
|
|
}, {
|
|
|
|
concurrency: 2,
|
|
|
|
});
|
|
|
|
|
|
|
|
return photos.concat(otherPhotos.flat());
|
|
|
|
}
|
2019-04-07 18:51:14 +00:00
|
|
|
|
|
|
|
function scrape(html, site) {
|
|
|
|
const $ = cheerio.load(html, { normalizeWhitespace: true });
|
|
|
|
const scenesElements = $('li[data-itemtype=scene]').toArray();
|
|
|
|
|
|
|
|
return scenesElements.reduce((accReleases, element) => {
|
|
|
|
const siteName = $(element).find('.studioName a').attr('title');
|
|
|
|
|
2019-12-09 04:00:49 +00:00
|
|
|
if (!site.url && siteName.toLowerCase() !== site.name.toLowerCase()) {
|
|
|
|
// using generic overview as fallback, scene from different site
|
2019-04-07 18:51:14 +00:00
|
|
|
return accReleases;
|
|
|
|
}
|
|
|
|
|
|
|
|
const sceneLinkElement = $(element).find('.sceneTitle a');
|
2019-12-09 04:00:49 +00:00
|
|
|
const url = `${site.url || 'https://www.21sextury.com'}${sceneLinkElement.attr('href')}`;
|
2019-04-07 18:51:14 +00:00
|
|
|
const title = sceneLinkElement.attr('title').trim();
|
|
|
|
|
|
|
|
const entryId = $(element).attr('data-itemid');
|
|
|
|
|
|
|
|
const date = moment
|
|
|
|
.utc($(element).find('.sceneDate').text(), 'MM-DD-YYYY')
|
|
|
|
.toDate();
|
|
|
|
|
|
|
|
const actors = $(element).find('.sceneActors a')
|
|
|
|
.map((actorIndex, actorElement) => $(actorElement).attr('title'))
|
|
|
|
.toArray();
|
|
|
|
|
2019-12-09 04:00:49 +00:00
|
|
|
const poster = $(element).find('.imgLink img').attr('data-original');
|
|
|
|
const trailer = `https://videothumb.gammacdn.com/307x224/${entryId}.mp4`;
|
|
|
|
|
2019-04-07 18:51:14 +00:00
|
|
|
const [likes, dislikes] = $(element).find('.value')
|
|
|
|
.toArray()
|
|
|
|
.map(value => Number($(value).text()));
|
|
|
|
|
|
|
|
return [
|
|
|
|
...accReleases,
|
|
|
|
{
|
|
|
|
url,
|
|
|
|
entryId,
|
|
|
|
title,
|
|
|
|
actors,
|
|
|
|
date,
|
2019-12-09 04:00:49 +00:00
|
|
|
poster,
|
|
|
|
trailer: {
|
|
|
|
src: trailer,
|
|
|
|
},
|
2019-04-07 18:51:14 +00:00
|
|
|
rating: {
|
|
|
|
likes,
|
|
|
|
dislikes,
|
|
|
|
},
|
|
|
|
site,
|
|
|
|
},
|
|
|
|
];
|
|
|
|
}, []);
|
|
|
|
}
|
|
|
|
|
|
|
|
async function scrapeScene(html, url, site) {
|
|
|
|
const $ = cheerio.load(html, { normalizeWhitespace: true });
|
|
|
|
const sceneElement = $('#videoWrapper');
|
|
|
|
const json = $('script[type="application/ld+json"]').html();
|
2019-12-09 04:00:49 +00:00
|
|
|
const videoJson = $('script:contains("ScenePlayerOptions")').html();
|
|
|
|
const videoDataString = videoJson.slice(videoJson.indexOf('= {') + 2, videoJson.indexOf('};') + 1);
|
2019-04-07 18:51:14 +00:00
|
|
|
|
|
|
|
const data = JSON.parse(json)[0];
|
2019-12-09 04:00:49 +00:00
|
|
|
const videoData = JSON.parse(videoDataString);
|
2019-04-07 18:51:14 +00:00
|
|
|
const entryId = new URL(url).pathname.split('/').slice(-1)[0];
|
|
|
|
|
2019-12-09 04:00:49 +00:00
|
|
|
const title = videoData?.playerOptions?.sceneInfos?.sceneTitle || (data.isPartOf && data.isPartOf !== 'TBD' ? data.isPartOf.name : data.name);
|
|
|
|
const dataDate = moment.utc(videoData?.playerOptions?.sceneInfos?.sceneReleaseDate, 'YYYY-MM-DD');
|
2019-04-10 01:42:20 +00:00
|
|
|
|
|
|
|
const date = dataDate.isValid()
|
|
|
|
? dataDate.toDate()
|
|
|
|
: moment.utc(sceneElement.find('.updatedDate').text().trim(), 'MM-DD-YYYY').toDate();
|
2019-04-07 18:51:14 +00:00
|
|
|
|
2019-12-09 04:00:49 +00:00
|
|
|
const actors = data.actor.map(actor => actor.name);
|
2019-04-07 18:51:14 +00:00
|
|
|
|
|
|
|
const description = data.description || null; // prevent empty string
|
|
|
|
const likes = Number(sceneElement.find('.rating .state_1 .value').text());
|
|
|
|
const dislikes = Number(sceneElement.find('#infoWrapper .rating .state_2 .value').text());
|
|
|
|
|
|
|
|
const duration = moment.duration(data.duration.slice(2).split(':')).asSeconds();
|
|
|
|
|
2019-12-09 04:00:49 +00:00
|
|
|
const poster = videoData.picPreview;
|
|
|
|
const trailer = `${videoData.playerOptions.host}${videoData.url}`;
|
|
|
|
|
|
|
|
const photoPath = $('.picturesItem a').attr('href');
|
|
|
|
const photos = await getPhotos(photoPath, site);
|
|
|
|
|
|
|
|
const tags = data.keywords.split(', ');
|
2019-04-07 18:51:14 +00:00
|
|
|
const siteName = data.productionCompany ? data.productionCompany.name : $('#logoLink a').attr('title');
|
2019-12-09 04:00:49 +00:00
|
|
|
const channel = siteName && siteName.replace(/\s+/g, '').toLowerCase();
|
2019-04-07 18:51:14 +00:00
|
|
|
|
|
|
|
return {
|
2019-12-09 04:00:49 +00:00
|
|
|
url,
|
2019-04-07 18:51:14 +00:00
|
|
|
entryId,
|
|
|
|
title,
|
|
|
|
date,
|
|
|
|
actors,
|
|
|
|
description,
|
|
|
|
duration,
|
|
|
|
tags,
|
2019-12-09 04:00:49 +00:00
|
|
|
poster,
|
|
|
|
photos,
|
|
|
|
trailer: {
|
|
|
|
src: trailer,
|
|
|
|
},
|
2019-04-07 18:51:14 +00:00
|
|
|
rating: {
|
|
|
|
likes,
|
|
|
|
dislikes,
|
|
|
|
},
|
2019-12-09 04:00:49 +00:00
|
|
|
site,
|
|
|
|
channel,
|
2019-04-07 18:51:14 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
async function fetchLatest(site, page = 1) {
|
2019-12-09 04:00:49 +00:00
|
|
|
const url = `${site.url || 'https://21sextury.com'}/en/videos/All-Categories/0/All-Pornstars/0/latest/${page}`;
|
|
|
|
const res = await bhttp.get(url);
|
2019-04-07 18:51:14 +00:00
|
|
|
|
|
|
|
return scrape(res.body.toString(), site);
|
|
|
|
}
|
|
|
|
|
|
|
|
async function fetchUpcoming(site) {
|
2019-12-09 04:00:49 +00:00
|
|
|
const url = `${site.url || 'https://21sextury.com'}/en/videos/All-Categories/0/All-Pornstars/0/upcoming`;
|
|
|
|
const res = await bhttp.get(url);
|
2019-04-07 18:51:14 +00:00
|
|
|
|
|
|
|
return scrape(res.body.toString(), site);
|
|
|
|
}
|
|
|
|
|
|
|
|
async function fetchScene(url, site) {
|
|
|
|
const res = await bhttp.get(url);
|
|
|
|
|
|
|
|
return scrapeScene(res.body.toString(), url, site);
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
fetchLatest,
|
|
|
|
fetchUpcoming,
|
|
|
|
fetchScene,
|
|
|
|
};
|