2019-04-07 23:49:45 +00:00
|
|
|
'use strict';
|
|
|
|
|
2020-10-30 16:37:10 +00:00
|
|
|
const bhttp = require('@thependulum/bhttp');
|
2019-12-06 23:42:47 +00:00
|
|
|
const cheerio = require('cheerio');
|
2019-04-07 23:49:45 +00:00
|
|
|
|
2020-01-27 21:54:14 +00:00
|
|
|
const {
|
2020-05-14 02:26:05 +00:00
|
|
|
scrapeLatestX,
|
|
|
|
fetchLatest,
|
|
|
|
fetchScene,
|
|
|
|
fetchProfile,
|
2020-01-27 21:54:14 +00:00
|
|
|
} = require('./mindgeek');
|
2019-04-07 23:49:45 +00:00
|
|
|
|
2019-12-06 23:42:47 +00:00
|
|
|
function scrapeLatestClassic(html, site) {
|
2020-05-14 02:26:05 +00:00
|
|
|
const $ = cheerio.load(html, { normalizeWhitespace: true });
|
2019-12-06 23:42:47 +00:00
|
|
|
|
2020-05-14 02:26:05 +00:00
|
|
|
const stateTag = $('script:contains("initialState")').html();
|
|
|
|
const prefix = 'initialState = {';
|
|
|
|
const prefixIndex = stateTag.indexOf('initialState = {');
|
|
|
|
const suffix = '};';
|
|
|
|
const stateString = stateTag.slice(prefixIndex + prefix.length - 1, stateTag.indexOf('};', prefixIndex) + suffix.length - 1);
|
|
|
|
const data = JSON.parse(stateString);
|
2019-12-06 23:42:47 +00:00
|
|
|
|
2020-05-14 02:26:05 +00:00
|
|
|
return Object.values(data.entities.releases).map(scene => scrapeLatestX(scene, site));
|
2019-04-07 23:49:45 +00:00
|
|
|
}
|
|
|
|
|
2019-12-06 23:42:47 +00:00
|
|
|
async function fetchClassic(site, page) {
|
2020-05-14 02:26:05 +00:00
|
|
|
const res = await bhttp.get(`${site.url}/scenes?page=${page}`);
|
2019-12-06 23:42:47 +00:00
|
|
|
|
2020-05-14 02:26:05 +00:00
|
|
|
if (res.statusCode === 200) {
|
|
|
|
return scrapeLatestClassic(res.body.toString(), site);
|
|
|
|
}
|
2019-12-06 23:42:47 +00:00
|
|
|
|
2020-05-14 02:26:05 +00:00
|
|
|
return null;
|
2019-12-06 23:42:47 +00:00
|
|
|
}
|
|
|
|
|
2020-01-14 03:50:42 +00:00
|
|
|
async function fetchLatestWrap(site, page = 1) {
|
2020-05-14 02:26:05 +00:00
|
|
|
if (site.parameters?.classic) {
|
|
|
|
return fetchClassic(site, page);
|
|
|
|
}
|
2019-12-06 23:42:47 +00:00
|
|
|
|
2020-05-14 02:26:05 +00:00
|
|
|
return fetchLatest(site, page);
|
2019-04-07 23:49:45 +00:00
|
|
|
}
|
|
|
|
|
2020-07-20 23:44:51 +00:00
|
|
|
async function networkFetchProfile({ name: actorName }) {
|
|
|
|
return fetchProfile({ name: actorName }, 'realitykings');
|
2020-01-27 21:54:14 +00:00
|
|
|
}
|
|
|
|
|
2019-04-07 23:49:45 +00:00
|
|
|
module.exports = {
|
2020-05-14 02:26:05 +00:00
|
|
|
fetchLatest: fetchLatestWrap,
|
|
|
|
fetchProfile: networkFetchProfile,
|
|
|
|
fetchScene,
|
2019-04-07 23:49:45 +00:00
|
|
|
};
|