2019-03-04 01:46:33 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const bhttp = require('bhttp');
|
|
|
|
const cheerio = require('cheerio');
|
2019-03-04 03:19:03 +00:00
|
|
|
const moment = require('moment');
|
2019-03-04 01:46:33 +00:00
|
|
|
|
2019-03-25 02:57:33 +00:00
|
|
|
const { matchTags } = require('../tags');
|
2019-03-24 00:29:22 +00:00
|
|
|
|
2019-03-04 01:46:33 +00:00
|
|
|
function scrape(html, site) {
|
|
|
|
const $ = cheerio.load(html, { normalizeWhitespace: true });
|
2019-03-26 00:26:47 +00:00
|
|
|
const scenesElements = $('li[data-itemtype=scene]').toArray();
|
2019-03-04 01:46:33 +00:00
|
|
|
|
|
|
|
return scenesElements.map((element) => {
|
|
|
|
const sceneLinkElement = $(element).find('.sceneTitle a');
|
|
|
|
const url = `${site.url}${sceneLinkElement.attr('href')}`;
|
|
|
|
const title = sceneLinkElement.attr('title');
|
|
|
|
|
2019-03-26 00:26:47 +00:00
|
|
|
const shootId = $(element).attr('data-itemid');
|
|
|
|
|
2019-03-18 03:46:53 +00:00
|
|
|
const date = moment
|
|
|
|
.utc($(element).find('.sceneDate').text(), 'MM-DD-YYYY')
|
|
|
|
.toDate();
|
2019-03-04 01:46:33 +00:00
|
|
|
|
|
|
|
const actors = $(element).find('.sceneActors a')
|
|
|
|
.map((actorIndex, actorElement) => $(actorElement).attr('title'))
|
|
|
|
.toArray();
|
|
|
|
|
2019-03-18 03:46:53 +00:00
|
|
|
const [likes, dislikes] = $(element).find('.value')
|
|
|
|
.toArray()
|
|
|
|
.map(value => Number($(value).text()));
|
2019-03-04 01:46:33 +00:00
|
|
|
|
|
|
|
return {
|
|
|
|
url,
|
2019-03-26 00:26:47 +00:00
|
|
|
shootId,
|
2019-03-04 01:46:33 +00:00
|
|
|
title,
|
|
|
|
actors,
|
2019-04-04 02:00:28 +00:00
|
|
|
director: 'Mason',
|
2019-03-04 01:46:33 +00:00
|
|
|
date,
|
|
|
|
rating: {
|
|
|
|
likes,
|
|
|
|
dislikes,
|
|
|
|
},
|
2019-03-11 03:19:36 +00:00
|
|
|
site,
|
2019-03-04 01:46:33 +00:00
|
|
|
};
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-03-25 02:57:33 +00:00
|
|
|
async function scrapeSceneFallback($, url, site) {
|
2019-03-26 00:26:47 +00:00
|
|
|
const shootId = new URL(url).pathname.split('/').slice(-1)[0];
|
2019-03-23 21:48:39 +00:00
|
|
|
const title = $('h1.title').text();
|
|
|
|
const date = moment.utc($('.updatedDate').text(), 'MM-DD-YYYY').toDate();
|
|
|
|
const actors = $('.sceneColActors a').map((actorIndex, actorElement) => $(actorElement).text()).toArray();
|
2019-03-24 00:29:22 +00:00
|
|
|
|
|
|
|
const description = ($('.sceneDesc').text() || '').replace(/Video Description:/g, ' ').trim();
|
2019-03-23 21:48:39 +00:00
|
|
|
const stars = $('.currentRating').text().split('/')[0] / 2;
|
|
|
|
|
2019-03-24 00:29:22 +00:00
|
|
|
const rawTags = $('.sceneColCategories > a').map((tagIndex, tagElement) => $(tagElement).text()).toArray();
|
2019-03-25 02:57:33 +00:00
|
|
|
const tags = await matchTags(rawTags);
|
2019-03-24 00:29:22 +00:00
|
|
|
|
|
|
|
return {
|
|
|
|
url,
|
2019-03-26 00:26:47 +00:00
|
|
|
shootId,
|
2019-03-24 00:29:22 +00:00
|
|
|
title,
|
|
|
|
date,
|
|
|
|
actors,
|
2019-04-04 02:00:28 +00:00
|
|
|
director: 'Mason',
|
2019-03-24 00:29:22 +00:00
|
|
|
description,
|
|
|
|
tags,
|
|
|
|
rating: {
|
|
|
|
stars,
|
|
|
|
},
|
|
|
|
site,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-03-25 02:57:33 +00:00
|
|
|
async function scrapeScene(html, url, site) {
|
2019-03-24 00:29:22 +00:00
|
|
|
const $ = cheerio.load(html, { normalizeWhitespace: true });
|
|
|
|
const json = $('script[type="application/ld+json"]').html();
|
|
|
|
|
|
|
|
if (!json) {
|
|
|
|
return scrapeSceneFallback($, url, site);
|
|
|
|
}
|
|
|
|
|
|
|
|
const data = JSON.parse(json)[0];
|
2019-03-26 00:26:47 +00:00
|
|
|
const shootId = new URL(url).pathname.split('/').slice(-1)[0];
|
2019-03-24 00:29:22 +00:00
|
|
|
|
|
|
|
const title = data.isPartOf.name;
|
|
|
|
const date = moment.utc(data.dateCreated, 'YYYY-MM-DD').toDate();
|
|
|
|
|
|
|
|
const actors = data.actor
|
|
|
|
.sort(({ genderA }, { genderB }) => {
|
|
|
|
if (genderA === 'female' && genderB === 'male') return 1;
|
|
|
|
if (genderA === 'male' && genderB === 'female') return -1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
})
|
|
|
|
.map(actor => actor.name);
|
|
|
|
|
|
|
|
const description = data.description || undefined;
|
|
|
|
const stars = (data.aggregateRating.ratingValue / data.aggregateRating.bestRating) * 5;
|
|
|
|
|
2019-03-24 04:28:18 +00:00
|
|
|
const duration = moment.duration(data.duration.slice(2).split(':')).asSeconds();
|
2019-03-24 00:29:22 +00:00
|
|
|
|
|
|
|
const rawTags = data.keywords.split(', ');
|
2019-03-25 02:57:33 +00:00
|
|
|
const tags = await matchTags(rawTags);
|
2019-03-24 00:29:22 +00:00
|
|
|
|
2019-03-23 21:48:39 +00:00
|
|
|
return {
|
|
|
|
url,
|
2019-03-26 00:26:47 +00:00
|
|
|
shootId,
|
2019-03-23 21:48:39 +00:00
|
|
|
title,
|
|
|
|
date,
|
|
|
|
actors,
|
2019-04-04 02:00:28 +00:00
|
|
|
director: 'Mason',
|
2019-03-23 21:48:39 +00:00
|
|
|
description,
|
2019-03-24 00:29:22 +00:00
|
|
|
duration,
|
|
|
|
tags,
|
2019-03-23 21:48:39 +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}/en/videos/AllCategories/0/${page}`);
|
2019-03-23 21:48:39 +00:00
|
|
|
|
2019-04-05 01:45:40 +00:00
|
|
|
return scrape(res.body.toString(), site);
|
2019-03-23 21:48:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
async function fetchUpcoming(site) {
|
|
|
|
const res = await bhttp.get(`${site.url}/en/videos/AllCategories/0/1/upcoming`);
|
|
|
|
|
|
|
|
return scrape(res.body.toString(), site);
|
|
|
|
}
|
|
|
|
|
|
|
|
async function fetchScene(url, site) {
|
|
|
|
const res = await bhttp.get(url);
|
2019-03-04 01:46:33 +00:00
|
|
|
|
2019-03-23 21:48:39 +00:00
|
|
|
return scrapeScene(res.body.toString(), url, site);
|
2019-03-04 01:46:33 +00:00
|
|
|
}
|
|
|
|
|
2019-03-23 21:48:39 +00:00
|
|
|
module.exports = {
|
|
|
|
fetchLatest,
|
|
|
|
fetchUpcoming,
|
|
|
|
fetchScene,
|
|
|
|
};
|