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');
|
|
|
|
|
2019-11-13 23:00:29 +00:00
|
|
|
const fetchSites = require('../sites');
|
2019-04-04 02:00:28 +00:00
|
|
|
const { matchTags } = require('../tags');
|
|
|
|
|
2019-11-16 02:33:36 +00:00
|
|
|
async function getPhotos(entryId, site) {
|
2019-11-13 23:00:29 +00:00
|
|
|
const { hostname } = new URL(site.url);
|
|
|
|
|
2019-11-16 02:33:36 +00:00
|
|
|
const res = await bhttp.get(`https://${hostname}/gallery.php?type=highres&id=${entryId}`);
|
2019-11-05 00:41:13 +00:00
|
|
|
const html = res.body.toString();
|
|
|
|
|
|
|
|
const $ = cheerio.load(html, { normalizeWhitespace: true });
|
|
|
|
const photos = $('a.fakethumb').map((photoIndex, photoElement) => $(photoElement).attr('data-src') || $(photoElement).attr('href')).toArray();
|
|
|
|
|
|
|
|
return photos;
|
|
|
|
}
|
|
|
|
|
2019-11-13 23:00:29 +00:00
|
|
|
async function getChannelSite($, site) {
|
|
|
|
const { hostname } = new URL(site.url);
|
|
|
|
|
|
|
|
if (site.isFallback && hostname.match('private.com')) {
|
|
|
|
const siteElement = $('.content-wrapper .logos-sites a');
|
|
|
|
const siteUrl = siteElement.attr('href').slice(0, -1);
|
|
|
|
const siteName = siteElement.text();
|
|
|
|
const siteSlug = siteName.replace(/\s+/g, '').toLowerCase();
|
|
|
|
|
|
|
|
const channelSite = await fetchSites({
|
|
|
|
slug: siteSlug,
|
|
|
|
name: siteName,
|
|
|
|
url: siteUrl,
|
|
|
|
});
|
|
|
|
|
|
|
|
return channelSite;
|
|
|
|
}
|
|
|
|
|
|
|
|
return site;
|
|
|
|
}
|
|
|
|
|
2019-04-04 02:00:28 +00:00
|
|
|
function scrapeLatest(html, site) {
|
|
|
|
const $ = cheerio.load(html, { normalizeWhitespace: true });
|
2019-11-13 23:00:29 +00:00
|
|
|
const sceneElements = $('.content-wrapper .scene').toArray();
|
2019-04-04 02:00:28 +00:00
|
|
|
|
|
|
|
return sceneElements.map((element) => {
|
2019-11-13 23:00:29 +00:00
|
|
|
const sceneLinkElement = $(element).find('h3 a');
|
2019-04-04 02:00:28 +00:00
|
|
|
|
|
|
|
const url = sceneLinkElement.attr('href');
|
|
|
|
const title = sceneLinkElement.text();
|
2019-11-16 02:33:36 +00:00
|
|
|
const entryId = url.split('/').slice(-1)[0];
|
2019-04-04 02:00:28 +00:00
|
|
|
|
|
|
|
const date = moment.utc($(element).find('.scene-date'), 'MM/DD/YYYY').toDate();
|
|
|
|
|
2019-11-13 23:00:29 +00:00
|
|
|
const actors = $(element).find('.scene-models a').map((actorIndex, actorElement) => $(actorElement).text()).toArray();
|
2019-04-04 02:00:28 +00:00
|
|
|
const likes = Number($(element).find('.scene-votes').text());
|
|
|
|
|
2019-11-13 23:00:29 +00:00
|
|
|
const thumbnailElement = $(element).find('img.img-responsive');
|
|
|
|
const photoCount = Number(thumbnailElement.attr('thumbs_num'));
|
|
|
|
const poster = thumbnailElement.attr('src');
|
|
|
|
const photos = Array.from({ length: photoCount }, (val, index) => thumbnailElement.attr(`src${index + 1}`));
|
|
|
|
|
|
|
|
const scene = {
|
2019-04-04 02:00:28 +00:00
|
|
|
url,
|
2019-11-16 02:33:36 +00:00
|
|
|
entryId,
|
2019-04-04 02:00:28 +00:00
|
|
|
title,
|
|
|
|
actors,
|
|
|
|
date,
|
2019-11-05 00:41:13 +00:00
|
|
|
poster,
|
|
|
|
photos,
|
2019-04-04 02:00:28 +00:00
|
|
|
rating: {
|
|
|
|
likes,
|
|
|
|
},
|
|
|
|
site,
|
|
|
|
};
|
2019-11-13 23:00:29 +00:00
|
|
|
|
|
|
|
return scene;
|
2019-04-04 02:00:28 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async function scrapeScene(html, url, site) {
|
|
|
|
const $ = cheerio.load(html, { normalizeWhitespace: true });
|
|
|
|
|
2019-11-16 02:33:36 +00:00
|
|
|
const entryId = url.split('/').slice(-1)[0];
|
2019-04-04 02:00:28 +00:00
|
|
|
const title = $('.video-wrapper meta[itemprop="name"]').attr('content');
|
|
|
|
|
2019-04-07 03:19:44 +00:00
|
|
|
const date = moment.utc($('.video-wrapper meta[itemprop="uploadDate"]').attr('content'), 'MM/DD/YYYY').toDate();
|
2019-04-04 02:00:28 +00:00
|
|
|
const actors = $('.content-wrapper .scene-models-list a').map((actorIndex, actorElement) => $(actorElement).text()).toArray();
|
|
|
|
|
|
|
|
const description = $('.video-wrapper meta[itemprop="description"]').attr('content');
|
|
|
|
const [minutes, seconds] = $('.video-wrapper meta[itemprop="duration"]').attr('content').match(/\d+/g);
|
|
|
|
const duration = Number(minutes) * 60 + Number(seconds);
|
|
|
|
|
2019-11-16 02:33:36 +00:00
|
|
|
const posterScript = $('script:contains(poster)').html();
|
|
|
|
const posterLink = posterScript.slice(posterScript.indexOf('https://'), posterScript.indexOf('.jpg') + 4);
|
|
|
|
const poster = $('meta[property="og:image"]').attr('content') || posterLink;
|
|
|
|
|
|
|
|
const trailerElementSrc = $('#videojs-trailer source').attr('src');
|
|
|
|
const trailer = $('meta[property="og:video"]').attr('content') || trailerElementSrc;
|
2019-11-05 00:41:13 +00:00
|
|
|
|
2019-04-04 02:00:28 +00:00
|
|
|
const likes = Number($('.content-desc #social-actions #likes').text());
|
|
|
|
|
|
|
|
const rawTags = $('.content-desc .scene-tags a').map((tagIndex, tagElement) => $(tagElement).text()).toArray();
|
2019-04-04 18:22:47 +00:00
|
|
|
|
2019-11-13 23:00:29 +00:00
|
|
|
const [tags, photos, channelSite] = await Promise.all([
|
2019-04-04 18:22:47 +00:00
|
|
|
matchTags(rawTags),
|
2019-11-16 02:33:36 +00:00
|
|
|
getPhotos(entryId, site),
|
2019-11-13 23:00:29 +00:00
|
|
|
getChannelSite($, site),
|
2019-04-04 18:22:47 +00:00
|
|
|
]);
|
2019-04-04 02:00:28 +00:00
|
|
|
|
2019-11-13 23:00:29 +00:00
|
|
|
const scene = {
|
2019-04-04 02:00:28 +00:00
|
|
|
url,
|
2019-11-16 02:33:36 +00:00
|
|
|
entryId,
|
2019-04-04 02:00:28 +00:00
|
|
|
title,
|
|
|
|
date,
|
|
|
|
actors,
|
|
|
|
description,
|
|
|
|
duration,
|
|
|
|
tags,
|
2019-11-05 00:41:13 +00:00
|
|
|
poster,
|
|
|
|
photos,
|
|
|
|
trailer: {
|
|
|
|
src: trailer,
|
|
|
|
},
|
2019-04-04 02:00:28 +00:00
|
|
|
rating: {
|
|
|
|
likes,
|
|
|
|
},
|
|
|
|
site: channelSite || site,
|
|
|
|
};
|
2019-11-13 23:00:29 +00:00
|
|
|
|
|
|
|
return scene;
|
2019-04-04 02:00:28 +00:00
|
|
|
}
|
|
|
|
|
2019-04-05 01:45:40 +00:00
|
|
|
async function fetchLatest(site, page = 1) {
|
2019-11-13 23:00:29 +00:00
|
|
|
const { hostname } = new URL(site.url);
|
|
|
|
|
|
|
|
if (hostname.match('private.com')) {
|
|
|
|
const res = await bhttp.get(`${site.url}/${page}/`);
|
|
|
|
|
|
|
|
return scrapeLatest(res.body.toString(), site);
|
|
|
|
}
|
|
|
|
|
|
|
|
const res = await bhttp.get(`${site.url}/scenes/${page}/`);
|
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,
|
|
|
|
};
|