2019-04-07 03:01:06 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const bhttp = require('bhttp');
|
|
|
|
const cheerio = require('cheerio');
|
2019-11-30 04:55:32 +00:00
|
|
|
const { JSDOM } = require('jsdom');
|
2019-04-07 03:01:06 +00:00
|
|
|
const moment = require('moment');
|
|
|
|
|
2019-11-30 04:55:32 +00:00
|
|
|
const knex = require('../knex');
|
2019-04-07 03:01:06 +00:00
|
|
|
|
2019-04-07 03:19:44 +00:00
|
|
|
/* eslint-disable newline-per-chained-call */
|
2019-04-07 03:01:06 +00:00
|
|
|
function scrapeLatest(html, site) {
|
|
|
|
const $ = cheerio.load(html, { normalizeWhitespace: true });
|
|
|
|
const sceneElements = $('.card.m-1').toArray();
|
|
|
|
|
|
|
|
return sceneElements.map((element) => {
|
|
|
|
const sceneLinkElement = $(element).find('a').first();
|
|
|
|
const title = sceneLinkElement.attr('title');
|
|
|
|
const url = `${site.url}${sceneLinkElement.attr('href')}`;
|
|
|
|
const entryId = url.split('/').slice(-1)[0];
|
|
|
|
|
2019-10-30 03:45:42 +00:00
|
|
|
const date = moment.utc($(element).find('small[datetime]').attr('datetime'), 'YYYY-MM-DD HH:mm:ss').toDate();
|
|
|
|
const actors = $(element).find('.card-subtitle a').map((actorIndex, actorElement) => $(actorElement).text().trim())
|
|
|
|
.toArray()
|
|
|
|
.filter(actor => actor);
|
2019-04-07 03:01:06 +00:00
|
|
|
|
2019-10-30 03:45:42 +00:00
|
|
|
const duration = parseInt($(element).find('.card-info div:nth-child(2) .card-text').text(), 10) * 60;
|
|
|
|
|
|
|
|
const poster = sceneLinkElement.find('img').attr('data-src');
|
2019-04-07 03:01:06 +00:00
|
|
|
|
|
|
|
return {
|
|
|
|
url,
|
|
|
|
entryId,
|
|
|
|
title,
|
|
|
|
actors,
|
|
|
|
date,
|
|
|
|
duration,
|
2019-10-30 03:45:42 +00:00
|
|
|
poster,
|
2019-04-07 03:01:06 +00:00
|
|
|
rating: null,
|
|
|
|
site,
|
|
|
|
};
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async function scrapeScene(html, url, site) {
|
|
|
|
const $ = cheerio.load(html, { normalizeWhitespace: true });
|
|
|
|
|
|
|
|
const entryId = url.split('/').slice(-1)[0];
|
2019-10-30 03:45:42 +00:00
|
|
|
const title = $('meta[itemprop="name"]').attr('content');
|
|
|
|
const description = $('.descr-box p').text(); // meta tags don't contain full description
|
2019-04-07 03:01:06 +00:00
|
|
|
|
2019-12-09 04:00:49 +00:00
|
|
|
const dateProp = $('meta[itemprop="uploadDate"]').attr('content');
|
|
|
|
const date = dateProp
|
|
|
|
? moment.utc($('meta[itemprop="uploadDate"]').attr('content'), 'YYYY-MM-DD').toDate()
|
|
|
|
: moment.utc($('.title-border:nth-child(2) p').text(), 'MM.DD.YYYY').toDate();
|
2019-10-30 03:45:42 +00:00
|
|
|
const actors = $('.pornstar-card > a').map((actorIndex, actorElement) => $(actorElement).attr('title')).toArray();
|
2019-04-07 03:01:06 +00:00
|
|
|
|
|
|
|
const likes = Number($('.info-panel.likes .likes').text());
|
|
|
|
const duration = Number($('.info-panel.duration .duration').text().slice(0, -4)) * 60;
|
|
|
|
|
2019-12-09 04:00:49 +00:00
|
|
|
const tags = $('.tags-tab .tags a').map((tagIndex, tagElement) => $(tagElement).text()).toArray();
|
2019-10-30 03:45:42 +00:00
|
|
|
|
|
|
|
const poster = $('#video').attr('poster');
|
|
|
|
const photos = $('.photo-slider-guest .card a').map((photoIndex, photoElement) => $(photoElement).attr('href')).toArray();
|
|
|
|
|
|
|
|
const trailer540 = $('source[res="540"]').attr('src');
|
|
|
|
const trailer720 = $('source[res="720"]').attr('src');
|
|
|
|
|
2019-04-07 03:01:06 +00:00
|
|
|
return {
|
2019-10-30 03:45:42 +00:00
|
|
|
url,
|
2019-04-07 03:01:06 +00:00
|
|
|
entryId,
|
|
|
|
title,
|
2019-04-07 03:19:44 +00:00
|
|
|
description,
|
2019-04-07 03:01:06 +00:00
|
|
|
actors,
|
|
|
|
date,
|
|
|
|
duration,
|
|
|
|
tags,
|
2019-10-30 03:45:42 +00:00
|
|
|
poster,
|
|
|
|
photos,
|
2019-12-09 04:00:49 +00:00
|
|
|
trailer: [
|
|
|
|
{
|
2019-10-30 03:45:42 +00:00
|
|
|
src: trailer720,
|
|
|
|
quality: 720,
|
|
|
|
},
|
2019-12-09 04:00:49 +00:00
|
|
|
{
|
|
|
|
src: trailer540,
|
|
|
|
quality: 540,
|
|
|
|
},
|
|
|
|
],
|
2019-04-07 03:01:06 +00:00
|
|
|
rating: {
|
|
|
|
likes,
|
|
|
|
},
|
2019-10-30 03:45:42 +00:00
|
|
|
site,
|
2019-04-07 03:01:06 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-11-30 04:55:32 +00:00
|
|
|
async function scrapeProfile(html, _url, actorName) {
|
|
|
|
const { document } = new JSDOM(html).window;
|
|
|
|
|
|
|
|
const keys = Array.from(document.querySelectorAll('.about-title'), el => el.textContent.trim().replace(':', ''));
|
|
|
|
const values = Array.from(document.querySelectorAll('.about-info'), (el) => {
|
|
|
|
if (el.children.length > 0) {
|
|
|
|
return Array.from(el.children, child => child.textContent.trim()).join(', ');
|
|
|
|
}
|
|
|
|
|
|
|
|
return el.textContent.trim();
|
|
|
|
});
|
|
|
|
|
|
|
|
const bio = keys.reduce((acc, key, index) => {
|
|
|
|
if (values[index] === '-') {
|
|
|
|
return acc;
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
...acc,
|
|
|
|
[key]: values[index],
|
|
|
|
};
|
|
|
|
}, {});
|
|
|
|
|
|
|
|
const descriptionEl = document.querySelector('.description-box');
|
|
|
|
const avatarEl = document.querySelector('.pornstar-details .card-img-top');
|
|
|
|
|
|
|
|
const country = await knex('countries')
|
|
|
|
.where('nationality', 'ilike', `%${bio.Nationality}%`)
|
|
|
|
.orderBy('priority', 'desc')
|
|
|
|
.first();
|
|
|
|
|
|
|
|
const profile = {
|
|
|
|
name: actorName,
|
|
|
|
};
|
|
|
|
|
|
|
|
profile.birthdate = moment.utc(bio.Birthday, 'MMMM DD, YYYY').toDate();
|
|
|
|
if (country) profile.birthPlace = country.name;
|
|
|
|
|
|
|
|
if (bio['Bra size']) [profile.bust] = bio['Bra size'].match(/\d+\w+/);
|
|
|
|
if (bio.Waist) profile.waist = Number(bio.Waist.match(/\d+/)[0]);
|
|
|
|
if (bio.Hips) profile.hip = Number(bio.Hips.match(/\d+/)[0]);
|
|
|
|
|
|
|
|
if (bio.Height) profile.height = Number(bio.Height.match(/\d{2,}/)[0]);
|
|
|
|
|
|
|
|
if (bio['Tit Style'] && bio['Tit Style'].match('Enhanced')) profile.naturalBoobs = false;
|
|
|
|
if (bio['Tit Style'] && bio['Tit Style'].match('Natural')) profile.naturalBoobs = true;
|
|
|
|
|
|
|
|
if (bio['Body Art'] && bio['Body Art'].match('Tattoo')) profile.hasTattoos = true;
|
|
|
|
if (bio['Body Art'] && bio['Body Art'].match('Piercing')) profile.hasPiercings = true;
|
|
|
|
|
|
|
|
if (bio['Hair Style']) profile.hair = bio['Hair Style'].split(',')[0].trim().toLowerCase();
|
|
|
|
if (bio['Eye Color']) profile.eyes = bio['Eye Color'].match(/\w+/)[0].toLowerCase();
|
|
|
|
|
|
|
|
if (bio['Shoe size']) profile.shoes = Number(bio['Shoe size'].split('|')[1]);
|
|
|
|
|
|
|
|
if (descriptionEl) profile.description = descriptionEl.textContent.trim();
|
|
|
|
if (avatarEl) profile.avatar = `https:${avatarEl.dataset.src}`;
|
|
|
|
|
|
|
|
return profile;
|
|
|
|
}
|
|
|
|
|
2019-04-07 03:01:06 +00:00
|
|
|
async function fetchLatest(site, page = 1) {
|
|
|
|
const res = await bhttp.get(`https://ddfnetwork.com/videos/search/latest/ever/${new URL(site.url).hostname}/-/${page}`);
|
|
|
|
|
|
|
|
return scrapeLatest(res.body.toString(), site);
|
|
|
|
}
|
|
|
|
|
|
|
|
async function fetchScene(url, site) {
|
|
|
|
const res = await bhttp.get(`https://ddfnetwork.com${new URL(url).pathname}`);
|
|
|
|
|
|
|
|
return scrapeScene(res.body.toString(), url, site);
|
|
|
|
}
|
|
|
|
|
2019-11-30 04:55:32 +00:00
|
|
|
async function fetchProfile(actorName) {
|
|
|
|
const resSearch = await bhttp.post('https://ddfnetwork.com/search/ajax',
|
|
|
|
{
|
|
|
|
type: 'hints',
|
|
|
|
word: actorName,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
decodeJSON: true,
|
|
|
|
headers: {
|
|
|
|
'x-requested-with': 'XMLHttpRequest',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
if (resSearch.statusCode !== 200 || Array.isArray(resSearch.body.list)) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!resSearch.body.list.pornstarsName || resSearch.body.list.pornstarsName.length === 0) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
const [actor] = resSearch.body.list.pornstarsName;
|
|
|
|
const url = `https://ddfnetwork.com${actor.href}`;
|
|
|
|
|
|
|
|
const resActor = await bhttp.get(url);
|
|
|
|
|
|
|
|
if (resActor.statusCode !== 200) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return scrapeProfile(resActor.body.toString(), url, actorName);
|
|
|
|
}
|
|
|
|
|
2019-04-07 03:01:06 +00:00
|
|
|
module.exports = {
|
|
|
|
fetchLatest,
|
2019-11-30 04:55:32 +00:00
|
|
|
fetchProfile,
|
2019-04-07 03:01:06 +00:00
|
|
|
fetchScene,
|
|
|
|
};
|