'use strict'; const unprint = require('unprint'); const slugify = require('../utils/slugify'); function scrapeProfile({ query }) { const profile = {}; const bio = query.all('.infobox tr[valign="top"]') .map((detail) => unprint.query.contents(detail, 'td')) .reduce((acc, [key, value]) => ({ ...acc, [slugify(key, '_')]: value }), {}); /* unreliable, see: Syren De Mer const catlinks = qa('#mw-normal-catlinks a', true); const isTrans = catlinks.some(link => link.match(/shemale|transgender/i)); profile.gender = isTrans ? 'transsexual' : 'female'; */ profile.dateOfBirth = query.date('.bday', 'YYYY-MM-DD'); profile.description = query.content('.mw-parser-output > p'); profile.placeOfBirth = bio.born; profile.ethnicity = bio.ethnicity; profile.nationality = bio.nationality.split(',')[0]; profile.measurements = bio.measurements; if (bio.bra_cup_size) { [profile.bust] = bio.bra_cup_size.match(/^\d+\w+/) || []; } if (/enhanced/i.test(bio.boobs)) profile.naturalBoobs = false; if (/natural/i.test(bio.boobs)) profile.naturalBoobs = true; if (bio.height) profile.height = Number(bio.height.match(/\d+\.\d+/g).slice(-1)[0]) * 100; if (bio.weight) profile.weight = Number(bio.weight.match(/\d+/g)[1]); if (bio.eye_color) profile.eyes = bio.eye_color; if (bio.hair) [profile.hairColor] = bio.hair.split(/(?=[A-Z])/); // field concatted to BrunetteLong if (bio.blood_group) profile.blood = bio.blood_group; if (bio.also_known_as) profile.aliases = bio.also_known_as.split(', '); const avatarThumbPath = query.img('.infobox .mw-file-description img'); if (avatarThumbPath && !/NoImageAvailable/.test(avatarThumbPath)) { const avatarPath = avatarThumbPath.slice(0, avatarThumbPath.lastIndexOf('/')).replace('thumb/', ''); profile.avatar = unprint.prefixUrl(avatarPath, 'https://www.boobpedia.com'); } profile.socials = query.urls('.infobox a.external'); return profile; } async function fetchProfile({ name: actorName }) { const actorSlug = slugify(actorName, '_', { lower: false }); const res = await unprint.get(`https://www.boobpedia.com/boobs/${actorSlug}`); if (res.ok) { return scrapeProfile(res.context); } return null; } module.exports = { fetchProfile, };