2019-03-23 21:48:39 +00:00
|
|
|
'use strict';
|
2019-03-24 00:29:22 +00:00
|
|
|
|
|
|
|
const bhttp = require('bhttp');
|
|
|
|
const cheerio = require('cheerio');
|
|
|
|
const moment = require('moment');
|
|
|
|
|
2019-03-25 02:57:33 +00:00
|
|
|
const { matchTags } = require('../tags');
|
|
|
|
|
2019-03-24 00:29:22 +00:00
|
|
|
const tagMap = {
|
|
|
|
'3+ on 1': 'gangbang',
|
|
|
|
anal: 'anal',
|
|
|
|
bbc: 'big black cock',
|
|
|
|
'cum swallowing': 'swallowing',
|
|
|
|
rough: 'rough',
|
|
|
|
'deep throat': 'deepthroat',
|
|
|
|
'double penetration (DP)': 'DP',
|
|
|
|
'double anal (DAP)': 'DAP',
|
|
|
|
'double vaginal (DPP)': 'DVP',
|
|
|
|
'gapes (gaping asshole)': 'gaping',
|
|
|
|
'huge toys': 'toys',
|
|
|
|
interracial: 'interracial',
|
|
|
|
'triple penetration': 'TP',
|
|
|
|
};
|
|
|
|
|
|
|
|
function extractTitle(originalTitle) {
|
|
|
|
const titleComponents = originalTitle.split(' ');
|
|
|
|
const sceneIdMatch = titleComponents.slice(-1)[0].match(/(GP|SZ|IV|GIO|AA|GL|BZ|FS)\d+/); // detect studio prefixes
|
|
|
|
const id = sceneIdMatch ? sceneIdMatch[0] : null;
|
|
|
|
const title = sceneIdMatch ? titleComponents.slice(0, -1).join(' ') : originalTitle;
|
|
|
|
|
|
|
|
return { id, title };
|
|
|
|
}
|
|
|
|
|
|
|
|
function scrapeLatest(html, site) {
|
|
|
|
const $ = cheerio.load(html, { normalizeWhitespace: true });
|
|
|
|
const scenesElements = $('.thumbnails > div').toArray();
|
|
|
|
|
|
|
|
return scenesElements.map((element) => {
|
|
|
|
const sceneLinkElement = $(element).find('.thumbnail-title a');
|
|
|
|
const url = sceneLinkElement.attr('href');
|
|
|
|
|
|
|
|
const originalTitle = sceneLinkElement.attr('title');
|
|
|
|
const { id, title } = extractTitle(originalTitle);
|
|
|
|
|
|
|
|
const date = moment.utc($(element).attr('release'), 'YYYY/MM/DD').toDate();
|
|
|
|
|
|
|
|
return {
|
|
|
|
url,
|
|
|
|
id,
|
|
|
|
title,
|
|
|
|
date,
|
|
|
|
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 originalTitle = $('h1.watchpage-title').text().trim();
|
|
|
|
const { id, title } = extractTitle(originalTitle);
|
|
|
|
|
|
|
|
const date = moment.utc($('span[title="Release date"] a').text(), 'YYYY-MM-DD').toDate();
|
|
|
|
|
|
|
|
const [actorsElement, tagsElement] = $('.scene-description__row').toArray();
|
|
|
|
const actors = $(actorsElement)
|
|
|
|
.find('a[href*="com/model"]')
|
|
|
|
.map((actorIndex, actorElement) => $(actorElement).text()).toArray();
|
|
|
|
|
2019-03-24 04:28:18 +00:00
|
|
|
const duration = moment.duration($('span[title="Runtime"]').text().trim()).asSeconds();
|
2019-03-24 00:29:22 +00:00
|
|
|
|
|
|
|
const rawTags = $(tagsElement).find('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,
|
|
|
|
id,
|
|
|
|
title,
|
|
|
|
date,
|
|
|
|
actors,
|
|
|
|
duration,
|
|
|
|
tags,
|
|
|
|
site,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
async function fetchLatest(site) {
|
|
|
|
const res = await bhttp.get(`${site.url}/new-videos`);
|
|
|
|
|
|
|
|
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,
|
|
|
|
};
|