'use strict'; const { decode } = require('html-entities'); const qu = require('../utils/qu'); 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.entryId = query.number(null, /\d+/, 'onclick'); release.url = query.url(null, 'href', { origin: 'https://www.cumlouder.com' }); release.date = date; release.datePrecision = precision; release.title = query.cnt('h2'); release.duration = query.duration('.minutos'); release.poster = [ poster.replace(/\/(\w+)\.jpg/, '/previewhd.jpg'), poster, ]; return release; }); } function scrapeScene({ query }, channel, html) { const release = {}; const { date, precision } = query.dateAgo('.sub-video .added'); release.entryId = html.match(/cumlouder_(\d+)/)?.[1]; release.title = query.cnt('.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: query.cnt(el, null), url: query.url(el, null, 'href', { origin: 'https://www.cumlouder.com' }), })); release.duration = query.duration('.video-top .duracion'); release.tags = query.cnts('.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; } function scrapeProfile({ query, el }, channel) { const profile = {}; const bio = query.all('.data-bio li').reduce((acc, bioEl) => ({ ...acc, [slugify(query.cnt(bioEl, 'strong'), '_')]: query.text(bioEl), }), {}); profile.nationality = bio.nationality; profile.dateOfBirth = qu.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.cnt('.data-bio p:last-of-type'); profile.avatar = query.img('.thumb-bio'); profile.scenes = scrapeAll(qu.initAll(el, '.muestra-escena'), channel); return profile; } async function fetchLatest(channel, page) { const res = await qu.getAll(`${channel.url}/${page}/`, '.muestra-escena'); if (res.ok) { return scrapeAll(res.items, channel); } return res.status; } async function fetchScene(url, channel) { const res = await qu.get(url); if (res.ok) { return scrapeScene(res.item, channel, res.html); } return res.status; } async function fetchProfile(actor, channel) { const res = await qu.get(`https://www.cumlouder.com/girl/${actor.slug}/`, '.listado-escenas'); if (res.ok) { return scrapeProfile(res.item, channel); } return res.status; } module.exports = { fetchLatest, fetchScene, fetchProfile, };