Added Fantasy Massage sites. Improved Private scraper, added movie link.

This commit is contained in:
2020-02-08 04:52:32 +01:00
parent ff8ab2fe09
commit d2cb74a252
5 changed files with 143 additions and 95 deletions

View File

@@ -11,6 +11,16 @@ const logger = require('../logger')(__filename);
const { ex, get } = require('../utils/q');
const slugify = require('../utils/slugify');
function getAlbumUrl(albumPath, site) {
if (site.parameters?.photos) {
return /^http/.test(site.parameters.photos)
? `${site.parameters.photos}${albumPath.split('/').slice(-2).join('/')}`
: `${site.url}${site.parameters.photos}${albumPath.split('/').slice(-2).join('/')}`;
}
return `${site.url}${albumPath}`;
}
async function fetchPhotos(url) {
const res = await bhttp.get(url);
@@ -25,7 +35,7 @@ function scrapePhotos(html) {
if (/\/join|\/createaccount/.test(url)) {
// URL links to join page instead of full photo, extract thumbnail
// /createaccount is used by e.g. Tricky Spa
// /createaccount is used by e.g. Tricky Spa native site
const src = $(linkEl).find('img').attr('src');
if (src.match('previews/')) {
@@ -47,9 +57,9 @@ function scrapePhotos(html) {
}
async function getPhotos(albumPath, site) {
const albumUrl = site.parameters?.photos
? `${site.url}${site.parameters.photos}${albumPath.split('/').slice(-2).join('/')}`
: `${site.url}${albumPath}`;
const albumUrl = getAlbumUrl(albumPath, site);
console.log(albumUrl);
try {
const html = await fetchPhotos(albumUrl);
@@ -397,28 +407,63 @@ async function fetchApiUpcoming(site) {
return fetchApiLatest(site, 1, true);
}
function getLatestUrl(site, page) {
if (site.parameters?.latest) {
return /^http/.test(site.parameters.latest)
? `${site.parameters.latest}${page}`
: `${site.url}${site.parameters.latest}${page}`;
}
return `${site.url}/en/videos/AllCategories/0/${page}`;
}
function getUpcomingUrl(site) {
if (site.parameters?.upcoming) {
return /^http/.test(site.parameters.upcoming)
? `${site.parameters.upcoming}`
: `${site.url}${site.parameters.upcoming}`;
}
return `${site.url}/en/videos/AllCategories/0/1/upcoming`;
}
async function fetchLatest(site, page = 1) {
const url = `${site.url}${site.parameters?.latest || '/en/videos/AllCategories/0/'}${page}`;
const url = getLatestUrl(site, page);
const res = await bhttp.get(url);
return scrapeAll(res.body.toString(), site);
}
async function fetchUpcoming(site) {
const url = `${site.url}${site.parameters?.upcoming || '/en/videos/AllCategories/0/1/upcoming'}`;
const url = getUpcomingUrl(site);
const res = await bhttp.get(url);
return scrapeAll(res.body.toString(), site);
}
function getDeepUrl(url, site) {
const { pathname } = new URL(url);
if (site.parameters?.deep === 'network') {
return `${site.network.url}${pathname}`;
}
if (site.parameters?.deep) {
return `${site.parameters.deep}${pathname}`;
}
return url;
}
async function fetchScene(url, site, release) {
if (site.parameters?.deep === false) {
return release;
}
const res = await bhttp.get(url);
const deepUrl = getDeepUrl(url, site);
const res = await bhttp.get(deepUrl);
return scrapeScene(res.body.toString(), url, site);
return scrapeScene(res.body.toString(), url, site, deepUrl);
}
async function fetchActorScenes(actorName, apiUrl, siteSlug) {

View File

@@ -5,9 +5,6 @@ const bhttp = require('bhttp');
const cheerio = require('cheerio');
const moment = require('moment');
const fetchSites = require('../sites');
const { matchTags } = require('../tags');
async function getPhotos(entryId, site) {
const { hostname } = new URL(site.url);
@@ -20,27 +17,6 @@ async function getPhotos(entryId, site) {
return photos;
}
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;
}
function scrapeLatest(html, site) {
const $ = cheerio.load(html, { normalizeWhitespace: true });
const sceneElements = $('.content-wrapper .scene').toArray();
@@ -82,55 +58,40 @@ function scrapeLatest(html, site) {
async function scrapeScene(html, url, site) {
const $ = cheerio.load(html, { normalizeWhitespace: true });
const release = {};
const entryId = url.split('/').slice(-1)[0];
const title = $('.video-wrapper meta[itemprop="name"]').attr('content');
[release.entryId] = url.split('/').slice(-1);
release.title = $('.video-wrapper meta[itemprop="name"]').attr('content');
release.description = $('.video-wrapper meta[itemprop="description"]').attr('content');
const date = moment.utc($('.video-wrapper meta[itemprop="uploadDate"]').attr('content'), 'MM/DD/YYYY').toDate();
const actors = $('.content-wrapper .scene-models-list a').map((actorIndex, actorElement) => $(actorElement).text()).toArray();
release.date = moment.utc($('.video-wrapper meta[itemprop="uploadDate"]').attr('content'), 'MM/DD/YYYY').toDate();
release.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);
const timestamp = $('.video-wrapper meta[itemprop="duration"]').attr('content');
if (timestamp) {
const [minutes, seconds] = timestamp.match(/\d+/g);
release.duration = Number(minutes) * 60 + Number(seconds);
}
release.tags = $('.content-desc .scene-tags a').map((tagIndex, tagElement) => $(tagElement).text()).toArray();
release.likes = Number($('.content-desc #social-actions #likes').text());
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;
release.poster = $('meta[property="og:image"]').attr('content') || posterLink;
const trailerElementSrc = $('#videojs-trailer source').attr('src');
const trailer = $('meta[property="og:video"]').attr('content') || trailerElementSrc;
const likes = Number($('.content-desc #social-actions #likes').text());
const rawTags = $('.content-desc .scene-tags a').map((tagIndex, tagElement) => $(tagElement).text()).toArray();
const [tags, photos, channelSite] = await Promise.all([
matchTags(rawTags),
getPhotos(entryId, site),
getChannelSite($, site),
]);
const scene = {
url,
entryId,
title,
date,
actors,
description,
duration,
tags,
poster,
photos,
trailer: {
src: trailer,
},
rating: {
likes,
},
site: channelSite || site,
release.trailer = {
src: $('meta[property="og:video"]').attr('content') || $('#videojs-trailer source').attr('src'),
};
return scene;
release.photos = await getPhotos(release.entryId, site);
release.movie = $('a[data-track="FULL MOVIE"]').attr('href');
const siteElement = $('.content-wrapper .logos-sites a');
if (siteElement) release.channel = siteElement.text().replace(/\s+/g, '').toLowerCase();
return release;
}
async function fetchLatest(site, page = 1) {