2019-03-24 04:28:18 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
/* eslint-disable */
|
|
|
|
const bhttp = require('bhttp');
|
|
|
|
const cheerio = require('cheerio');
|
|
|
|
const moment = require('moment');
|
|
|
|
|
2019-04-01 00:45:15 +00:00
|
|
|
const { matchTags } = require('../tags');
|
2019-03-24 04:28:18 +00:00
|
|
|
|
|
|
|
function scrapeLatest(html, site) {
|
|
|
|
const $ = cheerio.load(html, { normalizeWhitespace: true });
|
2019-04-04 18:22:47 +00:00
|
|
|
const sceneElements = $('.scenes-latest').toArray();
|
2019-04-04 02:00:28 +00:00
|
|
|
|
|
|
|
return sceneElements.map((element) => {
|
2019-04-07 03:01:06 +00:00
|
|
|
const actors = $('.actors a').map((actorIndex, actorElement) => $(actorElement).text()).toArray();
|
|
|
|
|
2019-04-04 02:00:28 +00:00
|
|
|
return {
|
|
|
|
url,
|
|
|
|
shootId,
|
|
|
|
title,
|
|
|
|
actors,
|
|
|
|
date,
|
|
|
|
rating: {
|
|
|
|
likes,
|
|
|
|
dislikes,
|
|
|
|
stars,
|
|
|
|
},
|
|
|
|
site,
|
|
|
|
};
|
|
|
|
});
|
2019-03-24 04:28:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function scrapeUpcoming(html, site) {
|
|
|
|
const $ = cheerio.load(html, { normalizeWhitespace: true });
|
2019-04-04 18:22:47 +00:00
|
|
|
const sceneElements = $('.scenes-upcoming').toArray();
|
2019-04-04 02:00:28 +00:00
|
|
|
|
|
|
|
return sceneElements.map((element) => {
|
2019-04-07 03:01:06 +00:00
|
|
|
const actors = $('.actors a').map((actorIndex, actorElement) => $(actorElement).text()).toArray();
|
|
|
|
|
2019-04-04 02:00:28 +00:00
|
|
|
return {
|
|
|
|
url,
|
|
|
|
shootId,
|
|
|
|
title,
|
|
|
|
actors,
|
|
|
|
date,
|
|
|
|
rating: {
|
|
|
|
likes,
|
|
|
|
dislikes,
|
|
|
|
stars,
|
|
|
|
},
|
|
|
|
site,
|
|
|
|
};
|
|
|
|
});
|
2019-03-24 04:28:18 +00:00
|
|
|
}
|
|
|
|
|
2019-04-06 21:24:26 +00:00
|
|
|
async function scrapeScene(html, url, site) {
|
2019-03-24 04:28:18 +00:00
|
|
|
const $ = cheerio.load(html, { normalizeWhitespace: true });
|
2019-04-04 02:00:28 +00:00
|
|
|
|
2019-04-06 21:24:26 +00:00
|
|
|
const rawTags = [];
|
|
|
|
const tags = await matchTags(rawTags);
|
|
|
|
|
2019-04-07 03:01:06 +00:00
|
|
|
const actors = $('.actors a').map((actorIndex, actorElement) => $(actorElement).text()).toArray();
|
|
|
|
|
|
|
|
const rawTags = $('.tags a').map((tagIndex, tagElement) => $(tagElement).text()).toArray();
|
|
|
|
const tags = await matchTags(rawTags);
|
|
|
|
|
2019-04-04 02:00:28 +00:00
|
|
|
return {
|
|
|
|
url,
|
|
|
|
shootId,
|
|
|
|
title,
|
|
|
|
actors,
|
2019-04-06 21:24:26 +00:00
|
|
|
director,
|
2019-04-04 02:00:28 +00:00
|
|
|
date,
|
2019-04-06 21:24:26 +00:00
|
|
|
tags,
|
2019-04-04 02:00:28 +00:00
|
|
|
rating: {
|
|
|
|
likes,
|
|
|
|
dislikes,
|
|
|
|
stars,
|
|
|
|
},
|
|
|
|
site,
|
|
|
|
};
|
2019-03-24 04:28:18 +00:00
|
|
|
}
|
|
|
|
|
2019-04-06 21:24:26 +00:00
|
|
|
async function fetchLatest(site, page = 1) {
|
2019-03-24 04:28:18 +00:00
|
|
|
const res = await bhttp.get(`${site.url}/url`);
|
|
|
|
|
|
|
|
return scrapeLatest(res.body.toString(), site);
|
|
|
|
}
|
|
|
|
|
|
|
|
async function fetchUpcoming(site) {
|
|
|
|
const res = await bhttp.get(`${site.url}/url`);
|
|
|
|
|
|
|
|
return scrapeUpcoming(res.body.toString(), site);
|
|
|
|
}
|
|
|
|
|
|
|
|
async function fetchScene(url, site) {
|
|
|
|
const res = await bhttp.get(url);
|
|
|
|
|
|
|
|
return scrapeScene(res.body.toString(), url, site);
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
fetchLatest,
|
|
|
|
fetchUpcoming,
|
|
|
|
fetchScene,
|
|
|
|
};
|