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
|
|
|
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
|
2019-03-26 00:26:47 +00:00
|
|
|
const shootId = sceneIdMatch ? sceneIdMatch[0] : null;
|
2019-03-24 00:29:22 +00:00
|
|
|
const title = sceneIdMatch ? titleComponents.slice(0, -1).join(' ') : originalTitle;
|
|
|
|
|
2019-03-26 00:26:47 +00:00
|
|
|
return { shootId, title };
|
2019-03-24 00:29:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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');
|
2019-03-26 00:26:47 +00:00
|
|
|
const { shootId, title } = extractTitle(originalTitle);
|
2019-03-24 00:29:22 +00:00
|
|
|
|
|
|
|
const date = moment.utc($(element).attr('release'), 'YYYY/MM/DD').toDate();
|
|
|
|
|
|
|
|
return {
|
|
|
|
url,
|
2019-03-26 00:26:47 +00:00
|
|
|
shootId,
|
2019-03-24 00:29:22 +00:00
|
|
|
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();
|
2019-03-26 00:26:47 +00:00
|
|
|
const { shootId, title } = extractTitle(originalTitle);
|
2019-03-24 00:29:22 +00:00
|
|
|
|
|
|
|
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,
|
2019-03-26 00:26:47 +00:00
|
|
|
shootId,
|
2019-03-24 00:29:22 +00:00
|
|
|
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,
|
|
|
|
};
|