2019-04-08 01:07:16 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
/* eslint-disable newline-per-chained-call */
|
|
|
|
const cheerio = require('cheerio');
|
|
|
|
const moment = require('moment');
|
|
|
|
|
2020-08-26 21:59:29 +00:00
|
|
|
const http = require('../utils/http');
|
2020-01-31 18:25:42 +00:00
|
|
|
const slugify = require('../utils/slugify');
|
2020-11-22 03:07:09 +00:00
|
|
|
const qu = require('../utils/q');
|
2020-01-31 18:25:42 +00:00
|
|
|
|
2019-04-08 01:07:16 +00:00
|
|
|
function titleExtractor(pathname) {
|
2020-05-14 02:26:05 +00:00
|
|
|
const components = pathname.split('/')[2].split('-');
|
|
|
|
const entryId = components.slice(-1)[0];
|
2019-04-08 01:07:16 +00:00
|
|
|
|
2020-05-14 02:26:05 +00:00
|
|
|
const title = components.slice(0, -1).reduce((accTitle, word, index) => `${accTitle}${index > 0 ? ' ' : ''}${word.slice(0, 1).toUpperCase()}${word.slice(1)}`, '');
|
2019-04-08 01:07:16 +00:00
|
|
|
|
2020-05-14 02:26:05 +00:00
|
|
|
return { title, entryId };
|
2019-04-08 01:07:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function scrapeLatest(html, site) {
|
2020-05-14 02:26:05 +00:00
|
|
|
const $ = cheerio.load(html, { normalizeWhitespace: true });
|
|
|
|
const sceneElements = $('.site-list .scene-item').toArray();
|
|
|
|
|
|
|
|
return sceneElements.map((item) => {
|
|
|
|
const element = $(item);
|
|
|
|
|
|
|
|
const sceneLinkElement = element.find('a').first();
|
|
|
|
const { protocol, hostname, pathname } = new URL(sceneLinkElement.attr('href'));
|
|
|
|
const url = `${protocol}//${hostname}${pathname}`;
|
|
|
|
const { title, entryId } = titleExtractor(pathname);
|
|
|
|
|
|
|
|
const date = moment.utc(element.find('.entry-date').text(), 'MMM D, YYYY').toDate();
|
|
|
|
const actors = element.find('.contain-actors a').map((actorIndex, actorElement) => $(actorElement).text()).toArray();
|
|
|
|
|
|
|
|
const duration = Number(element.find('.scene-runtime').text().slice(0, -4)) * 60;
|
|
|
|
|
|
|
|
const posterString = sceneLinkElement.find('img[data-srcset]').attr('data-srcset') || sceneLinkElement.find('img[data-src]').attr('data-src');
|
|
|
|
const poster = `https:${posterString.match(/[\w/.]+$/)[0]}`;
|
|
|
|
|
|
|
|
return {
|
|
|
|
url,
|
|
|
|
entryId,
|
|
|
|
title,
|
|
|
|
actors,
|
|
|
|
date,
|
|
|
|
duration,
|
|
|
|
poster,
|
|
|
|
rating: null,
|
|
|
|
site,
|
|
|
|
};
|
|
|
|
});
|
2019-04-08 01:07:16 +00:00
|
|
|
}
|
|
|
|
|
2020-01-31 18:25:42 +00:00
|
|
|
function scrapeScene(html, url, site) {
|
2020-05-14 02:26:05 +00:00
|
|
|
const $ = cheerio.load(html, { normalizeWhitespace: true });
|
|
|
|
const sceneElement = $('.scene-info');
|
|
|
|
|
|
|
|
const { protocol, hostname, pathname } = new URL(url);
|
|
|
|
const originalUrl = `${protocol}//${hostname}${pathname}`;
|
|
|
|
|
|
|
|
const entryId = originalUrl.split('-').slice(-1)[0];
|
2020-05-26 02:11:29 +00:00
|
|
|
const title = sceneElement.find('h1.scene-title').text();
|
2020-05-14 02:26:05 +00:00
|
|
|
const description = sceneElement.find('.synopsis').contents().slice(2).text().replace(/[\s\n]+/g, ' ').trim();
|
|
|
|
|
2020-05-26 02:11:29 +00:00
|
|
|
const date = moment.utc(sceneElement.find('span.entry-date').text()?.match(/\w+ \d{1,2}, \d{4}/), 'MMM D, YYYY').toDate();
|
|
|
|
const actors = $('.performer-list a, h1 a.scene-title').map((actorIndex, actorElement) => $(actorElement).text()).toArray();
|
2020-05-14 02:26:05 +00:00
|
|
|
|
|
|
|
const duration = Number(sceneElement.find('.duration-ratings .duration').text().slice(10, -4)) * 60;
|
|
|
|
|
2020-05-26 02:11:29 +00:00
|
|
|
const posterPath = $('video, dl8-video').attr('poster') || $('img.start-card').attr('src');
|
|
|
|
const poster = posterPath && `https:${posterPath}`;
|
2021-11-20 22:59:15 +00:00
|
|
|
const photos = $('.contain-scene-images.desktop-only a').map((index, el) => $(el).attr('href')).toArray().filter(Boolean).map((photo) => `https:${photo}`);
|
2020-05-14 02:26:05 +00:00
|
|
|
|
|
|
|
const trailerEl = $('source');
|
|
|
|
const trailerSrc = trailerEl.attr('src');
|
|
|
|
const trailerType = trailerEl.attr('type');
|
|
|
|
|
|
|
|
const siteName = sceneElement.find('a.site-title').text();
|
|
|
|
const channel = siteName.replace(/[\s']+/g, '').toLowerCase();
|
|
|
|
|
|
|
|
const tags = $('.categories a.cat-tag').map((tagIndex, tagElement) => $(tagElement).text()).toArray();
|
|
|
|
|
|
|
|
return {
|
|
|
|
url,
|
|
|
|
entryId,
|
|
|
|
title,
|
|
|
|
description,
|
|
|
|
actors,
|
|
|
|
date,
|
|
|
|
duration,
|
|
|
|
tags,
|
|
|
|
photos,
|
|
|
|
poster,
|
2020-05-26 02:11:29 +00:00
|
|
|
trailer: trailerSrc ? {
|
2020-05-14 02:26:05 +00:00
|
|
|
src: trailerSrc,
|
|
|
|
type: trailerType,
|
2020-05-26 02:11:29 +00:00
|
|
|
} : null,
|
2020-05-14 02:26:05 +00:00
|
|
|
rating: null,
|
|
|
|
site,
|
|
|
|
channel,
|
|
|
|
};
|
2019-04-08 01:07:16 +00:00
|
|
|
}
|
|
|
|
|
2020-02-03 23:18:53 +00:00
|
|
|
async function fetchActorReleases(url) {
|
2020-11-22 03:07:09 +00:00
|
|
|
const res = await qu.get(url);
|
2020-02-03 23:18:53 +00:00
|
|
|
|
2020-05-14 02:26:05 +00:00
|
|
|
return res.ok
|
2020-11-22 03:07:09 +00:00
|
|
|
? res.item.query.urls('.contain-block:not(.live-scenes) .scene-item > a:first-child') // live scenes repeat on all pages
|
2020-05-14 02:26:05 +00:00
|
|
|
: [];
|
2020-02-03 23:18:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
async function scrapeProfile(html) {
|
2020-11-22 03:07:09 +00:00
|
|
|
const { query } = qu.extract(html);
|
2020-05-14 02:26:05 +00:00
|
|
|
const profile = {};
|
2020-01-31 18:25:42 +00:00
|
|
|
|
2020-11-22 03:07:09 +00:00
|
|
|
profile.description = query.q('.bio_about_text', true);
|
2020-01-31 18:25:42 +00:00
|
|
|
|
2020-11-22 03:07:09 +00:00
|
|
|
const avatar = query.q('img.performer-pic', 'src');
|
2020-05-14 02:26:05 +00:00
|
|
|
if (avatar) profile.avatar = `https:${avatar}`;
|
2020-01-31 18:25:42 +00:00
|
|
|
|
2020-11-22 03:07:09 +00:00
|
|
|
const releases = query.urls('.scene-item > a:first-child');
|
|
|
|
const otherPages = query.urls('.pagination a:not([rel=next]):not([rel=prev])');
|
2021-11-20 22:59:15 +00:00
|
|
|
const olderReleases = await Promise.all(otherPages.map(async (page) => fetchActorReleases(page)));
|
2020-02-03 23:18:53 +00:00
|
|
|
|
2020-05-14 02:26:05 +00:00
|
|
|
profile.releases = releases.concat(olderReleases.flat());
|
2020-01-31 18:25:42 +00:00
|
|
|
|
2020-05-14 02:26:05 +00:00
|
|
|
return profile;
|
2020-01-31 18:25:42 +00:00
|
|
|
}
|
|
|
|
|
2019-04-08 01:07:16 +00:00
|
|
|
async function fetchLatest(site, page = 1) {
|
2020-08-26 21:59:29 +00:00
|
|
|
const res = await http.get(`${site.url}?page=${page}`);
|
2019-04-08 01:07:16 +00:00
|
|
|
|
2020-05-14 02:26:05 +00:00
|
|
|
return scrapeLatest(res.body.toString(), site);
|
2019-04-08 01:07:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
async function fetchScene(url, site) {
|
2020-08-26 21:59:29 +00:00
|
|
|
const res = await http.get(url);
|
2019-04-08 01:07:16 +00:00
|
|
|
|
2020-05-14 02:26:05 +00:00
|
|
|
return scrapeScene(res.body.toString(), url, site);
|
2019-04-08 01:07:16 +00:00
|
|
|
}
|
|
|
|
|
2020-07-20 23:44:51 +00:00
|
|
|
async function fetchProfile({ name: actorName }) {
|
2020-05-14 02:26:05 +00:00
|
|
|
const actorSlug = slugify(actorName);
|
2020-01-31 18:25:42 +00:00
|
|
|
|
2020-08-26 21:59:29 +00:00
|
|
|
const res = await http.get(`https://www.naughtyamerica.com/pornstar/${actorSlug}`);
|
2020-01-31 18:25:42 +00:00
|
|
|
|
2020-05-14 02:26:05 +00:00
|
|
|
if (res.statusCode === 200) {
|
|
|
|
return scrapeProfile(res.body.toString());
|
|
|
|
}
|
2020-01-31 18:25:42 +00:00
|
|
|
|
2020-05-14 02:26:05 +00:00
|
|
|
return null;
|
2020-01-31 18:25:42 +00:00
|
|
|
}
|
|
|
|
|
2019-04-08 01:07:16 +00:00
|
|
|
module.exports = {
|
2020-05-14 02:26:05 +00:00
|
|
|
fetchLatest,
|
|
|
|
fetchScene,
|
|
|
|
fetchProfile,
|
2019-04-08 01:07:16 +00:00
|
|
|
};
|