137 lines
3.4 KiB
JavaScript
137 lines
3.4 KiB
JavaScript
|
'use strict';
|
||
|
|
||
|
const qu = require('../utils/q');
|
||
|
const slugify = require('../utils/slugify');
|
||
|
|
||
|
function scrapeAll(scenes, channel) {
|
||
|
return scenes.map(({ query }) => {
|
||
|
const release = {};
|
||
|
|
||
|
release.url = query.url('.scene-update-details, .feature-update-details', 'href', { origin: channel.url });
|
||
|
release.entryId = new URL(release.url).pathname.match(/\/(\d+)/)[1];
|
||
|
|
||
|
release.title = query.q('.scene-img-wrapper img', 'alt').replace(/\s*image$/i, '');
|
||
|
|
||
|
release.date = query.date('.scene-update-stats span, .feature-update-details span', 'MMM DD, YYYY');
|
||
|
release.actors = query.cnt('.scene-update-details h3, .feature-update-details h2')?.split(/\s*\|\s*/).map(actor => actor.trim());
|
||
|
|
||
|
const poster = query.img('.scene-img-wrapper img');
|
||
|
release.poster = [
|
||
|
poster.replace(/\/res\/\d+/, '/res/1920'),
|
||
|
poster.replace(/\/res\/\d+/, '/res/1600'),
|
||
|
poster,
|
||
|
];
|
||
|
|
||
|
release.trailer = { src: query.video('.scene-img-wrapper source') };
|
||
|
|
||
|
return release;
|
||
|
});
|
||
|
}
|
||
|
|
||
|
async function scrapeScene({ query, html }, url) {
|
||
|
const release = {};
|
||
|
|
||
|
release.entryId = new URL(url).pathname.match(/\/(\d+)/)[1];
|
||
|
|
||
|
release.title = query.cnt('.scene-page .description');
|
||
|
release.date = query.date('.release-date:first-child', 'MMM DD, YYYY', /\w{3} \d{2}, \d{4}/);
|
||
|
release.duration = query.number('.release-date:last-child') * 60;
|
||
|
|
||
|
release.actors = query.all('.video-performer').map((el) => {
|
||
|
const avatar = qu.query.img(el, 'img', 'data-bgsrc');
|
||
|
|
||
|
return {
|
||
|
name: qu.query.cnt(el, 'span'),
|
||
|
avatar: [
|
||
|
avatar.replace(/\/actor\/\d+/, '/actor/1600'),
|
||
|
avatar,
|
||
|
],
|
||
|
};
|
||
|
});
|
||
|
|
||
|
release.tags = query.cnts('.tags a');
|
||
|
release.poster = query.url('link[rel="image_src"]') || query.meta('property="og:image"');
|
||
|
|
||
|
release.photos = query.imgs('#dv_frames a > img').map(photo => [
|
||
|
photo.replace(/(\/p\/\d+\/)\d+/, (match, path) => `${path}1920`),
|
||
|
photo.replace(/(\/p\/\d+\/)\d+/, (match, path) => `${path}1600`),
|
||
|
photo,
|
||
|
]);
|
||
|
|
||
|
const trailerId = html.match(/item: (\d+),/)?.[1];
|
||
|
|
||
|
if (trailerId) {
|
||
|
const trailerUrl = `https://www.adultempire.com/videoEmbed/${trailerId}?type=preview`;
|
||
|
const trailerRes = await qu.get(trailerUrl);
|
||
|
|
||
|
if (trailerRes.ok) {
|
||
|
const stream = trailerRes.item.query.video();
|
||
|
|
||
|
release.trailer = { stream };
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// console.log(release);
|
||
|
return release;
|
||
|
}
|
||
|
|
||
|
function scrapeProfile({ query, el }, actorName, entity, include) {
|
||
|
const profile = {};
|
||
|
|
||
|
profile.description = query.cnt('.bio-text');
|
||
|
profile.birthPlace = query.cnt('.birth-place span');
|
||
|
|
||
|
profile.avatar = query.img('.actor-photo img');
|
||
|
|
||
|
if (include.releases) {
|
||
|
return scrapeAll(qu.initAll(el, '.scene'));
|
||
|
}
|
||
|
|
||
|
console.log(profile);
|
||
|
return profile;
|
||
|
}
|
||
|
|
||
|
async function fetchLatest(channel, page = 1) {
|
||
|
const url = `${channel.url}/tour?page=${page}`;
|
||
|
const res = await qu.getAll(url, '.scene-update', null, {
|
||
|
// invalid certificate
|
||
|
rejectUnauthorized: false,
|
||
|
});
|
||
|
|
||
|
if (res.ok) {
|
||
|
return scrapeAll(res.items, channel);
|
||
|
}
|
||
|
|
||
|
return res.status;
|
||
|
}
|
||
|
|
||
|
async function fetchScene(url, channel) {
|
||
|
const res = await qu.get(url, null, null, {
|
||
|
// invalid certificate
|
||
|
rejectUnauthorized: false,
|
||
|
});
|
||
|
|
||
|
if (res.ok) {
|
||
|
return scrapeScene(res.item, url, channel);
|
||
|
}
|
||
|
|
||
|
return res.status;
|
||
|
}
|
||
|
|
||
|
async function fetchProfile(actorName, entity, include) {
|
||
|
const url = `${entity.url}/actors/${slugify(actorName, '_')}`;
|
||
|
const res = await qu.get(url);
|
||
|
|
||
|
if (res.ok) {
|
||
|
return scrapeProfile(res.item, actorName, entity, include);
|
||
|
}
|
||
|
|
||
|
return res.status;
|
||
|
}
|
||
|
|
||
|
module.exports = {
|
||
|
fetchLatest,
|
||
|
fetchScene,
|
||
|
fetchProfile,
|
||
|
};
|