2019-03-24 04:28:18 +00:00
|
|
|
'use strict';
|
|
|
|
|
2019-04-07 03:19:44 +00:00
|
|
|
/* eslint-disable newline-per-chained-call */
|
2019-03-24 04:28:18 +00:00
|
|
|
const bhttp = require('bhttp');
|
2019-11-09 00:22:50 +00:00
|
|
|
const { JSDOM } = require('jsdom');
|
2019-03-24 04:28:18 +00:00
|
|
|
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) {
|
2019-11-09 00:22:50 +00:00
|
|
|
const { document } = new JSDOM(html).window;
|
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 23:49:45 +00:00
|
|
|
const actors = $(element).find('.actors a').map((actorIndex, actorElement) => $(actorElement).text()).toArray();
|
2019-04-07 03:01:06 +00:00
|
|
|
|
2019-04-04 02:00:28 +00:00
|
|
|
return {
|
|
|
|
url,
|
2019-04-07 23:49:45 +00:00
|
|
|
entryId,
|
2019-04-04 02:00:28 +00:00
|
|
|
title,
|
|
|
|
actors,
|
|
|
|
date,
|
|
|
|
rating: {
|
|
|
|
likes,
|
|
|
|
dislikes,
|
|
|
|
stars,
|
|
|
|
},
|
|
|
|
site,
|
|
|
|
};
|
|
|
|
});
|
2019-03-24 04:28:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function scrapeUpcoming(html, site) {
|
2019-11-09 00:22:50 +00:00
|
|
|
const { document } = new JSDOM(html).window;
|
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 23:49:45 +00:00
|
|
|
const actors = $(element).find('.actors a').map((actorIndex, actorElement) => $(actorElement).text()).toArray();
|
2019-04-07 03:01:06 +00:00
|
|
|
|
2019-04-04 02:00:28 +00:00
|
|
|
return {
|
|
|
|
url,
|
2019-04-07 23:49:45 +00:00
|
|
|
entryId,
|
2019-04-04 02:00:28 +00:00
|
|
|
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-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,
|
2019-04-07 23:49:45 +00:00
|
|
|
entryId,
|
2019-04-04 02:00:28 +00:00
|
|
|
title,
|
2019-04-07 03:19:44 +00:00
|
|
|
description,
|
2019-04-04 02:00:28 +00:00
|
|
|
actors,
|
2019-04-06 21:24:26 +00:00
|
|
|
director,
|
2019-04-04 02:00:28 +00:00
|
|
|
date,
|
2019-04-07 03:21:27 +00:00
|
|
|
duration,
|
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,
|
|
|
|
};
|