'use strict'; const qu = require('../utils/qu'); function scrapeLatest(items, channel) { return items.map(({ query }) => { const release = {}; release.url = query.url('h5 a', null, { origin: channel.url }); release.entryId = new URL(release.url).pathname.match(/\/(\d+)/)[1]; release.title = query.cnt('h5 a'); [release.poster, ...release.photos] = query.imgs('.screenshot').map(src => [ // unnecessarily large // src.replace(/\/\d+/, 3840), // src.replace(/\/\d+/, '/2000'), src.replace(/\/\d+/, '/1500'), src.replace(/\/\d+/, '/1000'), src, ]); return release; }); } function scrapeScene({ query, html }, url, channel) { const release = {}; release.entryId = new URL(url).pathname.match(/\/(\d+)/)[1]; release.title = query.cnt('h1.description'); release.actors = query .all('.video-performer') .map((actorEl) => { const actorUrl = query.url(actorEl, 'a', 'href', { origin: channel.url }); const entryId = new URL(url).pathname.match(/\/(\d+)/)?.[1]; const avatar = query.img(actorEl, 'img:not([data-bgsrc*="not-available"])', 'data-bgsrc'); return { name: query.cnt(actorEl, '.video-performer-name'), gender: 'female', avatar: avatar && [ avatar.replace(/\/actor\/(\d+)/, '/actor/500'), avatar, ], url: actorUrl, entryId, }; }) .concat({ name: 'Jay Rock', gender: 'male' }); release.date = query.date('.release-date:first-child', 'MMM DD, YYYY', /\w+ \d{1,2}, \d{4}/); release.duration = query.number('.release-date:last-child') * 60; release.studio = query.cnt('.studio span:nth-child(2)'); release.director = query.text('.director'); release.tags = query.cnts('.tags a'); const poster = html.match(/url\((https.+\.jpg)\)/)?.[1]; const photos = query.imgs('#moreScreenshots img'); [release.poster, ...release.photos] = [poster] .concat(photos) .filter(Boolean) .map(src => [ src.replace(/\/(\d+)\/\d+/, '/$1/1500'), src.replace(/\/(\d+)\/\d+/, '/$1/1000'), src, ]); const videoId = html.match(/item: (\d+)/)?.[1]; if (videoId) { release.trailer = { stream: `https://trailer.adultempire.com/hls/trailer/${videoId}/master.m3u8` }; } return release; } async function fetchLatest(channel, page = 1) { const res = await qu.getAll(`https://jayspov.net/jays-pov-updates.html?view=list&page=${page}`, '.item-grid-list-view > .grid-item'); if (res.ok) { return scrapeLatest(res.items, channel); } return res.status; } async function fetchScene(url, channel) { const res = await qu.get(url); if (res.ok) { return scrapeScene(res.item, url, channel); } return res.status; } module.exports = { fetchLatest, fetchScene, };