forked from DebaucheryLibrarian/traxxx
91 lines
2.2 KiB
JavaScript
91 lines
2.2 KiB
JavaScript
|
'use strict';
|
||
|
|
||
|
/* eslint-disable */
|
||
|
const bhttp = require('bhttp');
|
||
|
const cheerio = require('cheerio');
|
||
|
const moment = require('moment');
|
||
|
|
||
|
const { matchTags } = require('../tags');
|
||
|
|
||
|
function scrapeLatest(html, site) {
|
||
|
const $ = cheerio.load(html, { normalizeWhitespace: true });
|
||
|
|
||
|
const stateObject = $('script:contains("INITIAL_STATE")');
|
||
|
const { videos: scenes } = JSON.parse(stateObject.html().trim().slice(27, -1));
|
||
|
|
||
|
return scenes.map((scene) => {
|
||
|
const shootId = scene.newId;
|
||
|
const title = scene.title;
|
||
|
const url = `${site.url}${scene.targetUrl}`;
|
||
|
const date = moment.utc(scene.releaseDateFormatted, 'MMMM DD, YYYY').toDate();
|
||
|
const actors = scene.models;
|
||
|
const stars = Number(scene.textRating) / 2;
|
||
|
|
||
|
return {
|
||
|
url,
|
||
|
shootId,
|
||
|
title,
|
||
|
actors,
|
||
|
date,
|
||
|
rating: {
|
||
|
stars,
|
||
|
},
|
||
|
site,
|
||
|
};
|
||
|
});
|
||
|
}
|
||
|
|
||
|
async function scrapeScene(html, url, site) {
|
||
|
const $ = cheerio.load(html, { normalizeWhitespace: true });
|
||
|
const { pathname, search } = new URL(url);
|
||
|
|
||
|
const stateObject = $('script:contains("INITIAL_STATE")');
|
||
|
const data = JSON.parse(stateObject.html().trim().slice(27, -1));
|
||
|
|
||
|
const scene = data.page.data[`${pathname}${search}`].data.video;
|
||
|
|
||
|
const shootId = scene.newId;
|
||
|
const title = scene.title;
|
||
|
const date = new Date(scene.releaseDate);
|
||
|
const actors = scene.models;
|
||
|
const stars = scene.totalRateVal;
|
||
|
|
||
|
const rawTags = scene.tags;
|
||
|
const tags = await matchTags(rawTags);
|
||
|
|
||
|
const duration = scene.runLength;
|
||
|
const director = scene.directorNames;
|
||
|
|
||
|
return {
|
||
|
url,
|
||
|
shootId,
|
||
|
title,
|
||
|
actors,
|
||
|
director,
|
||
|
date,
|
||
|
duration,
|
||
|
tags,
|
||
|
rating: {
|
||
|
stars,
|
||
|
},
|
||
|
site,
|
||
|
};
|
||
|
}
|
||
|
|
||
|
async function fetchLatest(site) {
|
||
|
const res = await bhttp.get(`${site.url}/videos`);
|
||
|
|
||
|
return scrapeLatest(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,
|
||
|
fetchScene,
|
||
|
};
|