'use strict'; const unprint = require('unprint'); const { decode } = require('html-entities'); const slugify = require('../utils/slugify'); function scrapeAll(items, _channel) { return items.map(({ query }) => { const release = {}; const { date, precision } = query.dateAgo('.fecha'); const poster = query.img('.thumb'); release.url = query.url(null, { origin: 'https://www.cumlouder.com' }); release.entryId = new URL(release.url).pathname.match(/video\/([\w-]+)/)?.[1]; release.date = date; release.datePrecision = precision; release.title = query.content('h2'); release.duration = query.duration('.minutos'); release.poster = [ poster.replace(/\/(\w+)\.jpg/, '/previewhd.jpg'), poster, ]; return release; }); } async function fetchLatest(channel, page) { const res = await unprint.get(`${channel.url}/${page}/`, { selectAll: '.muestra-escena' }); if (res.ok) { return scrapeAll(res.context, channel); } return res.status; } function scrapeScene({ query, html }, url) { const release = {}; const { date, precision } = query.dateAgo('.sub-video .added'); release.entryId = new URL(url).pathname.match(/video\/([\w-]+)/)?.[1]; release.title = query.content('.video-top h1'); release.description = query.text('.sub-video p'); release.date = date; release.datePrecision = precision; release.actors = query.all('.sub-video .pornstar-link').map((el) => ({ name: unprint.query.content(el, null), url: unprint.query.url(el, null, { origin: 'https://www.cumlouder.com' }), })); release.duration = query.duration('.video-top .duracion'); release.tags = query.contents('.video-top .tag-link'); release.poster = query.poster() || html.match(/urlImg\s*=\s*'(.*)';/)?.[1]; release.video = query.video() || decode(html.match(/urlVideo\s*=\s*'(.*)';/)?.[1]); // no trailers but full-length videos release.shootId = release.poster?.match(/\/rc(\d+)/)?.[1] || release.video?.match(/\/episodio_(\d+)/)?.[1]; return release; } async function fetchScene(url, channel) { const res = await unprint.get(url); if (res.ok) { return scrapeScene(res.context, url, channel); } return res.status; } function scrapeProfile({ query }, channel) { const profile = {}; const bio = query.all('.data-bio li').reduce((acc, bioEl) => ({ ...acc, [slugify(unprint.query.content(bioEl, 'strong'), '_')]: unprint.query.text(bioEl), }), {}); profile.nationality = bio.nationality; profile.dateOfBirth = unprint.extractDate(bio.date_of_birth, 'DD-MM-YYYY'); profile.height = Number(bio.height) * 100; profile.weight = parseInt(bio.weight, 10); profile.eyes = bio.eye_color; profile.hairColor = bio.hair_color; profile.description = query.content('.data-bio p:last-of-type'); profile.avatar = query.img('.thumb-bio'); profile.socials = query.urls('a.twitter-timeline'); profile.scenes = scrapeAll(unprint.initAll(query.all('.muestra-escena')), channel); return profile; } async function fetchProfile(actor, channel) { const res = await unprint.get(`https://www.cumlouder.com/girl/${actor.slug}/`, { select: '.listado-escenas' }); if (res.ok) { return scrapeProfile(res.context, channel); } return res.status; } module.exports = { fetchLatest, fetchScene, fetchProfile, };