121 lines
3.7 KiB
JavaScript
Executable File
121 lines
3.7 KiB
JavaScript
Executable File
'use strict';
|
|
|
|
const unprint = require('unprint');
|
|
|
|
const slugify = require('../utils/slugify');
|
|
const { convert } = require('../utils/convert');
|
|
const tryUrls = require('../utils/try-urls');
|
|
|
|
function scrapeAll(scenes, channel) {
|
|
return scenes.map(({ query }) => {
|
|
const release = {};
|
|
|
|
release.url = query.url('a');
|
|
release.entryId = slugify(new URL(release.url).pathname.match(/trailers\/(.*)/)[1]);
|
|
|
|
release.title = query.content('h2 a');
|
|
release.duration = query.duration('.video-data');
|
|
|
|
release.actors = query.all('a[href*="models/"], a[href*="sets.php"]').map((actorEl) => ({
|
|
name: unprint.query.content(actorEl),
|
|
url: unprint.query.url(actorEl, null, { origin: channel.url }),
|
|
}));
|
|
|
|
const poster = query.img('.thumbnail img');
|
|
const teaser = query.video('.thumbnail img', { attribute: 'data-vid' }); // not a mistake, video source is on img tag
|
|
|
|
if (!poster?.includes('blur')) { // seemingly global SFW
|
|
release.poster = poster;
|
|
}
|
|
|
|
if (!teaser?.includes('blur')) { // seemingly global SFW
|
|
release.teaser = teaser;
|
|
}
|
|
|
|
return release;
|
|
});
|
|
}
|
|
|
|
async function fetchLatest(channel, page = 1) {
|
|
const section = channel.pathname?.match(/\/channels\/([\w-]+)/)?.[1] || 'movies';
|
|
|
|
const url = `${channel.origin}/porn-categories/${section}/?page=${page}&sort=most-recent`; // parameter order matters for some reason!
|
|
const res = await unprint.get(url, { selectAll: '.content div[data-setid]' });
|
|
|
|
if (res.ok) {
|
|
return scrapeAll(res.context, channel);
|
|
}
|
|
|
|
return res.status;
|
|
}
|
|
|
|
function scrapeScene({ query }, { url, entity }) {
|
|
const release = {};
|
|
|
|
release.entryId = slugify(new URL(url).pathname.match(/trailers\/(.*)/)[1]);
|
|
|
|
release.title = query.content('h1.title_bar');
|
|
release.description = query.content('.description-text, #description');
|
|
|
|
release.date = query.date('//label[contains(text(), \'Date\')]/following-sibling::p[1]', 'YYYY-MM-DD')
|
|
|| query.date('//label[contains(text(), \'Date Added\')]/following-sibling::text()[1]', 'YYYY-MM-DD');
|
|
|
|
release.actors = query.all('#preview a[href*="/models"]').map((actorEl) => ({
|
|
name: unprint.query.content(actorEl),
|
|
url: unprint.query.url(actorEl, null, { origin: entity.origin }),
|
|
}));
|
|
|
|
release.tags = query.contents('#preview a[href*="categories/"]');
|
|
|
|
release.poster = query.poster('#preview video');
|
|
release.trailer = query.video('#preview video source');
|
|
|
|
return release;
|
|
}
|
|
|
|
function scrapeProfile({ query }, { url }) {
|
|
const profile = { url };
|
|
|
|
const bio = Object.fromEntries(query.all('.model-details > div').map((bioEl) => [
|
|
slugify(unprint.query.content(bioEl, 'h2'), '_'),
|
|
unprint.query.text(bioEl),
|
|
]));
|
|
|
|
profile.avatar = [
|
|
query.img('.model_bio_thumb', { attribute: 'src0_3x' }),
|
|
query.img('.model_bio_thumb', { attribute: 'src0_2x' }),
|
|
query.img('.model_bio_thumb', { attribute: 'src0_1x' }),
|
|
query.img('.model_bio_thumb'),
|
|
].filter(Boolean);
|
|
|
|
profile.description = [query.content('.model-bio-text, #performer-description'), bio.funfact].filter(Boolean).join(' ');
|
|
profile.aliases = bio.alias?.split(/[,\n]/).map((alias) => alias.trim());
|
|
|
|
profile.age = parseInt(bio.age, 10) || null;
|
|
profile.dateOfBirth = unprint.extractDate(bio.age, 'MM/DD/YYYY');
|
|
profile.measurements = bio.measurements;
|
|
profile.height = Number(bio.height?.match(/(\d+)\s*cm/)?.[1]) || convert(bio.height, 'cm');
|
|
|
|
return profile;
|
|
}
|
|
|
|
async function fetchProfile({ name: actorName, url: actorUrl }, { entity, include }) {
|
|
const { res, url } = await tryUrls([
|
|
actorUrl,
|
|
`${entity.url}/models/${slugify(actorName, '')}.html`,
|
|
`${entity.url}/models/${slugify(actorName, '-')}.html`,
|
|
]);
|
|
|
|
if (res.ok) {
|
|
return scrapeProfile(res.context, { entity, include, url });
|
|
}
|
|
|
|
return res.status;
|
|
}
|
|
|
|
module.exports = {
|
|
fetchLatest,
|
|
fetchProfile,
|
|
scrapeScene,
|
|
};
|