2020-03-29 21:42:41 +00:00
|
|
|
'use strict';
|
|
|
|
|
2020-10-29 14:20:59 +00:00
|
|
|
const { get, initAll, formatDate } = require('../utils/qu');
|
2020-03-29 21:42:41 +00:00
|
|
|
|
|
|
|
function scrapeLatest(scenes, dates, site) {
|
2020-05-14 02:26:05 +00:00
|
|
|
return scenes.map(({ qu }, index) => {
|
|
|
|
const release = {};
|
2020-10-29 14:20:59 +00:00
|
|
|
const path = qu.url('a[href*="videos/"]');
|
2020-03-29 21:42:41 +00:00
|
|
|
|
2020-10-29 14:20:59 +00:00
|
|
|
if (path) {
|
|
|
|
release.url = `${site.url}/visitors/${path}`;
|
|
|
|
}
|
2020-03-29 21:42:41 +00:00
|
|
|
|
2020-05-14 02:26:05 +00:00
|
|
|
if (dates && dates[index]) {
|
|
|
|
release.date = dates[index].qu.date(null, 'MM/DD/YYYY');
|
|
|
|
}
|
2020-03-29 21:42:41 +00:00
|
|
|
|
2020-10-29 14:20:59 +00:00
|
|
|
const entryId = path?.match(/videos\/([a-zA-Z0-9]+)(?:_hd)?_trailer/)?.[1]
|
|
|
|
|| qu.img('img[src*="graphics/fft"]')?.match(/fft_(\w+).gif/)?.[1];
|
|
|
|
|
|
|
|
if (!entryId) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
release.entryId = release.date ? `${formatDate(release.date, 'YYYY-MM-DD')}-${entryId}` : entryId;
|
2020-05-14 02:26:05 +00:00
|
|
|
release.description = qu.q('tbody tr:nth-child(3) font', true);
|
2020-03-29 21:42:41 +00:00
|
|
|
|
2020-05-14 02:26:05 +00:00
|
|
|
const infoLine = qu.q('font[color="#663366"]', true);
|
2020-10-29 14:20:59 +00:00
|
|
|
|
|
|
|
if (infoLine) {
|
|
|
|
release.duration = Number(infoLine.match(/(\d+) min/i)?.[1] || infoLine.match(/video: (\d+)/i)?.[1]) * 60 || null;
|
|
|
|
}
|
2020-03-29 21:42:41 +00:00
|
|
|
|
2020-05-14 02:26:05 +00:00
|
|
|
const poster = qu.img('img[src*="photos/"][width="400"]');
|
|
|
|
release.poster = `${site.url}/visitors/${poster}`;
|
|
|
|
release.photos = qu.imgs('img[src*="photos/"]:not([width="400"])').map(source => `${site.url}/visitors/${source}`);
|
2020-03-29 21:42:41 +00:00
|
|
|
|
2020-05-14 02:26:05 +00:00
|
|
|
return release;
|
|
|
|
});
|
2020-03-29 21:42:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function scrapeScene({ qu }, url, site) {
|
2020-05-14 02:26:05 +00:00
|
|
|
const release = { url };
|
2020-03-29 21:42:41 +00:00
|
|
|
|
2020-05-14 02:26:05 +00:00
|
|
|
const { pathname } = new URL(url);
|
|
|
|
release.entryId = pathname.match(/videos\/(\w+)_hd_trailer/)[1];
|
2020-03-29 21:42:41 +00:00
|
|
|
|
2020-05-14 02:26:05 +00:00
|
|
|
const actor = qu.q('font[color="#990033"] strong', true);
|
|
|
|
release.actors = [actor];
|
2020-03-29 21:42:41 +00:00
|
|
|
|
2020-05-14 02:26:05 +00:00
|
|
|
const hdTrailer = qu.url('a[href*="hd_trailer.mp4"]');
|
|
|
|
const sdTrailer = qu.url('a[href*="hd_trailer_mobile.mp4"]');
|
2020-03-29 21:42:41 +00:00
|
|
|
|
2020-05-14 02:26:05 +00:00
|
|
|
release.trailer = [
|
|
|
|
{
|
|
|
|
src: `${site.url}/visitors/videos/${hdTrailer}`,
|
|
|
|
quality: 1080,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
src: `${site.url}/visitors/videos/${sdTrailer}`,
|
|
|
|
quality: 270,
|
|
|
|
},
|
|
|
|
];
|
2020-03-29 21:42:41 +00:00
|
|
|
|
2020-05-14 02:26:05 +00:00
|
|
|
return release;
|
2020-03-29 21:42:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
async function fetchLatest(site, page = 1) {
|
2020-05-14 02:26:05 +00:00
|
|
|
const url = `https://jesseloadsmonsterfacials.com/visitors/tour_${page.toString().padStart(2, '0')}.html`;
|
|
|
|
const res = await get(url);
|
2020-03-29 21:42:41 +00:00
|
|
|
|
2020-05-14 02:26:05 +00:00
|
|
|
if (!res.ok) {
|
|
|
|
return res.status;
|
|
|
|
}
|
2020-03-29 21:42:41 +00:00
|
|
|
|
2020-05-14 02:26:05 +00:00
|
|
|
const { el } = res.item;
|
2020-03-29 21:42:41 +00:00
|
|
|
|
2020-05-14 02:26:05 +00:00
|
|
|
const scenes = initAll(el, 'table[width="880"]');
|
|
|
|
const dates = initAll(el, 'font[color="#000000"] strong:not(:empty)');
|
2020-03-29 21:42:41 +00:00
|
|
|
|
2020-05-14 02:26:05 +00:00
|
|
|
return scrapeLatest(scenes, dates, site);
|
2020-03-29 21:42:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
async function fetchScene(url, site) {
|
2020-05-14 02:26:05 +00:00
|
|
|
const res = await get(url);
|
2020-03-29 21:42:41 +00:00
|
|
|
|
2020-05-14 02:26:05 +00:00
|
|
|
if (res.ok) {
|
|
|
|
return scrapeScene(res.item, url, site);
|
|
|
|
}
|
2020-03-29 21:42:41 +00:00
|
|
|
|
2020-05-14 02:26:05 +00:00
|
|
|
return res.status;
|
2020-03-29 21:42:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
2020-05-14 02:26:05 +00:00
|
|
|
fetchLatest,
|
|
|
|
fetchScene,
|
2020-03-29 21:42:41 +00:00
|
|
|
};
|