117 lines
2.7 KiB
JavaScript
Executable File
117 lines
2.7 KiB
JavaScript
Executable File
'use strict';
|
|
|
|
const qu = require('../utils/qu');
|
|
const http = require('../utils/http');
|
|
|
|
async function getTrailer(entryId, channel) {
|
|
const videoLinksRes = await http.post('https://pinkyxxx.com/wp-admin/admin-ajax.php', {
|
|
action: 'vidplay',
|
|
vid: entryId,
|
|
type: 'promo',
|
|
}, {
|
|
encodeJSON: false,
|
|
decodeJSON: true,
|
|
});
|
|
|
|
if (!videoLinksRes.ok || !videoLinksRes.body.size1) {
|
|
return null;
|
|
}
|
|
|
|
const scriptUrl = qu.extract(videoLinksRes.body.size1)?.query.url('script', 'src', { origin: channel.url });
|
|
const videoScriptRes = await http.get(scriptUrl);
|
|
|
|
if (!videoScriptRes.ok) {
|
|
return null;
|
|
}
|
|
|
|
const videoDataString = videoScriptRes.body.match(/"clip":({.*"})/)?.[1];
|
|
const videoData = videoDataString && JSON.parse(videoDataString);
|
|
|
|
const posterUrlString = videoScriptRes.body.match(/src="(.*poster.*?)"/)?.[1];
|
|
const posterUrlEl = videoScriptRes.document.createElement('span');
|
|
|
|
posterUrlEl.innerHTML = posterUrlString;
|
|
|
|
return {
|
|
trailer: videoData?.url || null,
|
|
poster: posterUrlEl.textContent || null,
|
|
};
|
|
}
|
|
|
|
function scrapeAll(scenes) {
|
|
return scenes.map((scene) => {
|
|
const release = {};
|
|
|
|
release.entryId = scene.ID;
|
|
release.url = scene.permalink;
|
|
|
|
release.title = scene.title;
|
|
release.description = scene.description;
|
|
|
|
release.date = qu.extractDate(scene.info?.post_date, 'YYYY-MM-DD HH:mm:ss') || qu.extractDate(scene.date, 'MMMM D, YYYY'); // eslint-disable-line camelcase
|
|
|
|
release.poster = scene.poster[0];
|
|
release.photos = Object.entries(scene).reduce((acc, [key, data]) => {
|
|
if (/thumb/.test(key)) {
|
|
return [...acc, data.url];
|
|
}
|
|
|
|
return acc;
|
|
}, []);
|
|
|
|
return release;
|
|
});
|
|
}
|
|
|
|
async function scrapeScene({ query }, channel, baseScene) {
|
|
const release = {};
|
|
|
|
release.title = query.cnt('.title');
|
|
release.description = query.cnt('.description');
|
|
|
|
release.entryId = query.q('body', 'class').match(/postid-(\d+)/)?.[1];
|
|
|
|
const { poster, trailer } = await getTrailer(release.entryId, channel) || {};
|
|
|
|
release.poster = baseScene?.poster || poster;
|
|
release.photos = poster && baseScene?.poster
|
|
? [poster, ...baseScene.photos]
|
|
: baseScene?.photos;
|
|
|
|
release.trailer = trailer;
|
|
|
|
return release;
|
|
}
|
|
|
|
async function fetchLatest(channel, page) {
|
|
const res = await http.post('https://pinkyxxx.com/wp-admin/admin-ajax.php', {
|
|
action: 'vls',
|
|
limit: 10,
|
|
offset: (page - 1) * 10,
|
|
}, {
|
|
encodeJSON: false,
|
|
decodeJSON: true,
|
|
});
|
|
|
|
if (res.ok) {
|
|
return scrapeAll(res.body.listings);
|
|
}
|
|
|
|
return res.status;
|
|
}
|
|
|
|
async function fetchScene(url, channel, baseScene) {
|
|
const res = await qu.get(url);
|
|
|
|
if (res.ok) {
|
|
return scrapeScene(res.item, channel, baseScene);
|
|
}
|
|
|
|
return res.status;
|
|
}
|
|
|
|
module.exports = {
|
|
fetchLatest,
|
|
fetchScene,
|
|
};
|