206 lines
6.1 KiB
JavaScript
Executable File
206 lines
6.1 KiB
JavaScript
Executable File
'use strict';
|
|
|
|
const unprint = require('unprint');
|
|
|
|
const slugify = require('../utils/slugify');
|
|
|
|
const headers = {
|
|
'Accept-Language': 'en-US,en', // will translate to server language if not specified
|
|
};
|
|
|
|
function scrapeAll(scenes) {
|
|
return scenes.map(({ query }) => {
|
|
const release = {};
|
|
|
|
release.url = query.url('h3 a');
|
|
release.entryId = new URL(release.url).pathname.split('/').at(-1);
|
|
|
|
release.title = query.content('h3 a')
|
|
|| query.attribute('a img', 'alt')?.split(/:(.*)/)[1]?.trim()
|
|
|| query.attribute('a img', 'alt');
|
|
|
|
release.date = query.date('.scene-date', ['MM/DD/YYYY', 'YYYY-MM-DD']);
|
|
|
|
release.actors = query.all('.scene-models a').map((actorEl) => ({
|
|
name: unprint.query.content(actorEl),
|
|
url: unprint.query.url(actorEl, null),
|
|
}));
|
|
|
|
release.poster = query.img('a img');
|
|
release.teaser = query.video('.mini_video_player source');
|
|
|
|
return release;
|
|
});
|
|
}
|
|
|
|
async function fetchLatest(site, page = 1) {
|
|
const { hostname } = new URL(site.url);
|
|
|
|
if (hostname.match('private.com')) {
|
|
const res = await unprint.get(`${site.url}/${page}/`, { selectAll: '.content-wrapper .scene', headers });
|
|
|
|
return scrapeAll(res.context, site);
|
|
}
|
|
|
|
const res = await unprint.get(`${site.url}/scenes/${page}/`, { selectAll: '.content-wrapper .scene', headers });
|
|
|
|
return scrapeAll(res.context, site);
|
|
}
|
|
|
|
async function getPhotos(entryId, site) {
|
|
const { hostname } = new URL(site.url);
|
|
|
|
const res = await unprint.get(`https://${hostname}/gallery.php?type=highres&id=${entryId}`);
|
|
|
|
if (res.ok) {
|
|
return res.context.query.urls('#lightgallery a.item');
|
|
}
|
|
|
|
return [];
|
|
}
|
|
|
|
async function scrapeScene({ query }, { url, entity }) {
|
|
const release = {};
|
|
|
|
release.entryId = new URL(url).pathname.split('/').at(-1);
|
|
release.channel = slugify(query.content('.title-site'), '');
|
|
|
|
release.title = query.content(['.title-zone h1', '.content-desc h1']);
|
|
release.description = query.content('meta[itemprop="description"]', { attribute: 'content' }) || query.content('#description-section');
|
|
|
|
release.date = query.date('meta[itemprop="uploadDate"]', 'YYYY-MM-DD', { attribute: 'content' });
|
|
release.duration = query.duration('meta[itemprop="duration"]', { attribute: 'content' });
|
|
|
|
release.actors = query.all('.title-zone .tag-models a, .scene-models-list a').map((actorEl) => ({
|
|
name: unprint.query.content(actorEl),
|
|
url: unprint.query.url(actorEl, null),
|
|
}));
|
|
|
|
release.tags = query.contents('.title-zone .tag-tags, .scene-tags a');
|
|
|
|
release.poster = query.img('meta[itemprop="thumbnailUrl"]', { attribute: 'content' }) || query.img('#trailer_player_finished img');
|
|
release.photos = await getPhotos(release.entryId, entity);
|
|
release.trailer = query.url('meta[itemprop="contentURL"]', { attribute: 'content' }) || query.video('#trailer_player source');
|
|
|
|
const movieUrl = query.url('.content-desc a[href*="movie/"]');
|
|
|
|
if (movieUrl) {
|
|
release.movie = {
|
|
url: movieUrl,
|
|
entryId: new URL(movieUrl).pathname.match(/movie\/(\d+)/)?.[1],
|
|
};
|
|
}
|
|
|
|
return release;
|
|
}
|
|
|
|
async function scrapeMovie({ query }, { url }) {
|
|
const release = {};
|
|
|
|
release.entryId = new URL(url).pathname.match(/movie\/(\d+)/)[1];
|
|
|
|
release.title = query.content('.dvds-wrapper h1');
|
|
release.description = query.content('meta[itemprop="description"]', { attribute: 'content' }) || query.content('p.sinopsys');
|
|
|
|
release.date = query.date('.date-duration [itemprop="datePublished"]', 'YYYY-MM-DD')
|
|
|| query.date('.date-duration em + span', 'DD/MM/YYYY')
|
|
|| query.date('meta[itemprop="uploadDate"]', 'YYYY-MM-DD', { attribute: 'content' }); // upload date does not match release date
|
|
|
|
release.duration = query.number('.date-duration', { match: /(\d+) min/, matchIndex: 1 }) * 60 || null;
|
|
|
|
release.actors = query.all('.dvd-performers a').map((actorEl) => ({
|
|
name: unprint.query.content(actorEl),
|
|
url: unprint.query.url(actorEl, null),
|
|
}));
|
|
|
|
release.poster = query.img('meta[itemprop="thumbnailUrl"]', { attribute: 'content' }) || query.img('#trailer_player_finished img');
|
|
release.covers = query.imgs('.dvds-picture img');
|
|
|
|
release.trailer = query.url('meta[itemprop="contentURL"]', { attribute: 'content' }) || query.video('#trailer_player source');
|
|
|
|
release.scenes = scrapeAll(unprint.initAll(query.all('.scenes .card')));
|
|
|
|
return release;
|
|
}
|
|
|
|
function scrapeProfile({ query }) {
|
|
const profile = {};
|
|
|
|
const bioKeys = query.contents('.bio-pornstar .model-facts:last-child em');
|
|
const bioValues = query.texts('.bio-pornstar .model-facts:last-child li');
|
|
|
|
const bio = Object.fromEntries(bioKeys.map((key, index) => [slugify(key, '_'), bioValues[index]]).filter(([, value]) => value !== '-'));
|
|
|
|
profile.description = query.content('.model-facts-long');
|
|
|
|
profile.birthPlace = bio.birth_place;
|
|
profile.nationality = bio.nationality;
|
|
|
|
profile.measurements = bio.measurements;
|
|
|
|
profile.height = Number(bio.height?.match(/(\d+)cm/)?.[1]) || null;
|
|
profile.weight = Number(bio.weight?.match(/(\d+)kg/i)?.[1]) || null;
|
|
|
|
profile.hairColor = bio.hair_color;
|
|
profile.eye = bio.eye_color;
|
|
|
|
if (bio.tattoos) {
|
|
profile.hasTattoos = true;
|
|
profile.tattoos = bio.tattoos;
|
|
}
|
|
|
|
if (bio.tattoos) {
|
|
profile.hasTattoos = true;
|
|
profile.tattoos = bio.tattoos;
|
|
}
|
|
|
|
if (bio.piercings) {
|
|
profile.hasPiercings = true;
|
|
profile.piercings = bio.piercings;
|
|
}
|
|
|
|
profile.avatar = query.img('meta[property="og:image"]', { attribute: 'content' }); // other images are not suitable as avatar
|
|
|
|
// profile.releases = scrapeAll(unprint.initAll(query.all('.scenes .card'))); // works for good measure, but no longer in use
|
|
|
|
return profile;
|
|
}
|
|
|
|
async function searchProfile(actorName) {
|
|
const actorSearchSlug = slugify(actorName, '+');
|
|
const url = `https://www.private.com/search.php?query=${actorSearchSlug}`;
|
|
|
|
const res = await unprint.get(url, { headers });
|
|
|
|
return res.context.query.url(`.model a[title="${actorName}"]`);
|
|
}
|
|
|
|
async function fetchProfile({ name: actorName, url }) {
|
|
const actorUrl = url || await searchProfile(actorName);
|
|
|
|
if (!actorUrl) {
|
|
return null;
|
|
}
|
|
|
|
const res = await unprint.get(actorUrl, { headers });
|
|
|
|
if (res.ok) {
|
|
return scrapeProfile(res.context);
|
|
}
|
|
|
|
return res.status;
|
|
}
|
|
|
|
module.exports = {
|
|
fetchLatest,
|
|
fetchProfile,
|
|
scrapeScene: {
|
|
scraper: scrapeScene,
|
|
headers,
|
|
},
|
|
scrapeMovie: {
|
|
scraper: scrapeMovie,
|
|
headers,
|
|
},
|
|
};
|