2019-04-07 23:49:45 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const bhttp = require('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 {
|
|
|
|
scrapeLatestX,
|
|
|
|
fetchLatest,
|
|
|
|
fetchScene,
|
|
|
|
fetchProfile,
|
|
|
|
} = require('./mindgeek');
|
2019-04-07 23:49:45 +00:00
|
|
|
|
2019-12-06 23:42:47 +00:00
|
|
|
function scrapeLatestClassic(html, site) {
|
|
|
|
const $ = cheerio.load(html, { normalizeWhitespace: true });
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
2020-01-14 03:50:42 +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) {
|
|
|
|
const res = await bhttp.get(`${site.url}/scenes?page=${page}`);
|
|
|
|
|
|
|
|
if (res.statusCode === 200) {
|
|
|
|
return scrapeLatestClassic(res.body.toString(), site);
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2020-01-14 03:50:42 +00:00
|
|
|
async function fetchLatestWrap(site, page = 1) {
|
2019-12-06 23:42:47 +00:00
|
|
|
if (site.parameters && site.parameters.classic) {
|
|
|
|
return fetchClassic(site, page);
|
|
|
|
}
|
|
|
|
|
2020-01-14 03:50:42 +00:00
|
|
|
return fetchLatest(site, page);
|
2019-04-07 23:49:45 +00:00
|
|
|
}
|
|
|
|
|
2020-01-27 21:54:14 +00:00
|
|
|
async function networkFetchProfile(actorName) {
|
|
|
|
return fetchProfile(actorName, 'realitykings');
|
|
|
|
}
|
|
|
|
|
2019-04-07 23:49:45 +00:00
|
|
|
module.exports = {
|
2020-01-14 03:50:42 +00:00
|
|
|
fetchLatest: fetchLatestWrap,
|
2020-01-27 21:54:14 +00:00
|
|
|
fetchProfile: networkFetchProfile,
|
2019-04-07 23:49:45 +00:00
|
|
|
fetchScene,
|
|
|
|
};
|