2019-03-24 04:28:18 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const bhttp = require('bhttp');
|
|
|
|
const cheerio = require('cheerio');
|
|
|
|
const moment = require('moment');
|
2019-03-25 02:57:33 +00:00
|
|
|
|
2019-11-16 02:33:36 +00:00
|
|
|
const { fetchSites } = require('../sites');
|
2019-03-25 02:57:33 +00:00
|
|
|
const { matchTags } = require('../tags');
|
2019-03-24 04:28:18 +00:00
|
|
|
|
|
|
|
function scrapeLatest(html, site) {
|
|
|
|
const $ = cheerio.load(html, { normalizeWhitespace: true });
|
|
|
|
const sceneElements = $('.shoot-list .shoot').toArray();
|
|
|
|
|
|
|
|
return sceneElements.map((element) => {
|
|
|
|
const sceneLinkElement = $(element).find('.shoot-thumb-title a');
|
|
|
|
const href = sceneLinkElement.attr('href');
|
|
|
|
const url = `https://kink.com${href}`;
|
2019-03-26 00:26:47 +00:00
|
|
|
const shootId = href.split('/')[2];
|
2019-04-05 01:45:40 +00:00
|
|
|
const title = sceneLinkElement.text().trim();
|
2019-03-24 04:28:18 +00:00
|
|
|
|
2019-09-25 02:52:58 +00:00
|
|
|
const poster = $(element).find('.adimage').attr('src');
|
2019-07-06 03:29:12 +00:00
|
|
|
const photos = $(element).find('.rollover .roll-image').map((photoIndex, photoElement) => $(photoElement).attr('data-imagesrc')).toArray();
|
2019-05-08 03:50:13 +00:00
|
|
|
|
2019-03-24 04:28:18 +00:00
|
|
|
const date = moment.utc($(element).find('.date').text(), 'MMM DD, YYYY').toDate();
|
|
|
|
const actors = $(element).find('.shoot-thumb-models a').map((actorIndex, actorElement) => $(actorElement).text()).toArray();
|
|
|
|
const stars = $(element).find('.average-rating').attr('data-rating') / 10;
|
|
|
|
|
|
|
|
const timestamp = $(element).find('.video span').text();
|
|
|
|
const timestampComponents = timestamp.split(':'); // fix mixed hh:mm:ss and mm:ss format
|
|
|
|
const duration = moment.duration(timestampComponents.length > 2 ? timestamp : `0:${timestamp}`).asSeconds();
|
|
|
|
|
|
|
|
return {
|
|
|
|
url,
|
2019-03-26 00:26:47 +00:00
|
|
|
shootId,
|
2019-04-06 21:24:26 +00:00
|
|
|
entryId: shootId,
|
2019-03-24 04:28:18 +00:00
|
|
|
title,
|
|
|
|
actors,
|
|
|
|
date,
|
2019-07-06 03:29:12 +00:00
|
|
|
photos,
|
2019-09-25 02:52:58 +00:00
|
|
|
poster,
|
2019-03-24 04:28:18 +00:00
|
|
|
rating: {
|
|
|
|
stars,
|
|
|
|
},
|
|
|
|
duration,
|
|
|
|
site,
|
|
|
|
};
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-03-26 00:26:47 +00:00
|
|
|
async function scrapeScene(html, url, shootId, ratingRes, site) {
|
2019-03-24 04:28:18 +00:00
|
|
|
const $ = cheerio.load(html, { normalizeWhitespace: true });
|
|
|
|
|
|
|
|
// const title = $('h1.shoot-title').text().replace(/\ue800/, ''); // fallback, special character is 'like'-heart
|
|
|
|
const title = $('h1.shoot-title span.favorite-button').attr('data-title');
|
|
|
|
const actorsRaw = $('.shoot-info p.starring');
|
|
|
|
|
2019-09-08 01:53:09 +00:00
|
|
|
const photos = $('.gallery .thumb img').map((photoIndex, photoElement) => $(photoElement).attr('data-image-file')).toArray();
|
2019-05-08 03:50:13 +00:00
|
|
|
const trailerVideo = $('.player span[data-type="trailer-src"]').attr('data-url');
|
|
|
|
const trailerPoster = $('.player video#kink-player').attr('poster');
|
|
|
|
|
2019-03-24 04:28:18 +00:00
|
|
|
const date = moment.utc($(actorsRaw)
|
|
|
|
.prev()
|
|
|
|
.text()
|
|
|
|
.trim()
|
|
|
|
.replace('Date: ', ''),
|
|
|
|
'MMMM DD, YYYY')
|
|
|
|
.toDate();
|
|
|
|
|
|
|
|
const actors = $(actorsRaw).find('span.names a').map((actorIndex, actorElement) => $(actorElement).text()).toArray();
|
2019-05-06 00:01:57 +00:00
|
|
|
const description = $('.shoot-info .description').text().trim();
|
2019-03-24 04:28:18 +00:00
|
|
|
|
|
|
|
const { average: stars } = ratingRes.body;
|
|
|
|
|
2019-11-16 02:33:36 +00:00
|
|
|
const siteName = $('.shoot-logo a').attr('href').split('/')[2];
|
|
|
|
const siteSlug = siteName.replace(/\s+/g, '').toLowerCase();
|
2019-03-24 04:28:18 +00:00
|
|
|
const rawTags = $('.tag-list > a[href*="/tag"]').map((tagIndex, tagElement) => $(tagElement).text()).toArray();
|
2019-03-25 02:57:33 +00:00
|
|
|
|
2019-11-16 02:33:36 +00:00
|
|
|
const [[channelSite], tags] = await Promise.all([
|
2019-11-04 04:47:37 +00:00
|
|
|
site.isFallback
|
2019-11-16 02:33:36 +00:00
|
|
|
? fetchSites({
|
|
|
|
slug: siteSlug,
|
|
|
|
name: siteName,
|
|
|
|
})
|
|
|
|
: [site],
|
2019-04-04 02:00:28 +00:00
|
|
|
matchTags(rawTags),
|
|
|
|
]);
|
2019-03-24 04:28:18 +00:00
|
|
|
|
|
|
|
return {
|
|
|
|
url,
|
2019-03-26 00:26:47 +00:00
|
|
|
shootId,
|
2019-04-06 21:24:26 +00:00
|
|
|
entryId: shootId,
|
2019-03-24 04:28:18 +00:00
|
|
|
title,
|
|
|
|
date,
|
|
|
|
actors,
|
|
|
|
description,
|
2019-07-06 03:29:12 +00:00
|
|
|
photos,
|
2019-09-25 02:52:58 +00:00
|
|
|
poster: trailerPoster,
|
2019-05-08 03:50:13 +00:00
|
|
|
trailer: {
|
2019-09-25 02:52:58 +00:00
|
|
|
src: trailerVideo,
|
|
|
|
quality: 480,
|
2019-05-08 03:50:13 +00:00
|
|
|
},
|
2019-03-24 04:28:18 +00:00
|
|
|
rating: {
|
|
|
|
stars,
|
|
|
|
},
|
|
|
|
tags,
|
|
|
|
site: channelSite || site,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-04-05 01:45:40 +00:00
|
|
|
async function fetchLatest(site, page = 1) {
|
|
|
|
const res = await bhttp.get(`${site.url}/latest/page/${page}`);
|
2019-03-24 04:28:18 +00:00
|
|
|
|
|
|
|
return scrapeLatest(res.body.toString(), site);
|
|
|
|
}
|
|
|
|
|
|
|
|
async function fetchScene(url, site) {
|
2019-03-26 00:26:47 +00:00
|
|
|
const shootId = new URL(url).pathname.split('/')[2];
|
2019-03-24 04:28:18 +00:00
|
|
|
|
|
|
|
const [res, ratingRes] = await Promise.all([
|
|
|
|
bhttp.get(url),
|
2019-03-26 00:26:47 +00:00
|
|
|
bhttp.get(`https://kink.com/api/ratings/${shootId}`),
|
2019-03-24 04:28:18 +00:00
|
|
|
]);
|
|
|
|
|
2019-03-26 00:26:47 +00:00
|
|
|
return scrapeScene(res.body.toString(), url, shootId, ratingRes, site);
|
2019-03-24 04:28:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
fetchLatest,
|
|
|
|
fetchScene,
|
|
|
|
};
|