2019-04-06 21:24:26 +00:00
|
|
|
'use strict';
|
|
|
|
|
2019-04-07 03:19:44 +00:00
|
|
|
/* eslint-disable newline-per-chained-call */
|
2019-04-06 21:24:26 +00:00
|
|
|
const bhttp = require('bhttp');
|
|
|
|
const cheerio = require('cheerio');
|
|
|
|
const moment = require('moment');
|
|
|
|
|
|
|
|
const { matchTags } = require('../tags');
|
|
|
|
|
|
|
|
function scrape(html, site) {
|
|
|
|
const $ = cheerio.load(html, { normalizeWhitespace: true });
|
|
|
|
const sceneElements = $('.sceneList .scene').toArray();
|
|
|
|
|
|
|
|
return sceneElements.map((element) => {
|
|
|
|
const entryId = $(element).attr('data-itemid');
|
|
|
|
|
|
|
|
const sceneLinkElement = $(element).find('.sceneTitle a');
|
|
|
|
const title = sceneLinkElement.attr('title');
|
|
|
|
const url = `${site.url}/en/scene/${sceneLinkElement.attr('href').split('/').slice(-2).join('/')}`;
|
|
|
|
|
|
|
|
const date = moment.utc($(element).find('.sceneDate').text(), 'MM-DD-YYYY').toDate();
|
|
|
|
const actors = $(element).find('.sceneActors a').map((actorIndex, actorElement) => $(actorElement).text()).toArray();
|
|
|
|
|
2019-09-26 01:27:01 +00:00
|
|
|
const poster = $(element).find('a.imgLink img.img').attr('data-original');
|
|
|
|
const trailer = `https://videothumb.gammacdn.com/600x339/${entryId}.mp4`;
|
|
|
|
|
2019-04-06 21:24:26 +00:00
|
|
|
const likes = Number($(element).find('.rating .state_1 .value').text());
|
|
|
|
|
|
|
|
return {
|
|
|
|
url,
|
|
|
|
entryId,
|
|
|
|
title,
|
|
|
|
actors,
|
|
|
|
date,
|
2019-09-26 01:27:01 +00:00
|
|
|
poster,
|
|
|
|
trailer: {
|
|
|
|
src: trailer,
|
|
|
|
quality: 339,
|
|
|
|
},
|
2019-04-06 21:24:26 +00:00
|
|
|
rating: {
|
|
|
|
likes,
|
|
|
|
},
|
|
|
|
site,
|
|
|
|
};
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async function scrapeScene(html, url, site) {
|
|
|
|
const $ = cheerio.load(html, { normalizeWhitespace: true });
|
|
|
|
const json = $('script[type="application/ld+json"]').html();
|
|
|
|
const data = JSON.parse(json).slice(-1)[0];
|
|
|
|
const sceneElement = $('#wrapper');
|
|
|
|
|
2019-09-26 01:27:01 +00:00
|
|
|
const videoScript = $('script:contains("window.ScenePlayerOptions")').html();
|
|
|
|
const playerObject = videoScript.slice(videoScript.indexOf('{'), videoScript.indexOf('};') + 1);
|
|
|
|
const playerData = JSON.parse(playerObject);
|
|
|
|
|
2019-04-06 21:24:26 +00:00
|
|
|
const workName = data.isPartOf.name.split(' - ');
|
2019-09-26 01:27:01 +00:00
|
|
|
const shootId = workName.length > 1 ? workName[1] : null;
|
2019-04-06 21:24:26 +00:00
|
|
|
const entryId = url.split('/').slice(-1)[0];
|
2019-09-26 01:27:01 +00:00
|
|
|
const title = data.title || $('meta[name="twitter:title"]').attr('content');
|
|
|
|
const description = data.description || $('meta[name="twitter:description"]').attr('content');
|
|
|
|
// date in data object is not the release date of the scene, but the date the entry was added
|
|
|
|
const date = moment.utc($('.updatedDate').first().text(), 'MM-DD-YYYY').toDate();
|
2019-04-06 21:24:26 +00:00
|
|
|
|
2019-09-26 01:27:01 +00:00
|
|
|
const actors = data.actor.map(({ name }) => name);
|
2019-04-06 21:24:26 +00:00
|
|
|
|
|
|
|
const likes = Number(sceneElement.find('.rating .state_1 .value').text());
|
|
|
|
const dislikes = Number(sceneElement.find('.rating .state_2 .value').text());
|
|
|
|
|
2019-09-26 01:27:01 +00:00
|
|
|
const poster = playerData.picPreview;
|
|
|
|
const trailer = `${playerData.playerOptions.host}${playerData.url}`;
|
|
|
|
|
2019-04-06 21:24:26 +00:00
|
|
|
const duration = moment.duration(data.duration.slice(2)).asSeconds();
|
|
|
|
|
|
|
|
const rawTags = data.keywords.split(', ');
|
|
|
|
const tags = await matchTags(rawTags);
|
|
|
|
|
|
|
|
return {
|
|
|
|
url,
|
|
|
|
shootId,
|
|
|
|
entryId,
|
|
|
|
title,
|
2019-04-07 03:19:44 +00:00
|
|
|
description,
|
2019-04-06 21:24:26 +00:00
|
|
|
actors,
|
|
|
|
date,
|
|
|
|
duration,
|
2019-09-26 01:27:01 +00:00
|
|
|
poster,
|
|
|
|
trailer: {
|
|
|
|
src: trailer,
|
|
|
|
quality: playerData.sizeOnLoad.slice(0, -1),
|
|
|
|
},
|
2019-04-06 21:24:26 +00:00
|
|
|
tags,
|
|
|
|
rating: {
|
|
|
|
likes,
|
|
|
|
dislikes,
|
|
|
|
},
|
|
|
|
site,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
async function fetchLatest(site, page = 1) {
|
2019-09-26 01:27:01 +00:00
|
|
|
const res = await bhttp.get(`https://www.blowpass.com/en/videos/${site.slug}/latest/All-Categories/0/All-Pornstars/0/${page}`);
|
2019-04-06 21:24:26 +00:00
|
|
|
|
|
|
|
return scrape(res.body.toString(), site);
|
|
|
|
}
|
|
|
|
|
|
|
|
async function fetchUpcoming(site) {
|
2019-09-26 01:27:01 +00:00
|
|
|
const res = await bhttp.get(`https://www.blowpass.com/en/videos/${site.slug}/upcoming`);
|
2019-04-06 21:24:26 +00:00
|
|
|
|
|
|
|
return scrape(res.body.toString(), site);
|
|
|
|
}
|
|
|
|
|
|
|
|
async function fetchScene(url, site) {
|
|
|
|
const res = await bhttp.get(`https://www.blowpass.com/en/video/${site.id}/${new URL(url).pathname.split('/').slice(-2).join('/')}`);
|
|
|
|
|
|
|
|
return scrapeScene(res.body.toString(), url, site);
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
fetchLatest,
|
|
|
|
fetchUpcoming,
|
|
|
|
fetchScene,
|
|
|
|
};
|