2019-04-04 02:00:28 +00:00
|
|
|
'use strict';
|
|
|
|
|
2019-04-07 03:19:44 +00:00
|
|
|
/* eslint-disable newline-per-chained-call */
|
2019-04-04 02:00:28 +00:00
|
|
|
const bhttp = require('bhttp');
|
|
|
|
const cheerio = require('cheerio');
|
|
|
|
const moment = require('moment');
|
|
|
|
|
|
|
|
const { matchTags } = require('../tags');
|
|
|
|
|
2019-11-11 04:18:28 +00:00
|
|
|
const defaultTags = {
|
|
|
|
blacked: ['bbc'],
|
|
|
|
blackedraw: ['bbc'],
|
|
|
|
tushy: ['anal'],
|
|
|
|
tushyraw: ['anal'],
|
|
|
|
vixen: [],
|
|
|
|
deeper: [],
|
|
|
|
};
|
|
|
|
|
2019-04-04 02:00:28 +00:00
|
|
|
function scrapeLatest(html, site) {
|
|
|
|
const $ = cheerio.load(html, { normalizeWhitespace: true });
|
|
|
|
|
2019-09-26 01:27:01 +00:00
|
|
|
const stateScript = $('script:contains("INITIAL_STATE")').html();
|
|
|
|
const { videos: scenes } = JSON.parse(stateScript.slice(stateScript.indexOf('{'), stateScript.indexOf('};') + 1));
|
2019-04-04 02:00:28 +00:00
|
|
|
|
|
|
|
return scenes.map((scene) => {
|
2019-11-16 02:33:36 +00:00
|
|
|
const entryId = String(scene.newId);
|
2019-09-25 02:52:58 +00:00
|
|
|
|
|
|
|
const {
|
|
|
|
title,
|
|
|
|
models: actors,
|
|
|
|
} = scene;
|
|
|
|
|
2019-04-04 02:00:28 +00:00
|
|
|
const url = `${site.url}${scene.targetUrl}`;
|
|
|
|
const date = moment.utc(scene.releaseDateFormatted, 'MMMM DD, YYYY').toDate();
|
|
|
|
const stars = Number(scene.textRating) / 2;
|
|
|
|
|
2019-09-25 02:52:58 +00:00
|
|
|
// largest thumbnail. poster is the same image but bigger, too large for storage space efficiency
|
|
|
|
const poster = scene.images.listing.slice(-1)[0].src;
|
|
|
|
const trailer = scene.previews.listing.slice(-1)[0];
|
|
|
|
|
2019-04-04 02:00:28 +00:00
|
|
|
return {
|
|
|
|
url,
|
2019-11-16 02:33:36 +00:00
|
|
|
entryId,
|
2019-04-04 02:00:28 +00:00
|
|
|
title,
|
|
|
|
actors,
|
|
|
|
date,
|
2019-09-25 02:52:58 +00:00
|
|
|
poster,
|
|
|
|
trailer: {
|
|
|
|
src: trailer.src,
|
|
|
|
type: trailer.type,
|
|
|
|
quality: trailer.height,
|
|
|
|
},
|
2019-04-04 02:00:28 +00:00
|
|
|
rating: {
|
|
|
|
stars,
|
|
|
|
},
|
|
|
|
site,
|
|
|
|
};
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async function scrapeScene(html, url, site) {
|
|
|
|
const $ = cheerio.load(html, { normalizeWhitespace: true });
|
|
|
|
const { pathname, search } = new URL(url);
|
|
|
|
|
|
|
|
const stateObject = $('script:contains("INITIAL_STATE")');
|
|
|
|
const data = JSON.parse(stateObject.html().trim().slice(27, -1));
|
|
|
|
|
2019-11-16 02:33:36 +00:00
|
|
|
const entryId = data.page.data[`${pathname}${search}`].data.video;
|
|
|
|
const scene = data.videos.find(video => video.newId === entryId);
|
2019-09-25 00:44:25 +00:00
|
|
|
|
2019-09-26 01:27:01 +00:00
|
|
|
const [poster, ...photos] = scene.rotatingThumbsUrlSizes.map(photo => photo['1040w']);
|
|
|
|
const trailer = scene.previews.listing.find(preview => preview.height === 353) || null;
|
2019-09-25 02:52:58 +00:00
|
|
|
|
2019-09-25 00:44:25 +00:00
|
|
|
const {
|
|
|
|
title,
|
|
|
|
description,
|
|
|
|
models: actors,
|
|
|
|
totalRateVal: stars,
|
2019-09-25 02:52:58 +00:00
|
|
|
runLength: duration,
|
|
|
|
directorNames: director,
|
|
|
|
tags: rawTags,
|
2019-09-25 00:44:25 +00:00
|
|
|
} = scene;
|
2019-04-04 02:00:28 +00:00
|
|
|
|
|
|
|
const date = new Date(scene.releaseDate);
|
2019-11-11 04:18:28 +00:00
|
|
|
const tags = await matchTags([...defaultTags[site.slug], ...rawTags]);
|
2019-04-04 02:00:28 +00:00
|
|
|
|
|
|
|
return {
|
|
|
|
url,
|
2019-11-16 02:33:36 +00:00
|
|
|
entryId,
|
2019-04-04 02:00:28 +00:00
|
|
|
title,
|
2019-09-25 00:44:25 +00:00
|
|
|
description,
|
2019-04-04 02:00:28 +00:00
|
|
|
actors,
|
|
|
|
director,
|
|
|
|
date,
|
|
|
|
duration,
|
|
|
|
tags,
|
2019-09-26 01:27:01 +00:00
|
|
|
photos,
|
|
|
|
poster,
|
|
|
|
trailer: trailer && {
|
|
|
|
src: trailer.src,
|
|
|
|
type: trailer.type,
|
|
|
|
quality: 353,
|
|
|
|
},
|
2019-04-04 02:00:28 +00:00
|
|
|
rating: {
|
|
|
|
stars,
|
|
|
|
},
|
|
|
|
site,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-04-05 01:45:40 +00:00
|
|
|
async function fetchLatest(site, page = 1) {
|
|
|
|
const res = await bhttp.get(`${site.url}/videos?page=${page}&size=7`);
|
2019-04-04 02:00:28 +00:00
|
|
|
|
|
|
|
return scrapeLatest(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,
|
|
|
|
fetchScene,
|
|
|
|
};
|