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-10-30 03:45:42 +00:00
|
|
|
const knex = require('../knex');
|
2019-03-24 00:29:22 +00:00
|
|
|
|
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(' ');
|
2019-09-23 16:32:47 +00:00
|
|
|
const sceneIdMatch = titleComponents.slice(-1)[0].match(/(AB|AF|GP|SZ|IV|GIO|RS|TW|MA|FM|SAL|NR|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
|
|
|
}
|
|
|
|
|
2019-10-29 00:47:16 +00:00
|
|
|
function getPoster(posterElement, sceneId) {
|
|
|
|
const posterStyle = posterElement.attr('style');
|
|
|
|
|
|
|
|
if (posterStyle) {
|
|
|
|
return posterStyle.slice(posterStyle.indexOf('(') + 1, -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
const posterRange = posterElement.attr('data-casting');
|
|
|
|
const posterRangeData = posterRange ? JSON.parse(posterRange) : null;
|
|
|
|
const posterTimeRange = posterRangeData[Math.floor(Math.random() * posterRangeData.length)];
|
|
|
|
|
|
|
|
if (typeof posterTimeRange === 'number') {
|
|
|
|
// poster time is already a single time value
|
|
|
|
return `https://legalporno.com/casting/${sceneId}/${posterTimeRange}`;
|
|
|
|
}
|
|
|
|
|
|
|
|
const [max, min] = posterTimeRange.split('-');
|
|
|
|
const posterTime = Math.floor(Math.random() * (Number(max) - Number(min) + 1) + Number(min));
|
|
|
|
|
|
|
|
return `https://legalporno.com/casting/${sceneId}/${posterTime}`;
|
|
|
|
}
|
|
|
|
|
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');
|
|
|
|
|
2019-04-05 01:45:40 +00:00
|
|
|
const originalTitle = sceneLinkElement.text().trim(); // title attribute breaks when they use \\ escaping
|
2019-03-26 00:26:47 +00:00
|
|
|
const { shootId, title } = extractTitle(originalTitle);
|
2019-04-06 21:24:26 +00:00
|
|
|
const entryId = new URL(url).pathname.split('/')[2];
|
2019-03-24 00:29:22 +00:00
|
|
|
|
|
|
|
const date = moment.utc($(element).attr('release'), 'YYYY/MM/DD').toDate();
|
|
|
|
|
2019-10-29 00:47:16 +00:00
|
|
|
const sceneId = $(element).attr('data-content');
|
|
|
|
const posterElement = $(element).find('.thumbnail-avatar');
|
|
|
|
|
|
|
|
const poster = getPoster(posterElement, sceneId);
|
|
|
|
|
2019-03-24 00:29:22 +00:00
|
|
|
return {
|
|
|
|
url,
|
2019-04-06 21:24:26 +00:00
|
|
|
shootId,
|
|
|
|
entryId,
|
2019-03-24 00:29:22 +00:00
|
|
|
title,
|
|
|
|
date,
|
2019-10-29 00:47:16 +00:00
|
|
|
poster,
|
2019-03-24 00:29:22 +00:00
|
|
|
site,
|
|
|
|
};
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-10-29 00:47:16 +00:00
|
|
|
async function scrapeScene(html, url, site, useGallery) {
|
2019-03-24 00:29:22 +00:00
|
|
|
const $ = cheerio.load(html, { normalizeWhitespace: true });
|
2019-10-29 00:47:16 +00:00
|
|
|
const playerObject = $('script:contains("new VideoPlayer")').html();
|
|
|
|
const data = JSON.parse(playerObject.slice(playerObject.indexOf('{"swf":'), playerObject.indexOf('} );') + 1));
|
2019-03-24 00:29:22 +00:00
|
|
|
|
|
|
|
const originalTitle = $('h1.watchpage-title').text().trim();
|
2019-03-26 00:26:47 +00:00
|
|
|
const { shootId, title } = extractTitle(originalTitle);
|
2019-04-06 21:24:26 +00:00
|
|
|
const entryId = new URL(url).pathname.split('/')[2];
|
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
|
|
|
|
2019-10-29 00:47:16 +00:00
|
|
|
const posterStyle = $('#player').attr('style');
|
|
|
|
const poster = posterStyle.slice(posterStyle.indexOf('(') + 1, -1);
|
|
|
|
|
|
|
|
const photos = useGallery
|
|
|
|
? $('.gallery a img').map((photoIndex, photoElement) => $(photoElement).attr('src')).toArray()
|
|
|
|
: $('.screenshots img').map((photoIndex, photoElement) => $(photoElement).attr('src')).toArray();
|
|
|
|
|
|
|
|
const trailer = data.clip.qualities.find(clip => clip.quality === 'vga' || clip.quality === 'hd');
|
|
|
|
|
2019-10-30 03:45:42 +00:00
|
|
|
const studioName = $('.watchpage-studioname').first().text().trim();
|
|
|
|
const studioSlug = studioName.replace(/\s+/g, '').toLowerCase();
|
2019-03-24 00:29:22 +00:00
|
|
|
const rawTags = $(tagsElement).find('a').map((tagIndex, tagElement) => $(tagElement).text()).toArray();
|
2019-10-30 03:45:42 +00:00
|
|
|
|
|
|
|
const [studio, tags] = await Promise.all([
|
|
|
|
knex('studios')
|
|
|
|
.where({ name: studioName })
|
|
|
|
.orWhere({ slug: studioSlug })
|
|
|
|
.first(),
|
|
|
|
matchTags(rawTags),
|
|
|
|
]);
|
2019-03-24 00:29:22 +00:00
|
|
|
|
|
|
|
return {
|
|
|
|
url,
|
2019-03-26 00:26:47 +00:00
|
|
|
shootId,
|
2019-04-06 21:24:26 +00:00
|
|
|
entryId,
|
2019-03-24 00:29:22 +00:00
|
|
|
title,
|
|
|
|
date,
|
|
|
|
actors,
|
|
|
|
duration,
|
2019-10-29 00:47:16 +00:00
|
|
|
poster,
|
|
|
|
photos,
|
|
|
|
trailer: {
|
|
|
|
src: trailer.src,
|
|
|
|
type: trailer.type,
|
|
|
|
quality: trailer.quality === 'vga' ? 480 : 720,
|
|
|
|
},
|
2019-03-24 00:29:22 +00:00
|
|
|
tags,
|
|
|
|
site,
|
2019-10-30 03:45:42 +00:00
|
|
|
studio,
|
2019-03-24 00:29:22 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-04-05 01:45:40 +00:00
|
|
|
async function fetchLatest(site, page = 1) {
|
|
|
|
const res = await bhttp.get(`${site.url}/new-videos/${page}`);
|
2019-03-24 00:29:22 +00:00
|
|
|
|
|
|
|
return scrapeLatest(res.body.toString(), site);
|
|
|
|
}
|
|
|
|
|
|
|
|
async function fetchScene(url, site) {
|
2019-10-29 00:47:16 +00:00
|
|
|
const useGallery = true;
|
|
|
|
|
|
|
|
const res = useGallery
|
|
|
|
? await bhttp.get(`${url}/gallery#gallery`)
|
|
|
|
: await bhttp.get(`${url}/screenshots#screenshots`);
|
2019-03-24 00:29:22 +00:00
|
|
|
|
2019-10-29 00:47:16 +00:00
|
|
|
return scrapeScene(res.body.toString(), url, site, useGallery);
|
2019-03-24 00:29:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
fetchLatest,
|
|
|
|
fetchScene,
|
|
|
|
};
|