'use strict'; const util = require('util'); const { get, geta, fd } = require('../utils/q'); const slugify = require('../utils/slugify'); function extractPoster(posterPath, site, baseRelease) { if (posterPath && !/400.jpg/.test(posterPath)) { const poster = `${site.parameters?.media || site.url}${posterPath}`; const posterSources = [ poster, // upscaled poster.replace('-1x', '-2x'), poster.replace('-1x', '-3x'), ]; if (baseRelease?.poster) { return [posterSources, [baseRelease.poster]]; } return [posterSources, []]; } return [null, []]; } function scrapeLatest(scenes, site) { return scenes.map(({ q, qu, qd, ql }) => { const release = {}; release.entryId = q('.modelimg img', 'id').match(/set-target-(\d+)/)[1]; release.title = q('h3 a', 'title') || q('h3 a', true); release.url = qu('h3 a'); release.date = qd('.modeldata p', 'YYYY-MM-DD', /\d{4}-\d{2}-\d{2}/); release.duration = ql('.modeldata p'); if (/bts|behind the scenes/i.test(release.title)) release.tags = ['behind-the-scenes']; release.poster = [ q('.modelimg img', 'src0_3x'), q('.modelimg img', 'src0_2x'), q('.modelimg img', 'src0_1x'), ].filter(Boolean).map(src => `${site.parameters?.media || site.url}${src}`); return release; }); } function scrapeLatestT1(scenes, site) { return scenes.map(({ q, qi, qd, ql, qu }) => { const release = {}; release.title = q('h4 a', 'title') || q('h4 a', true); release.url = qu('h4 a'); release.date = qd('.more-info-div', 'MMM D, YYYY'); release.duration = ql('.more-info-div'); release.entryId = q('.img-div img', 'id')?.match(/set-target-(\d+)/)[1] || `${slugify(fd(release.date, 'YYYY-MM-DD'))}-${slugify(release.title)}`; const posterPath = q('.img-div img', 'src0_1x') || qi('img.video_placeholder'); if (posterPath) { const poster = /^http/.test(posterPath) ? posterPath : `${site.parameters?.media || site.url}${posterPath}`; release.poster = [ poster.replace('-1x', '-3x'), poster.replace('-1x', '-2x'), poster, ]; } return release; }); } function scrapeScene({ html, q, qa, qd, ql }, site, url, baseRelease) { const release = { url }; release.entryId = html.match(/set-target-(\d+)/)[1]; release.title = q('.centerwrap h2', true); release.description = q('.videocontent p', true); release.date = qd('.videodetails .date', 'MM/DD/YYYY'); release.duration = ql('.videodetails .date'); release.actors = qa('.modelname a', true); const posterPath = html.match(/poster="([\w-/.]+)"/)?.[1]; [release.poster, release.photos] = extractPoster(posterPath, site, baseRelease); const trailerPath = html.match(/\/trailers\/.*.mp4/); if (trailerPath) release.trailer = { src: `${site.parameters?.media || site.url}${trailerPath}` }; const stars = q('.modelrates + p', true).match(/\d.\d/)?.[0]; if (stars) release.stars = Number(stars); return release; } function scrapeSceneT1({ html, q, qa, qd, ql, qtx }, site, url, baseRelease) { const release = { url }; release.title = q('.trailer-section-head .section-title', true); release.description = qtx('.row .update-info-block'); release.date = qd('.update-info-row', 'MMM D, YYYY', /\w+ \d{1,2}, \d{4}/); release.duration = ql('.update-info-row:nth-child(2)'); release.entryId = q('.player-thumb img', 'id').match(/set-target-(\d+)/)[1] || `${slugify(fd(release.date, 'YYYY-MM-DD'))}-${slugify(release.title)}`; release.actors = qa('.models-list-thumbs a').map(el => ({ name: q(el, 'span', true), avatar: [ q(el, 'img', 'src0_3x'), q(el, 'img', 'src0_2x'), q(el, 'img', 'src0_1x'), ].filter(Boolean).map(src => `${site.parameters?.media || site.url}${src}`), })); release.tags = qa('.tags a', true); // const posterPath = html.match(/poster="(.*\.jpg)/)?.[1]; const posterPath = q('.player-thumb img', 'src0_1x'); [release.poster, release.photos] = extractPoster(posterPath, site, baseRelease); const trailer = html.match(/ /Shot Her First|WhiteZilla|Frat House Fuck Fest|Freaky First Timers|MILF Invaders|Housewives Need Cash|Bubble Butt Bonanza|Suburban Sex Party|Butt Naked In Streets/i.test(tag)); if (channel) { release.channel = { force: true, slug: slugify(channel, { delimiter: '' }), }; } } return release; } async function fetchLatest(site, page = 1) { const url = (site.parameters?.latest && util.format(site.parameters.latest, page)) || (site.parameters?.t1 && `${site.url}/t1/categories/movies_${page}_d.html`) || `${site.url}/categories/movies_${page}_d.html`; const qLatest = await geta(url, '.modelfeature, .item-video'); if (!qLatest) return null; return site.parameters?.t1 ? scrapeLatestT1(qLatest, site) : scrapeLatest(qLatest, site); } async function fetchScene(url, site, baseRelease) { const qScene = await get(url); if (!qScene) return null; return site.parameters?.t1 ? scrapeSceneT1(qScene, site, url, baseRelease) : scrapeScene(qScene, site, url, baseRelease); } module.exports = { // preflight, fetchLatest, fetchScene, };